forked from Shinonome/dots-hyprland
rename material theme service
This commit is contained in:
@@ -0,0 +1,55 @@
|
|||||||
|
pragma Singleton
|
||||||
|
pragma ComponentBehavior: Bound
|
||||||
|
|
||||||
|
import "root:/modules/common"
|
||||||
|
import QtQuick
|
||||||
|
import Quickshell
|
||||||
|
import Quickshell.Io
|
||||||
|
import Qt.labs.platform
|
||||||
|
|
||||||
|
Singleton {
|
||||||
|
id: root
|
||||||
|
property string filePath: `${StandardPaths.standardLocations(StandardPaths.StateLocation)[0]}/user/generated/colors.json`
|
||||||
|
|
||||||
|
function reapplyTheme() {
|
||||||
|
themeFileView.reload()
|
||||||
|
}
|
||||||
|
|
||||||
|
function applyColors(fileContent) {
|
||||||
|
const json = JSON.parse(fileContent)
|
||||||
|
for (const key in json) {
|
||||||
|
if (json.hasOwnProperty(key)) {
|
||||||
|
// Convert snake_case to CamelCase
|
||||||
|
const camelCaseKey = key.replace(/_([a-z])/g, (g) => g[1].toUpperCase())
|
||||||
|
const m3Key = `m3${camelCaseKey}`
|
||||||
|
Appearance.m3colors[m3Key] = json[key]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Appearance.m3colors.darkmode = (Appearance.m3colors.m3background.hslLightness < 0.5)
|
||||||
|
}
|
||||||
|
|
||||||
|
Timer {
|
||||||
|
id: delayedFileRead
|
||||||
|
interval: ConfigOptions.hacks.arbitraryRaceConditionDelay
|
||||||
|
repeat: false
|
||||||
|
running: false
|
||||||
|
onTriggered: {
|
||||||
|
root.applyColors(themeFileView.text())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
FileView {
|
||||||
|
id: themeFileView
|
||||||
|
path: root.filePath
|
||||||
|
watchChanges: true
|
||||||
|
onFileChanged: {
|
||||||
|
this.reload()
|
||||||
|
delayedFileRead.start()
|
||||||
|
}
|
||||||
|
onLoadedChanged: {
|
||||||
|
const fileContent = themeFileView.text()
|
||||||
|
root.applyColors(fileContent)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -17,7 +17,7 @@ import "./services/"
|
|||||||
|
|
||||||
ShellRoot {
|
ShellRoot {
|
||||||
Component.onCompleted: {
|
Component.onCompleted: {
|
||||||
MaterialTheme.reapplyTheme()
|
MaterialThemeLoader.reapplyTheme()
|
||||||
}
|
}
|
||||||
|
|
||||||
Bar {}
|
Bar {}
|
||||||
|
|||||||
Reference in New Issue
Block a user