fix(@desktop/general): Changing System Appearance on the fly is not working

App is responsive to the OS theme change event.
Now we're following system set theme when the app is started.

Corresponding part on the side on nimqml is added.

Corresponding part on the side on dotherside is added.

On the side of dother side we had kind of a memory leak, cause objects added to
the filter were not deleted ever. When the app is closing, it just removes
filters, but doesn't delete them.

I faced a logical issue, that we were sending qmlengine pointer to the
installEventFilter method, instead object which may or may not rely on the
qqmlengine instance, that is fixed also.

Fixes: #1725
This commit is contained in:
Sale Djenic 2021-08-12 13:52:04 +02:00 committed by Iuri Matias
parent f440995462
commit 04ca90a7d0
6 changed files with 35 additions and 11 deletions

View File

@ -92,7 +92,14 @@ proc mainProc() =
defer: engine.delete()
engine.addImportPath("qrc:/./StatusQ/src")
engine.setNetworkAccessManagerFactory(networkAccessFactory)
app.installEventFilter(engine)
# Register events objects
let dockShowAppEvent = newStatusDockShowAppEventObject(engine)
defer: dockShowAppEvent.delete()
let osThemeEvent = newStatusOSThemeEventObject(engine)
defer: osThemeEvent.delete()
app.installEventFilter(dockShowAppEvent)
app.installEventFilter(osThemeEvent)
let netAccMgr = newQNetworkAccessManager(engine.getNetworkAccessManager())

View File

@ -22,7 +22,7 @@ ScrollView {
function updateTheme(theme) {
globalSettings.theme = theme
Style.changeTheme(theme)
Style.changeTheme(theme, systemPalette.isCurrentSystemThemeDark())
}
function updateFontSize(fontSize) {

View File

@ -15,20 +15,22 @@ QtObject {
property ThemePalette statusQLightTheme: StatusLightTheme {}
property ThemePalette statusQDarkTheme: StatusDarkTheme {}
property var changeTheme: function (theme, isCurrentSystemThemeDark) {
property var changeTheme: function (theme) {
switch (theme) {
case Universal.Light:
current = lightTheme;
current = lightTheme;
Theme.palette = statusQLightTheme
break;
case Universal.Dark:
current = darkTheme;
current = darkTheme;
Theme.palette = statusQDarkTheme
break;
default:
current = lightTheme;
Theme.palette = statusQLightTheme
case Universal.System:
current = isCurrentSystemThemeDark? darkTheme : lightTheme;
Theme.palette = isCurrentSystemThemeDark? statusQDarkTheme : statusQLightTheme
break;
default:
console.log('Unknown theme. Valid themes are "light" and "dark"')
}
}

View File

@ -39,6 +39,7 @@ StatusWindow {
}
id: applicationWindow
objectName: "mainWindow"
minimumWidth: 900
minimumHeight: 600
width: 1232
@ -120,8 +121,22 @@ StatusWindow {
}
}
// The easiest way to get current system theme (is it light or dark) without using
// OS native methods is to check lightness (0 - 1.0) of the window color.
// If it's too high (0.85+) means light theme is an active.
SystemPalette {
id: systemPalette
function isCurrentSystemThemeDark() {
return window.hslLightness < 0.85
}
}
function changeThemeFromOutside() {
Style.changeTheme(globalSettings.theme, systemPalette.isCurrentSystemThemeDark())
}
Component.onCompleted: {
Style.changeTheme(globalSettings.theme)
Style.changeTheme(globalSettings.theme, systemPalette.isCurrentSystemThemeDark())
setX(Qt.application.screens[0].width / 2 - width / 2);
setY(Qt.application.screens[0].height / 2 - height / 2);

2
vendor/DOtherSide vendored

@ -1 +1 @@
Subproject commit df432d4016d6c16791d89971f2c6bc386e3f2a7d
Subproject commit 11adba22838f448b34645bed33fdec86848c50b4

2
vendor/nimqml vendored

@ -1 +1 @@
Subproject commit 3a2026ebbc8a98ef1ffe15693685feea38286552
Subproject commit dbabf0b2979263e7df8d4bb7a3ddca244b4b682a