qs: add wallpaper cycling functionality
This commit is contained in:
@@ -34,6 +34,10 @@ Item {
|
||||
BackgroundService.setWallpaper(path);
|
||||
}
|
||||
|
||||
function next() {
|
||||
WallpaperCycle.applyNext();
|
||||
}
|
||||
|
||||
target: "background"
|
||||
}
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ Singleton {
|
||||
property alias location: adapter.location
|
||||
property alias backgroundPath: adapter.backgroundPath
|
||||
property alias wifiEnabled: adapter.wifiEnabled
|
||||
property alias cycleWallpapers: adapter.cycleWallpapers
|
||||
|
||||
FileView {
|
||||
id: settingFile
|
||||
@@ -34,6 +35,7 @@ Singleton {
|
||||
property string location: "New York"
|
||||
property string backgroundPath: ""
|
||||
property bool wifiEnabled: true
|
||||
property list<string> cycleWallpapers: []
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
import QtQuick
|
||||
import Quickshell
|
||||
import Quickshell.Io
|
||||
import qs.Utils
|
||||
pragma Singleton
|
||||
|
||||
Singleton {
|
||||
id: root
|
||||
|
||||
property int cycleInterval: 900 // in seconds
|
||||
property var wallpapers: SettingsService.cycleWallpapers
|
||||
|
||||
function applyNext() {
|
||||
if (root.wallpapers.length === 0) {
|
||||
Logger.w("WallpaperCycle", "No wallpapers to cycle through, skipping.");
|
||||
return ;
|
||||
}
|
||||
cycleTimer.stop();
|
||||
const current = SettingsService.backgroundPath;
|
||||
let index = -1;
|
||||
if (current) {
|
||||
for (let i = 0; i < root.wallpapers.length; i++) {
|
||||
if (root.wallpapers[i] === current) {
|
||||
index = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (index === -1) {
|
||||
Logger.w("WallpaperCycle", "Current wallpaper not found in cycle list, starting from the beginning.");
|
||||
index = 0;
|
||||
} else {
|
||||
index = (index + 1) % root.wallpapers.length;
|
||||
}
|
||||
const nextWallpaper = root.wallpapers[index];
|
||||
Logger.i("WallpaperCycle", "Cycling to next wallpaper: " + nextWallpaper);
|
||||
_apply(nextWallpaper);
|
||||
cycleTimer.start();
|
||||
}
|
||||
|
||||
function _apply(path) {
|
||||
Quickshell.execDetached(["sh", "-c", "wallreel -a '" + path + "'"]);
|
||||
}
|
||||
|
||||
Timer {
|
||||
id: cycleTimer
|
||||
|
||||
running: false
|
||||
repeat: true
|
||||
interval: root.cycleInterval * 1000
|
||||
onTriggered: {
|
||||
root.applyNext();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -23,6 +23,7 @@ ShellRoot {
|
||||
Component.onCompleted: {
|
||||
SunsetService;
|
||||
NotesService;
|
||||
WallpaperCycle;
|
||||
}
|
||||
|
||||
IPCService {
|
||||
|
||||
Reference in New Issue
Block a user