Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexandrePTJ committed Jun 30, 2024
2 parents 284d82f + 742b113 commit 168ec41
Show file tree
Hide file tree
Showing 12 changed files with 203 additions and 209 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
strategy:
fail-fast: false
matrix:
qt_version: [6.7.0, 5.15.2]
qt_version: [6.7.2, 5.15.2]
steps:
- name: Checkout repo
uses: actions/checkout@v3
Expand Down Expand Up @@ -62,7 +62,7 @@ jobs:
artifacts: 'Kemai-*.AppImage'

WindowsJob:
name: Windows Qt-6.7.0
name: Windows Qt-6.7.2
runs-on: windows-latest
steps:
- name: Checkout repo
Expand All @@ -74,7 +74,7 @@ jobs:
- name: Install Qt
uses: jurplel/install-qt-action@v3
with:
version: '6.7.0'
version: '6.7.2'
tools: 'tools_opensslv3_x64'
cache: true
aqtversion: '==3.1.*'
Expand Down Expand Up @@ -104,7 +104,7 @@ jobs:
artifacts: 'cmake-build-release-win/Kemai-*.msi'

MacOSJob:
name: MacOS Qt-6.7.0
name: MacOS Qt-6.7.2
runs-on: macos-latest
strategy:
matrix:
Expand All @@ -119,7 +119,7 @@ jobs:
- name: Install Qt
uses: jurplel/install-qt-action@v3
with:
version: '6.7.0'
version: '6.7.2'
cache: true
aqtversion: '==3.1.*'

Expand Down
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]


## [0.11.1] - 2024-06-30

### Fixed
- Fix missing log directory at first startup (Thanks to @ensemblebd)
- Settings management


## [0.11.0] - 2024-05-22

### Fixed
Expand Down Expand Up @@ -188,7 +195,8 @@ Special thanks to @shrippen for its support through [sponsorship](https://github
Initial version.


[Unreleased]: https://github.com/AlexandrePTJ/kemai/compare/0.11.0...HEAD
[Unreleased]: https://github.com/AlexandrePTJ/kemai/compare/0.11.1...HEAD
[0.11.1]: https://github.com/AlexandrePTJ/kemai/compare/0.11.0...0.11.1
[0.11.0]: https://github.com/AlexandrePTJ/kemai/compare/0.10.0...0.11.0
[0.10.0]: https://github.com/AlexandrePTJ/kemai/compare/0.9.4...0.10.0
[0.9.4]: https://github.com/AlexandrePTJ/kemai/compare/0.9.3...0.9.4
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.11)
project(KemaiProject VERSION 0.11.0 LANGUAGES CXX)
project(KemaiProject VERSION 0.11.1 LANGUAGES CXX)

# Point CMake to the custom modules
list(APPEND CMAKE_MODULE_PATH ${CMAKE_BINARY_DIR} ${CMAKE_SOURCE_DIR}/cmake)
Expand Down
4 changes: 2 additions & 2 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"name": "default-windows",
"hidden": true,
"cacheVariables": {
"CMAKE_PREFIX_PATH": "c:/Qt/6.7.0/msvc2019_64",
"CMAKE_PREFIX_PATH": "c:/Qt/6.7.2/msvc2019_64",
"OPENSSL_ROOT": "c:/Qt/Tools/OpenSSLv3/Win_x64",
"CMAKE_INSTALL_PREFIX": "dist"
}
Expand All @@ -30,7 +30,7 @@
"name": "default-macos",
"hidden": true,
"cacheVariables": {
"CMAKE_PREFIX_PATH": "$env{HOME}/Qt/6.7.0/macos",
"CMAKE_PREFIX_PATH": "$env{HOME}/Qt/6.7.2/macos",
"CMAKE_INSTALL_PREFIX": "dist"
}
},
Expand Down
5 changes: 5 additions & 0 deletions src/client/kimaiClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,11 @@ void KimaiClient::setHost(const QString& host)
mD->host = host;
}

QString KimaiClient::host() const
{
return mD->host;
}

void KimaiClient::setLegacyAuth(const QString& username, const QString& token)
{
mD->username = username;
Expand Down
1 change: 1 addition & 0 deletions src/client/kimaiClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class KimaiClient : public QObject
~KimaiClient() override;

void setHost(const QString& host);
QString host() const;

void setLegacyAuth(const QString& username, const QString& token);
bool isUsingLegacyAuth() const;
Expand Down
115 changes: 63 additions & 52 deletions src/gui/mainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ MainWindow::MainWindow() : mUi(std::make_unique<Ui::MainWindow>())
{
mUi->setupUi(this);

auto settings = Settings::get();
const auto& settings = SettingsHelper::load();

/*
* Setup icon
Expand Down Expand Up @@ -163,7 +163,7 @@ MainWindow::MainWindow() : mUi(std::make_unique<Ui::MainWindow>())
if (settings.kemai.checkUpdateAtStartup)
{
QTimer::singleShot(FirstRequestDelayMs, [&]() {
auto ignoreVersion = QVersionNumber::fromString(Settings::get().kemai.ignoredVersion);
auto ignoreVersion = QVersionNumber::fromString(SettingsHelper::load().kemai.ignoredVersion);
auto currentVersion = QVersionNumber::fromString(KEMAI_VERSION);
mUpdater.checkAvailableNewVersion(currentVersion >= ignoreVersion ? currentVersion : ignoreVersion, true);
});
Expand All @@ -188,19 +188,19 @@ void MainWindow::closeEvent(QCloseEvent* event)
mLoggerWidget.close();
}

auto settings = Settings::get();
auto settings = SettingsHelper::load();
if (settings.kemai.closeToSystemTray)
{
hide();
event->ignore();
}
settings.kemai.geometry = saveGeometry();
Settings::save(settings);
SettingsHelper::save(settings);
}

void MainWindow::hideEvent(QHideEvent* event)
{
auto settings = Settings::get();
auto settings = SettingsHelper::load();
if (settings.kemai.minimizeToSystemTray)
{
if (event->spontaneous() && isMinimized())
Expand All @@ -210,7 +210,7 @@ void MainWindow::hideEvent(QHideEvent* event)
}
}
settings.kemai.geometry = saveGeometry();
Settings::save(settings);
SettingsHelper::save(settings);
}

void MainWindow::createKemaiSession(const Settings::Profile& profile)
Expand All @@ -229,30 +229,39 @@ void MainWindow::createKemaiSession(const Settings::Profile& profile)
mStatusInstanceLabel.setText(tr("Not connected"));
}

auto settings = Settings::get();
if (settings.isReady())
// Ensure profile has all required infos
const auto haveHost = !profile.host.isEmpty();
const auto haveLegacyAuth = !profile.username.isEmpty() && !profile.token.isEmpty();
const auto haveAPIToken = !profile.apiToken.isEmpty();
const auto isProfileValidated = haveHost && (haveLegacyAuth || haveAPIToken);
if (!isProfileValidated)
{
auto kimaiClient = std::make_shared<KimaiClient>();
spdlog::error("Invalid profile. Check settings.");
return;
}

kimaiClient->setHost(profile.host);
kimaiClient->setLegacyAuth(profile.username, profile.token);
kimaiClient->setAPIToken(profile.apiToken);
// Create session
auto kimaiClient = std::make_shared<KimaiClient>();

mSession = std::make_shared<KemaiSession>(kimaiClient);
connect(mSession.get(), &KemaiSession::currentTimeSheetChanged, this, &MainWindow::onCurrentTimeSheetChanged);
connect(mSession.get(), &KemaiSession::pluginsChanged, this, &MainWindow::onPluginsChanged);
connect(mSession.get(), &KemaiSession::versionChanged, this, &MainWindow::onSessionVersionChanged);
kimaiClient->setHost(profile.host);
kimaiClient->setLegacyAuth(profile.username, profile.token);
kimaiClient->setAPIToken(profile.apiToken);

mActivityWidget->setKemaiSession(mSession);
mSession = std::make_shared<KemaiSession>(kimaiClient);
connect(mSession.get(), &KemaiSession::currentTimeSheetChanged, this, &MainWindow::onCurrentTimeSheetChanged);
connect(mSession.get(), &KemaiSession::pluginsChanged, this, &MainWindow::onPluginsChanged);
connect(mSession.get(), &KemaiSession::versionChanged, this, &MainWindow::onSessionVersionChanged);

mSession->refreshCache();
mSession->refreshSessionInfos();
mSession->refreshCurrentTimeSheet();
mActivityWidget->setKemaiSession(mSession);

// Save profile connection
settings.kemai.lastConnectedProfile = profile.id;
Settings::save(settings);
}
mSession->refreshCache();
mSession->refreshSessionInfos();
mSession->refreshCurrentTimeSheet();

// Save profile connection
auto settings = SettingsHelper::load();
settings.kemai.lastConnectedProfile = profile.id;
SettingsHelper::save(settings);
}

void MainWindow::showSelectedView()
Expand Down Expand Up @@ -283,12 +292,14 @@ void MainWindow::setViewActionsEnabled(bool enable)

void MainWindow::updateProfilesMenu()
{
auto settings = Settings::get();
const auto& settings = SettingsHelper::load();

// Removes obsoletes profiles
// Removes previous profiles
for (auto action : mActGroupProfiles->actions())
{
if (!settings.findProfile(action->data().toUuid()).has_value())
auto it = std::find_if(settings.profiles.begin(), settings.profiles.end(),
[profileId = action->data().toUuid()](const auto& profile) { return profile.id == profileId; });
if (it != settings.profiles.end())
{
mProfileMenu->removeAction(action);
mActGroupProfiles->removeAction(action);
Expand Down Expand Up @@ -318,26 +329,26 @@ void MainWindow::updateProfilesMenu()

void MainWindow::processAutoConnect()
{
auto settings = Settings::get();
if (settings.profiles.isEmpty())
const auto& settings = SettingsHelper::load();
if (settings.profiles.empty())
{
return;
}

auto profile = settings.findProfile(settings.kemai.lastConnectedProfile);
if (!profile.has_value())
{
profile = settings.profiles.front();
}

for (auto& action : mActGroupProfiles->actions())
auto profileIt = std::find_if(settings.profiles.begin(), settings.profiles.end(),
[profileId = settings.kemai.lastConnectedProfile](const auto& profile) { return profile.id == profileId; });
if (profileIt != settings.profiles.end())
{
if (action->data().toUuid() == profile->id)
for (auto& action : mActGroupProfiles->actions())
{
action->setChecked(true);
if (action->data().toUuid() == profileIt->id)
{
action->setChecked(true);
}
}

createKemaiSession(*profileIt);
}
createKemaiSession(profile.value());
}

void MainWindow::onCurrentTimeSheetChanged()
Expand Down Expand Up @@ -387,10 +398,10 @@ void MainWindow::onSessionVersionChanged()
void MainWindow::onActionSettingsTriggered()
{
SettingsDialog settingsDialog(mDesktopEventsMonitor, this);
settingsDialog.setSettings(Settings::get());
settingsDialog.setSettings(SettingsHelper::load());
if (settingsDialog.exec() == QDialog::Accepted)
{
Settings::save(settingsDialog.settings());
SettingsHelper::save(settingsDialog.settings());

showSelectedView();
updateProfilesMenu();
Expand All @@ -410,10 +421,9 @@ void MainWindow::onActionCheckUpdateTriggered()

void MainWindow::onActionOpenHostTriggered()
{
auto settings = Settings::get();
if (settings.isReady())
if (mSession)
{
QDesktopServices::openUrl(QUrl::fromUserInput(settings.profiles.first().host));
QDesktopServices::openUrl(QUrl::fromUserInput(mSession->client()->host()));
}
}

Expand All @@ -436,7 +446,7 @@ void MainWindow::onSystemTrayActivated(QSystemTrayIcon::ActivationReason reason)
switch (reason)
{
case QSystemTrayIcon::Trigger: {
auto settings = Settings::get();
const auto& settings = SettingsHelper::load();
if (isVisible() && (settings.kemai.minimizeToSystemTray || settings.kemai.closeToSystemTray))
{
hide();
Expand Down Expand Up @@ -472,9 +482,9 @@ void MainWindow::onNewVersionCheckFinished(const VersionDetails& details)
break;

case QMessageBox::Ignore: {
auto settings = Settings::get();
auto settings = SettingsHelper::load();
settings.kemai.ignoredVersion = details.vn.toString();
Settings::save(settings);
SettingsHelper::save(settings);
}
break;

Expand Down Expand Up @@ -508,20 +518,21 @@ void MainWindow::onProfilesActionGroupTriggered(QAction* action)
{
if (action->isChecked())
{
auto settings = Settings::get();
auto settings = SettingsHelper::load();
auto profileId = action->data().toUuid();
auto profile = settings.findProfile(profileId);
if (profile.has_value())
auto profileIt =
std::find_if(settings.profiles.begin(), settings.profiles.end(), [profileId](const auto& profile) { return profile.id == profileId; });
if (profileIt != settings.profiles.end())
{
createKemaiSession(profile.value());
createKemaiSession(*profileIt);
}
}
}
}

void MainWindow::onDesktopIdleDetected()
{
spdlog::info("System is idle since {} minutes. Stop current TimeSheet.", Settings::get().events.idleDelayMinutes);
spdlog::info("System is idle since {} minutes. Stop current TimeSheet.", SettingsHelper::load().events.idleDelayMinutes);
mActivityWidget->stopCurrentTimeSheet();
}

Expand Down
Loading

0 comments on commit 168ec41

Please sign in to comment.