quickshell: CacheServise
This commit is contained in:
31
quickshell/Services/CacheService.qml
Normal file
31
quickshell/Services/CacheService.qml
Normal file
@@ -0,0 +1,31 @@
|
||||
import QtQuick
|
||||
import Quickshell
|
||||
import Quickshell.Io
|
||||
import qs.Utils
|
||||
pragma Singleton
|
||||
|
||||
Singleton {
|
||||
id: root
|
||||
|
||||
property string cacheDir: Quickshell.env("HOME") + "/.cache/quickshell/"
|
||||
property var cacheFiles: ["Location.json", "Ip.json", "Notifications.json", "LyricsOffset.txt"]
|
||||
property bool loaded: false
|
||||
property string locationCacheFile: cacheDir + "Location.json"
|
||||
property string ipCacheFile: cacheDir + "Ip.json"
|
||||
property string notificationsCacheFile: cacheDir + "Notifications.json"
|
||||
property string lyricsOffsetCacheFile: cacheDir + "LyricsOffset.txt"
|
||||
|
||||
Process {
|
||||
id: process
|
||||
|
||||
running: true
|
||||
command: ["sh", "-c", `mkdir -p ${cacheDir} && touch ${cacheDir + cacheFiles.join(` && touch ${cacheDir}`)}`]
|
||||
onExited: (code, status) => {
|
||||
if (code === 0)
|
||||
root.loaded = true;
|
||||
else
|
||||
Logger.error("CacheService", `Failed to create cache files: ${command.join(" ")}`);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -7,6 +7,7 @@ pragma Singleton
|
||||
|
||||
Singleton {
|
||||
property alias ip: cacheFileAdapter.ip
|
||||
property string cacheFilePath: CacheService.ipCacheFile
|
||||
property string countryCode: "N/A"
|
||||
property real fetchInterval: 120 // in s
|
||||
property real fetchTimeout: 10 // in s
|
||||
@@ -150,7 +151,7 @@ Singleton {
|
||||
FileView {
|
||||
id: cacheFile
|
||||
|
||||
path: Qt.resolvedUrl("../Assets/Config/IpCache.json")
|
||||
path: cacheFilePath
|
||||
watchChanges: false
|
||||
onLoaded: {
|
||||
Logger.log("IpService", "Loaded IP from cache file: " + cacheFileAdapter.ip);
|
||||
|
||||
@@ -12,8 +12,8 @@ Singleton {
|
||||
|
||||
id: root
|
||||
|
||||
property string locationName: "Munich"
|
||||
property string locationFile: Qt.resolvedUrl("../Assets/Config/Location.json")
|
||||
property string locationName: SettingsService.location
|
||||
property string locationFile: CacheService.locationCacheFile
|
||||
property int weatherUpdateFrequency: 30 * 60 // 30 minutes expressed in seconds
|
||||
property bool isFetchingWeather: false
|
||||
readonly property alias data: adapter // Used to access via LocationService.data.xxx from outside, best to use "adapter" inside the service.
|
||||
|
||||
@@ -9,7 +9,7 @@ Singleton {
|
||||
property int linesCount: 3
|
||||
property int linesAhead: linesCount / 2
|
||||
property int currentIndex: linesCount - linesAhead - 1
|
||||
property string offsetFile: Qt.resolvedUrl("../Assets/Config/LyricsOffset.txt")
|
||||
property string offsetFile: CacheService.lyricsOffsetCacheFile
|
||||
property int offset: 0 // in ms
|
||||
property int offsetStep: 500 // in ms
|
||||
property int referenceCount: 0
|
||||
@@ -26,7 +26,7 @@ Singleton {
|
||||
Logger.log("LyricsService", "Starting lyrics syncing");
|
||||
// fill lyrics with empty lines
|
||||
lyrics = Array(linesCount).fill(" ");
|
||||
listenProcess.exec(["sh", "-c", `sl-wrap listen -l ${linesCount} -a ${linesAhead} -f ${offsetFile.slice(7)}`]);
|
||||
listenProcess.exec(["sh", "-c", `sl-wrap listen -l ${linesCount} -a ${linesAhead} -f ${offsetFile}`]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -127,17 +127,14 @@ Singleton {
|
||||
writeOffset();
|
||||
}
|
||||
} catch (e) {
|
||||
Logger.log("LyricsService", "Error reading offset file:", e);
|
||||
Logger.error("LyricsService", "Error reading offset file:", e);
|
||||
}
|
||||
}
|
||||
onLoadFailed: {
|
||||
Logger.log("LyricsService", "Error loading offset file:", errorString);
|
||||
Logger.error("LyricsService", "Error loading offset file:", errorString);
|
||||
}
|
||||
onSaveFailed: {
|
||||
Logger.log("LyricsService", "Error saving offset file:", errorString);
|
||||
}
|
||||
onSaved: {
|
||||
Logger.log("LyricsService", "Offset file saved.");
|
||||
Logger.error("LyricsService", "Error saving offset file:", errorString);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -14,15 +14,15 @@ Singleton {
|
||||
property bool noFocus: focusedWindowId === -1
|
||||
property bool inOverview: false
|
||||
property string focusedWindowTitle: ""
|
||||
// property string focusedWindowAppId: ""
|
||||
property string focusedWindowAppId: ""
|
||||
|
||||
function updateFocusedWindowTitle() {
|
||||
if (windows && windows[focusedWindowId]) {
|
||||
focusedWindowTitle = windows[focusedWindowId].title || "";
|
||||
// focusedWindowAppId = windows[focusedWindowId].appId || "";
|
||||
focusedWindowAppId = windows[focusedWindowId].appId || "";
|
||||
} else {
|
||||
focusedWindowTitle = "";
|
||||
// focusedWindowAppId = "";
|
||||
focusedWindowAppId = "";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,8 +30,6 @@ Singleton {
|
||||
return (windows && windows[focusedWindowId]) || null;
|
||||
}
|
||||
|
||||
onWindowsChanged: updateFocusedWindowTitle()
|
||||
onFocusedWindowIdChanged: updateFocusedWindowTitle()
|
||||
Component.onCompleted: {
|
||||
eventStream.running = true;
|
||||
}
|
||||
@@ -102,6 +100,7 @@ Singleton {
|
||||
};
|
||||
}
|
||||
root.windows = windowsMap;
|
||||
root.updateFocusedWindowTitle();
|
||||
} catch (e) {
|
||||
Logger.error("Niri", "Error parsing windows event:", e);
|
||||
}
|
||||
@@ -120,6 +119,7 @@ Singleton {
|
||||
} else {
|
||||
root.focusedWindowId = -1;
|
||||
}
|
||||
root.updateFocusedWindowTitle();
|
||||
} catch (e) {
|
||||
Logger.error("Niri", "Error parsing window focus event:", e);
|
||||
}
|
||||
@@ -155,9 +155,10 @@ Singleton {
|
||||
root.windows[id] = targetWin;
|
||||
}
|
||||
if (isFocused) {
|
||||
root.focusedWindowId = id;
|
||||
if (needUpdateTitle)
|
||||
if (root.focusedWindowId !== id || needUpdateTitle){
|
||||
root.focusedWindowId = id;
|
||||
root.updateFocusedWindowTitle();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -169,6 +170,10 @@ Singleton {
|
||||
const closedId = event.windowClosed.id;
|
||||
if (closedId && (root.windows && root.windows[closedId])) {
|
||||
delete root.windows[closedId];
|
||||
if (root.focusedWindowId === closedId) {
|
||||
root.focusedWindowId = -1;
|
||||
root.updateFocusedWindowTitle();
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
Logger.error("Niri", "Error parsing window closed event:", e);
|
||||
|
||||
@@ -16,7 +16,7 @@ Singleton {
|
||||
// Configuration
|
||||
property int maxVisible: 5
|
||||
property int maxHistory: 100
|
||||
property string historyFile: Qt.resolvedUrl("../Assets/Config/Notifications.json")
|
||||
property string historyFile: CacheService.notificationsCacheFile
|
||||
property string cacheDirImagesNotifications: Quickshell.env("HOME") + "/.cache/quickshell/notifications/"
|
||||
property real lowUrgencyDuration: 3
|
||||
property real normalUrgencyDuration: 8
|
||||
|
||||
@@ -9,6 +9,7 @@ Singleton {
|
||||
property alias primaryColor: adapter.primaryColor
|
||||
property alias showLyricsBar: adapter.showLyricsBar
|
||||
property alias notifications: adapter.notifications
|
||||
property alias location: adapter.location
|
||||
property string settingsFilePath: Qt.resolvedUrl("../Assets/Config/Settings.json")
|
||||
|
||||
FileView {
|
||||
@@ -25,6 +26,7 @@ Singleton {
|
||||
property string primaryColor: "#89b4fa"
|
||||
property bool showLyricsBar: false
|
||||
property JsonObject notifications
|
||||
property string location: "New York"
|
||||
|
||||
notifications: JsonObject {
|
||||
property bool doNotDisturb: false
|
||||
|
||||
Reference in New Issue
Block a user