Settings.qml cleanup
This commit is contained in:
parent
b85d68f4cb
commit
57731e5a36
1 changed files with 229 additions and 261 deletions
|
|
@ -1,9 +1,9 @@
|
|||
pragma Singleton
|
||||
import QtQuick
|
||||
import Quickshell
|
||||
import Quickshell.Io
|
||||
import qs.Commons
|
||||
import qs.Services
|
||||
pragma Singleton
|
||||
|
||||
Singleton {
|
||||
id: root
|
||||
|
|
@ -12,11 +12,8 @@ Singleton {
|
|||
// Default config directory: ~/.config/noctalia
|
||||
// Default cache directory: ~/.cache/noctalia
|
||||
property string shellName: "noctalia"
|
||||
property string configDir: Quickshell.env("NOCTALIA_CONFIG_DIR") || (Quickshell.env("XDG_CONFIG_HOME")
|
||||
|| Quickshell.env(
|
||||
"HOME") + "/.config") + "/" + shellName + "/"
|
||||
property string cacheDir: Quickshell.env("NOCTALIA_CACHE_DIR") || (Quickshell.env("XDG_CACHE_HOME") || Quickshell.env(
|
||||
"HOME") + "/.cache") + "/" + shellName + "/"
|
||||
property string configDir: Quickshell.env("NOCTALIA_CONFIG_DIR") || (Quickshell.env("XDG_CONFIG_HOME") || Quickshell.env("HOME") + "/.config") + "/" + shellName + "/"
|
||||
property string cacheDir: Quickshell.env("NOCTALIA_CACHE_DIR") || (Quickshell.env("XDG_CACHE_HOME") || Quickshell.env("HOME") + "/.cache") + "/" + shellName + "/"
|
||||
property string cacheDirImages: cacheDir + "images/"
|
||||
|
||||
property string settingsFile: Quickshell.env("NOCTALIA_SETTINGS_FILE") || (configDir + "settings.json")
|
||||
|
|
@ -32,41 +29,40 @@ Singleton {
|
|||
|
||||
// Function to validate monitor configurations
|
||||
function validateMonitorConfigurations() {
|
||||
var availableScreenNames = []
|
||||
var availableScreenNames = [];
|
||||
for (var i = 0; i < Quickshell.screens.length; i++) {
|
||||
availableScreenNames.push(Quickshell.screens[i].name)
|
||||
availableScreenNames.push(Quickshell.screens[i].name);
|
||||
}
|
||||
|
||||
Logger.log("Settings", "Available monitors: [" + availableScreenNames.join(", ") + "]")
|
||||
Logger.log("Settings", "Configured bar monitors: [" + adapter.bar.monitors.join(", ") + "]")
|
||||
Logger.log("Settings", "Available monitors: [" + availableScreenNames.join(", ") + "]");
|
||||
Logger.log("Settings", "Configured bar monitors: [" + adapter.bar.monitors.join(", ") + "]");
|
||||
|
||||
// Check bar monitors
|
||||
if (adapter.bar.monitors.length > 0) {
|
||||
var hasValidBarMonitor = false
|
||||
var hasValidBarMonitor = false;
|
||||
for (var j = 0; j < adapter.bar.monitors.length; j++) {
|
||||
if (availableScreenNames.includes(adapter.bar.monitors[j])) {
|
||||
hasValidBarMonitor = true
|
||||
break
|
||||
hasValidBarMonitor = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!hasValidBarMonitor) {
|
||||
Logger.log("Settings",
|
||||
"No configured bar monitors found on system, clearing bar monitor list to show on all screens")
|
||||
adapter.bar.monitors = []
|
||||
Logger.log("Settings", "No configured bar monitors found on system, clearing bar monitor list to show on all screens");
|
||||
adapter.bar.monitors = [];
|
||||
} else {
|
||||
Logger.log("Settings", "Found valid bar monitors, keeping configuration")
|
||||
Logger.log("Settings", "Found valid bar monitors, keeping configuration");
|
||||
}
|
||||
} else {
|
||||
Logger.log("Settings", "Bar monitor list is empty, will show on all available screens")
|
||||
Logger.log("Settings", "Bar monitor list is empty, will show on all available screens");
|
||||
}
|
||||
}
|
||||
Item {
|
||||
Component.onCompleted: {
|
||||
|
||||
// ensure settings dir exists
|
||||
Quickshell.execDetached(["mkdir", "-p", configDir])
|
||||
Quickshell.execDetached(["mkdir", "-p", cacheDir])
|
||||
Quickshell.execDetached(["mkdir", "-p", cacheDirImages])
|
||||
Quickshell.execDetached(["mkdir", "-p", configDir]);
|
||||
Quickshell.execDetached(["mkdir", "-p", cacheDir]);
|
||||
Quickshell.execDetached(["mkdir", "-p", cacheDirImages]);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -86,39 +82,37 @@ Singleton {
|
|||
onFileChanged: reload()
|
||||
onAdapterUpdated: saveTimer.start()
|
||||
Component.onCompleted: function () {
|
||||
reload()
|
||||
reload();
|
||||
}
|
||||
onLoaded: function () {
|
||||
Qt.callLater(function () {
|
||||
if (isInitialLoad) {
|
||||
Logger.log("Settings", "OnLoaded")
|
||||
Logger.log("Settings", "OnLoaded");
|
||||
// Only set wallpaper on initial load, not on reloads
|
||||
if (adapter.wallpaper.current !== "") {
|
||||
Logger.log("Settings", "Set current wallpaper", adapter.wallpaper.current)
|
||||
WallpaperService.setCurrentWallpaper(adapter.wallpaper.current, true)
|
||||
Logger.log("Settings", "Set current wallpaper", adapter.wallpaper.current);
|
||||
WallpaperService.setCurrentWallpaper(adapter.wallpaper.current, true);
|
||||
}
|
||||
|
||||
// Validate monitor configurations, only once
|
||||
// if none of the configured monitors exist, clear the lists
|
||||
validateMonitorConfigurations()
|
||||
validateMonitorConfigurations();
|
||||
}
|
||||
|
||||
isInitialLoad = false
|
||||
})
|
||||
isInitialLoad = false;
|
||||
});
|
||||
}
|
||||
onLoadFailed: function (error) {
|
||||
if (error.toString().includes("No such file") || error === 2)
|
||||
// File doesn't exist, create it with default values
|
||||
writeAdapter()
|
||||
writeAdapter();
|
||||
}
|
||||
|
||||
JsonAdapter {
|
||||
id: adapter
|
||||
|
||||
// bar
|
||||
property JsonObject bar
|
||||
|
||||
bar: JsonObject {
|
||||
property JsonObject bar: JsonObject {
|
||||
property string position: "top" // Possible values: "top", "bottom"
|
||||
property bool showActiveWindowIcon: true
|
||||
property bool alwaysShowBatteryPercentage: false
|
||||
|
|
@ -135,9 +129,7 @@ Singleton {
|
|||
}
|
||||
|
||||
// general
|
||||
property JsonObject general
|
||||
|
||||
general: JsonObject {
|
||||
property JsonObject general: JsonObject {
|
||||
property string avatarImage: defaultAvatar
|
||||
property bool dimDesktop: false
|
||||
property bool showScreenCorners: false
|
||||
|
|
@ -145,9 +137,7 @@ Singleton {
|
|||
}
|
||||
|
||||
// location
|
||||
property JsonObject location
|
||||
|
||||
location: JsonObject {
|
||||
property JsonObject location: JsonObject {
|
||||
property string name: "Tokyo"
|
||||
property bool useFahrenheit: false
|
||||
property bool reverseDayMonth: false
|
||||
|
|
@ -156,9 +146,7 @@ Singleton {
|
|||
}
|
||||
|
||||
// screen recorder
|
||||
property JsonObject screenRecorder
|
||||
|
||||
screenRecorder: JsonObject {
|
||||
property JsonObject screenRecorder: JsonObject {
|
||||
property string directory: "~/Videos"
|
||||
property int frameRate: 60
|
||||
property string audioCodec: "opus"
|
||||
|
|
@ -171,9 +159,7 @@ Singleton {
|
|||
}
|
||||
|
||||
// wallpaper
|
||||
property JsonObject wallpaper
|
||||
|
||||
wallpaper: JsonObject {
|
||||
property JsonObject wallpaper: JsonObject {
|
||||
property string directory: "/usr/share/wallpapers"
|
||||
property string current: ""
|
||||
property bool isRandom: false
|
||||
|
|
@ -194,9 +180,7 @@ Singleton {
|
|||
}
|
||||
|
||||
// applauncher
|
||||
property JsonObject appLauncher
|
||||
|
||||
appLauncher: JsonObject {
|
||||
property JsonObject appLauncher: JsonObject {
|
||||
// When disabled, Launcher hides clipboard command and ignores cliphist
|
||||
property bool enableClipboardHistory: true
|
||||
// Position: center, top_left, top_right, bottom_left, bottom_right
|
||||
|
|
@ -205,33 +189,25 @@ Singleton {
|
|||
}
|
||||
|
||||
// dock
|
||||
property JsonObject dock
|
||||
|
||||
dock: JsonObject {
|
||||
property JsonObject dock: JsonObject {
|
||||
property bool autoHide: false
|
||||
property bool exclusive: false
|
||||
property list<string> monitors: []
|
||||
}
|
||||
|
||||
// network
|
||||
property JsonObject network
|
||||
|
||||
network: JsonObject {
|
||||
property JsonObject network: JsonObject {
|
||||
property bool wifiEnabled: true
|
||||
property bool bluetoothEnabled: true
|
||||
}
|
||||
|
||||
// notifications
|
||||
property JsonObject notifications
|
||||
|
||||
notifications: JsonObject {
|
||||
property JsonObject notifications: JsonObject {
|
||||
property list<string> monitors: []
|
||||
}
|
||||
|
||||
// audio
|
||||
property JsonObject audio
|
||||
|
||||
audio: JsonObject {
|
||||
property JsonObject audio: JsonObject {
|
||||
property bool showMiniplayerAlbumArt: false
|
||||
property bool showMiniplayerCava: false
|
||||
property string visualizerType: "linear"
|
||||
|
|
@ -240,9 +216,7 @@ Singleton {
|
|||
}
|
||||
|
||||
// ui
|
||||
property JsonObject ui
|
||||
|
||||
ui: JsonObject {
|
||||
property JsonObject ui: JsonObject {
|
||||
property string fontDefault: "Roboto" // Default font for all text
|
||||
property string fontFixed: "DejaVu Sans Mono" // Fixed width font for terminal
|
||||
property string fontBillboard: "Inter" // Large bold font for clocks and prominent displays
|
||||
|
|
@ -255,20 +229,14 @@ Singleton {
|
|||
}
|
||||
|
||||
// Scaling (not stored inside JsonObject, or it crashes)
|
||||
property var monitorsScaling: {
|
||||
|
||||
}
|
||||
property var monitorsScaling: {}
|
||||
|
||||
// brightness
|
||||
property JsonObject brightness
|
||||
|
||||
brightness: JsonObject {
|
||||
property JsonObject brightness: JsonObject {
|
||||
property int brightnessStep: 5
|
||||
}
|
||||
|
||||
property JsonObject colorSchemes
|
||||
|
||||
colorSchemes: JsonObject {
|
||||
property JsonObject colorSchemes: JsonObject {
|
||||
property bool useWallpaperColors: false
|
||||
property string predefinedScheme: ""
|
||||
property bool darkMode: true
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue