1
0
mirror of https://github.com/AvengeMedia/DankMaterialShell.git synced 2026-01-30 00:12:50 -05:00

wallpaper: disable cycling if any toplevel is full screen

This commit is contained in:
bbedward
2025-11-24 22:28:53 -05:00
parent df940124b1
commit c2787f1282
2 changed files with 183 additions and 166 deletions

View File

@@ -3,7 +3,6 @@ import QtQuick.Layouts
import qs.Common import qs.Common
import qs.Services import qs.Services
import qs.Widgets import qs.Widgets
import qs.Modules.DankDash
DankPopout { DankPopout {
id: root id: root

View File

@@ -4,12 +4,21 @@ pragma ComponentBehavior: Bound
import QtQuick import QtQuick
import Quickshell import Quickshell
import Quickshell.Io import Quickshell.Io
import qs.Common import Quickshell.Wayland
Singleton { Singleton {
id: root id: root
property bool cyclingActive: false property bool cyclingActive: false
readonly property bool anyFullscreen: {
if (!ToplevelManager.toplevels?.values)
return false;
for (const toplevel of ToplevelManager.toplevels.values) {
if (toplevel.fullscreen)
return true;
}
return false;
}
property string cachedCyclingTime: SessionData.wallpaperCyclingTime property string cachedCyclingTime: SessionData.wallpaperCyclingTime
property int cachedCyclingInterval: SessionData.wallpaperCyclingInterval property int cachedCyclingInterval: SessionData.wallpaperCyclingInterval
property string lastTimeCheck: "" property string lastTimeCheck: ""
@@ -24,8 +33,8 @@ Singleton {
running: false running: false
repeat: true repeat: true
onTriggered: { onTriggered: {
if (typeof WallpaperCyclingService !== "undefined" && targetScreen !== "") { if (typeof WallpaperCyclingService !== "undefined" && targetScreen !== "" && !WallpaperCyclingService.anyFullscreen) {
WallpaperCyclingService.cycleNextForMonitor(targetScreen) WallpaperCyclingService.cycleNextForMonitor(targetScreen);
} }
} }
} }
@@ -41,24 +50,26 @@ Singleton {
stdout: StdioCollector { stdout: StdioCollector {
onStreamFinished: { onStreamFinished: {
if (text && text.trim()) { if (text && text.trim()) {
const files = text.trim().split('\n').filter(file => file.length > 0) const files = text.trim().split('\n').filter(file => file.length > 0);
if (files.length <= 1) return if (files.length <= 1)
const wallpaperList = files.sort() return;
const currentPath = currentWallpaper const wallpaperList = files.sort();
let currentIndex = wallpaperList.findIndex(path => path === currentPath) const currentPath = currentWallpaper;
if (currentIndex === -1) currentIndex = 0 let currentIndex = wallpaperList.findIndex(path => path === currentPath);
let targetIndex if (currentIndex === -1)
currentIndex = 0;
let targetIndex;
if (goToPrevious) { if (goToPrevious) {
targetIndex = currentIndex === 0 ? wallpaperList.length - 1 : currentIndex - 1 targetIndex = currentIndex === 0 ? wallpaperList.length - 1 : currentIndex - 1;
} else { } else {
targetIndex = (currentIndex + 1) % wallpaperList.length targetIndex = (currentIndex + 1) % wallpaperList.length;
} }
const targetWallpaper = wallpaperList[targetIndex] const targetWallpaper = wallpaperList[targetIndex];
if (targetWallpaper && targetWallpaper !== currentPath) { if (targetWallpaper && targetWallpaper !== currentPath) {
if (targetScreenName) { if (targetScreenName) {
SessionData.setMonitorWallpaper(targetScreenName, targetWallpaper) SessionData.setMonitorWallpaper(targetScreenName, targetWallpaper);
} else { } else {
SessionData.setWallpaper(targetWallpaper) SessionData.setWallpaper(targetWallpaper);
} }
} }
} }
@@ -71,205 +82,205 @@ Singleton {
target: SessionData target: SessionData
function onWallpaperCyclingEnabledChanged() { function onWallpaperCyclingEnabledChanged() {
updateCyclingState() updateCyclingState();
} }
function onWallpaperCyclingModeChanged() { function onWallpaperCyclingModeChanged() {
updateCyclingState() updateCyclingState();
} }
function onWallpaperCyclingIntervalChanged() { function onWallpaperCyclingIntervalChanged() {
cachedCyclingInterval = SessionData.wallpaperCyclingInterval cachedCyclingInterval = SessionData.wallpaperCyclingInterval;
if (SessionData.wallpaperCyclingMode === "interval") { if (SessionData.wallpaperCyclingMode === "interval") {
updateCyclingState() updateCyclingState();
} }
} }
function onWallpaperCyclingTimeChanged() { function onWallpaperCyclingTimeChanged() {
cachedCyclingTime = SessionData.wallpaperCyclingTime cachedCyclingTime = SessionData.wallpaperCyclingTime;
if (SessionData.wallpaperCyclingMode === "time") { if (SessionData.wallpaperCyclingMode === "time") {
updateCyclingState() updateCyclingState();
} }
} }
function onPerMonitorWallpaperChanged() { function onPerMonitorWallpaperChanged() {
updateCyclingState() updateCyclingState();
} }
function onMonitorCyclingSettingsChanged() { function onMonitorCyclingSettingsChanged() {
updateCyclingState() updateCyclingState();
} }
} }
function updateCyclingState() { function updateCyclingState() {
if (SessionData.perMonitorWallpaper) { if (SessionData.perMonitorWallpaper) {
stopCycling() stopCycling();
updatePerMonitorCycling() updatePerMonitorCycling();
} else if (SessionData.wallpaperCyclingEnabled && SessionData.wallpaperPath) { } else if (SessionData.wallpaperCyclingEnabled && SessionData.wallpaperPath) {
startCycling() startCycling();
stopAllMonitorCycling() stopAllMonitorCycling();
} else { } else {
stopCycling() stopCycling();
stopAllMonitorCycling() stopAllMonitorCycling();
} }
} }
function updatePerMonitorCycling() { function updatePerMonitorCycling() {
if (typeof Quickshell === "undefined") return if (typeof Quickshell === "undefined")
return;
var screens = Quickshell.screens var screens = Quickshell.screens;
for (var i = 0; i < screens.length; i++) { for (var i = 0; i < screens.length; i++) {
var screenName = screens[i].name var screenName = screens[i].name;
var settings = SessionData.getMonitorCyclingSettings(screenName) var settings = SessionData.getMonitorCyclingSettings(screenName);
var wallpaper = SessionData.getMonitorWallpaper(screenName) var wallpaper = SessionData.getMonitorWallpaper(screenName);
if (settings.enabled && wallpaper && !wallpaper.startsWith("#")) { if (settings.enabled && wallpaper && !wallpaper.startsWith("#")) {
startMonitorCycling(screenName, settings) startMonitorCycling(screenName, settings);
} else { } else {
stopMonitorCycling(screenName) stopMonitorCycling(screenName);
} }
} }
} }
function stopAllMonitorCycling() { function stopAllMonitorCycling() {
var screenNames = Object.keys(monitorTimers) var screenNames = Object.keys(monitorTimers);
for (var i = 0; i < screenNames.length; i++) { for (var i = 0; i < screenNames.length; i++) {
stopMonitorCycling(screenNames[i]) stopMonitorCycling(screenNames[i]);
} }
} }
function startCycling() { function startCycling() {
if (SessionData.wallpaperCyclingMode === "interval") { if (SessionData.wallpaperCyclingMode === "interval") {
intervalTimer.interval = cachedCyclingInterval * 1000 intervalTimer.interval = cachedCyclingInterval * 1000;
intervalTimer.start() intervalTimer.start();
cyclingActive = true cyclingActive = true;
} else if (SessionData.wallpaperCyclingMode === "time") { } else if (SessionData.wallpaperCyclingMode === "time") {
cyclingActive = true cyclingActive = true;
checkTimeBasedCycling() checkTimeBasedCycling();
} }
} }
function stopCycling() { function stopCycling() {
intervalTimer.stop() intervalTimer.stop();
cyclingActive = false cyclingActive = false;
} }
function startMonitorCycling(screenName, settings) { function startMonitorCycling(screenName, settings) {
if (settings.mode === "interval") { if (settings.mode === "interval") {
var timer = monitorTimers[screenName] var timer = monitorTimers[screenName];
if (!timer && monitorTimerComponent && monitorTimerComponent.status === Component.Ready) { if (!timer && monitorTimerComponent && monitorTimerComponent.status === Component.Ready) {
var newTimers = Object.assign({}, monitorTimers) var newTimers = Object.assign({}, monitorTimers);
newTimers[screenName] = monitorTimerComponent.createObject(root) newTimers[screenName] = monitorTimerComponent.createObject(root);
newTimers[screenName].targetScreen = screenName newTimers[screenName].targetScreen = screenName;
monitorTimers = newTimers monitorTimers = newTimers;
timer = monitorTimers[screenName] timer = monitorTimers[screenName];
} }
if (timer) { if (timer) {
timer.interval = settings.interval * 1000 timer.interval = settings.interval * 1000;
timer.start() timer.start();
} }
} else if (settings.mode === "time") { } else if (settings.mode === "time") {
var newChecks = Object.assign({}, monitorLastTimeChecks) var newChecks = Object.assign({}, monitorLastTimeChecks);
newChecks[screenName] = "" newChecks[screenName] = "";
monitorLastTimeChecks = newChecks monitorLastTimeChecks = newChecks;
} }
} }
function stopMonitorCycling(screenName) { function stopMonitorCycling(screenName) {
var timer = monitorTimers[screenName] var timer = monitorTimers[screenName];
if (timer) { if (timer) {
timer.stop() timer.stop();
timer.destroy() timer.destroy();
var newTimers = Object.assign({}, monitorTimers) var newTimers = Object.assign({}, monitorTimers);
delete newTimers[screenName] delete newTimers[screenName];
monitorTimers = newTimers monitorTimers = newTimers;
} }
var process = monitorProcesses[screenName] var process = monitorProcesses[screenName];
if (process) { if (process) {
process.destroy() process.destroy();
var newProcesses = Object.assign({}, monitorProcesses) var newProcesses = Object.assign({}, monitorProcesses);
delete newProcesses[screenName] delete newProcesses[screenName];
monitorProcesses = newProcesses monitorProcesses = newProcesses;
} }
var newChecks = Object.assign({}, monitorLastTimeChecks) var newChecks = Object.assign({}, monitorLastTimeChecks);
delete newChecks[screenName] delete newChecks[screenName];
monitorLastTimeChecks = newChecks monitorLastTimeChecks = newChecks;
} }
function cycleToNextWallpaper(screenName, wallpaperPath) { function cycleToNextWallpaper(screenName, wallpaperPath) {
const currentWallpaper = wallpaperPath || SessionData.wallpaperPath const currentWallpaper = wallpaperPath || SessionData.wallpaperPath;
if (!currentWallpaper) return if (!currentWallpaper)
return;
const wallpaperDir = currentWallpaper.substring(0, currentWallpaper.lastIndexOf('/')) const wallpaperDir = currentWallpaper.substring(0, currentWallpaper.lastIndexOf('/'));
if (screenName && monitorProcessComponent && monitorProcessComponent.status === Component.Ready) { if (screenName && monitorProcessComponent && monitorProcessComponent.status === Component.Ready) {
// Use per-monitor process // Use per-monitor process
var process = monitorProcesses[screenName] var process = monitorProcesses[screenName];
if (!process) { if (!process) {
var newProcesses = Object.assign({}, monitorProcesses) var newProcesses = Object.assign({}, monitorProcesses);
newProcesses[screenName] = monitorProcessComponent.createObject(root) newProcesses[screenName] = monitorProcessComponent.createObject(root);
monitorProcesses = newProcesses monitorProcesses = newProcesses;
process = monitorProcesses[screenName] process = monitorProcesses[screenName];
} }
if (process) { if (process) {
process.command = ["sh", "-c", `ls -1 "${wallpaperDir}"/*.jpg "${wallpaperDir}"/*.jpeg "${wallpaperDir}"/*.png "${wallpaperDir}"/*.bmp "${wallpaperDir}"/*.gif "${wallpaperDir}"/*.webp 2>/dev/null | sort`] process.command = ["sh", "-c", `ls -1 "${wallpaperDir}"/*.jpg "${wallpaperDir}"/*.jpeg "${wallpaperDir}"/*.png "${wallpaperDir}"/*.bmp "${wallpaperDir}"/*.gif "${wallpaperDir}"/*.webp 2>/dev/null | sort`];
process.targetScreenName = screenName process.targetScreenName = screenName;
process.currentWallpaper = currentWallpaper process.currentWallpaper = currentWallpaper;
process.goToPrevious = false process.goToPrevious = false;
process.running = true process.running = true;
} }
} else { } else {
// Use global process for fallback // Use global process for fallback
cyclingProcess.command = ["sh", "-c", `ls -1 "${wallpaperDir}"/*.jpg "${wallpaperDir}"/*.jpeg "${wallpaperDir}"/*.png "${wallpaperDir}"/*.bmp "${wallpaperDir}"/*.gif "${wallpaperDir}"/*.webp 2>/dev/null | sort`] cyclingProcess.command = ["sh", "-c", `ls -1 "${wallpaperDir}"/*.jpg "${wallpaperDir}"/*.jpeg "${wallpaperDir}"/*.png "${wallpaperDir}"/*.bmp "${wallpaperDir}"/*.gif "${wallpaperDir}"/*.webp 2>/dev/null | sort`];
cyclingProcess.targetScreenName = screenName || "" cyclingProcess.targetScreenName = screenName || "";
cyclingProcess.currentWallpaper = currentWallpaper cyclingProcess.currentWallpaper = currentWallpaper;
cyclingProcess.running = true cyclingProcess.running = true;
} }
} }
function cycleToPrevWallpaper(screenName, wallpaperPath) { function cycleToPrevWallpaper(screenName, wallpaperPath) {
const currentWallpaper = wallpaperPath || SessionData.wallpaperPath const currentWallpaper = wallpaperPath || SessionData.wallpaperPath;
if (!currentWallpaper) return if (!currentWallpaper)
return;
const wallpaperDir = currentWallpaper.substring(0, currentWallpaper.lastIndexOf('/')) const wallpaperDir = currentWallpaper.substring(0, currentWallpaper.lastIndexOf('/'));
if (screenName && monitorProcessComponent && monitorProcessComponent.status === Component.Ready) { if (screenName && monitorProcessComponent && monitorProcessComponent.status === Component.Ready) {
// Use per-monitor process (same as next, but with prev flag) // Use per-monitor process (same as next, but with prev flag)
var process = monitorProcesses[screenName] var process = monitorProcesses[screenName];
if (!process) { if (!process) {
var newProcesses = Object.assign({}, monitorProcesses) var newProcesses = Object.assign({}, monitorProcesses);
newProcesses[screenName] = monitorProcessComponent.createObject(root) newProcesses[screenName] = monitorProcessComponent.createObject(root);
monitorProcesses = newProcesses monitorProcesses = newProcesses;
process = monitorProcesses[screenName] process = monitorProcesses[screenName];
} }
if (process) { if (process) {
process.command = ["sh", "-c", `ls -1 "${wallpaperDir}"/*.jpg "${wallpaperDir}"/*.jpeg "${wallpaperDir}"/*.png "${wallpaperDir}"/*.bmp "${wallpaperDir}"/*.gif "${wallpaperDir}"/*.webp 2>/dev/null | sort`] process.command = ["sh", "-c", `ls -1 "${wallpaperDir}"/*.jpg "${wallpaperDir}"/*.jpeg "${wallpaperDir}"/*.png "${wallpaperDir}"/*.bmp "${wallpaperDir}"/*.gif "${wallpaperDir}"/*.webp 2>/dev/null | sort`];
process.targetScreenName = screenName process.targetScreenName = screenName;
process.currentWallpaper = currentWallpaper process.currentWallpaper = currentWallpaper;
process.goToPrevious = true process.goToPrevious = true;
process.running = true process.running = true;
} }
} else { } else {
// Use global process for fallback // Use global process for fallback
prevCyclingProcess.command = ["sh", "-c", `ls -1 "${wallpaperDir}"/*.jpg "${wallpaperDir}"/*.jpeg "${wallpaperDir}"/*.png "${wallpaperDir}"/*.bmp "${wallpaperDir}"/*.gif "${wallpaperDir}"/*.webp 2>/dev/null | sort`] prevCyclingProcess.command = ["sh", "-c", `ls -1 "${wallpaperDir}"/*.jpg "${wallpaperDir}"/*.jpeg "${wallpaperDir}"/*.png "${wallpaperDir}"/*.bmp "${wallpaperDir}"/*.gif "${wallpaperDir}"/*.webp 2>/dev/null | sort`];
prevCyclingProcess.targetScreenName = screenName || "" prevCyclingProcess.targetScreenName = screenName || "";
prevCyclingProcess.currentWallpaper = currentWallpaper prevCyclingProcess.currentWallpaper = currentWallpaper;
prevCyclingProcess.running = true prevCyclingProcess.running = true;
} }
} }
function cycleNextManually() { function cycleNextManually() {
if (SessionData.wallpaperPath) { if (SessionData.wallpaperPath) {
cycleToNextWallpaper() cycleToNextWallpaper();
// Restart timers if cycling is active // Restart timers if cycling is active
if (cyclingActive && SessionData.wallpaperCyclingEnabled) { if (cyclingActive && SessionData.wallpaperCyclingEnabled) {
if (SessionData.wallpaperCyclingMode === "interval") { if (SessionData.wallpaperCyclingMode === "interval") {
intervalTimer.interval = cachedCyclingInterval * 1000 intervalTimer.interval = cachedCyclingInterval * 1000;
intervalTimer.restart() intervalTimer.restart();
} }
} }
} }
@@ -277,71 +288,73 @@ Singleton {
function cyclePrevManually() { function cyclePrevManually() {
if (SessionData.wallpaperPath) { if (SessionData.wallpaperPath) {
cycleToPrevWallpaper() cycleToPrevWallpaper();
// Restart timers if cycling is active // Restart timers if cycling is active
if (cyclingActive && SessionData.wallpaperCyclingEnabled) { if (cyclingActive && SessionData.wallpaperCyclingEnabled) {
if (SessionData.wallpaperCyclingMode === "interval") { if (SessionData.wallpaperCyclingMode === "interval") {
intervalTimer.interval = cachedCyclingInterval * 1000 intervalTimer.interval = cachedCyclingInterval * 1000;
intervalTimer.restart() intervalTimer.restart();
} }
} }
} }
} }
function cycleNextForMonitor(screenName) { function cycleNextForMonitor(screenName) {
if (!screenName) return if (!screenName)
return;
var currentWallpaper = SessionData.getMonitorWallpaper(screenName) var currentWallpaper = SessionData.getMonitorWallpaper(screenName);
if (currentWallpaper) { if (currentWallpaper) {
cycleToNextWallpaper(screenName, currentWallpaper) cycleToNextWallpaper(screenName, currentWallpaper);
} }
} }
function cyclePrevForMonitor(screenName) { function cyclePrevForMonitor(screenName) {
if (!screenName) return if (!screenName)
return;
var currentWallpaper = SessionData.getMonitorWallpaper(screenName) var currentWallpaper = SessionData.getMonitorWallpaper(screenName);
if (currentWallpaper) { if (currentWallpaper) {
cycleToPrevWallpaper(screenName, currentWallpaper) cycleToPrevWallpaper(screenName, currentWallpaper);
} }
} }
function checkTimeBasedCycling() { function checkTimeBasedCycling() {
const currentTime = Qt.formatTime(systemClock.date, "hh:mm") if (anyFullscreen)
return;
const currentTime = Qt.formatTime(systemClock.date, "hh:mm");
if (!SessionData.perMonitorWallpaper) { if (!SessionData.perMonitorWallpaper) {
if (currentTime === cachedCyclingTime && currentTime !== lastTimeCheck) { if (currentTime === cachedCyclingTime && currentTime !== lastTimeCheck) {
lastTimeCheck = currentTime lastTimeCheck = currentTime;
cycleToNextWallpaper() cycleToNextWallpaper();
} else if (currentTime !== cachedCyclingTime) { } else if (currentTime !== cachedCyclingTime) {
lastTimeCheck = "" lastTimeCheck = "";
} }
} else { } else {
checkPerMonitorTimeBasedCycling(currentTime) checkPerMonitorTimeBasedCycling(currentTime);
} }
} }
function checkPerMonitorTimeBasedCycling(currentTime) { function checkPerMonitorTimeBasedCycling(currentTime) {
if (typeof Quickshell === "undefined") return if (typeof Quickshell === "undefined")
return;
var screens = Quickshell.screens var screens = Quickshell.screens;
for (var i = 0; i < screens.length; i++) { for (var i = 0; i < screens.length; i++) {
var screenName = screens[i].name var screenName = screens[i].name;
var settings = SessionData.getMonitorCyclingSettings(screenName) var settings = SessionData.getMonitorCyclingSettings(screenName);
var wallpaper = SessionData.getMonitorWallpaper(screenName) var wallpaper = SessionData.getMonitorWallpaper(screenName);
if (settings.enabled && settings.mode === "time" && wallpaper && !wallpaper.startsWith("#")) { if (settings.enabled && settings.mode === "time" && wallpaper && !wallpaper.startsWith("#")) {
var lastCheck = monitorLastTimeChecks[screenName] || "" var lastCheck = monitorLastTimeChecks[screenName] || "";
if (currentTime === settings.time && currentTime !== lastCheck) { if (currentTime === settings.time && currentTime !== lastCheck) {
var newChecks = Object.assign({}, monitorLastTimeChecks) var newChecks = Object.assign({}, monitorLastTimeChecks);
newChecks[screenName] = currentTime newChecks[screenName] = currentTime;
monitorLastTimeChecks = newChecks monitorLastTimeChecks = newChecks;
cycleNextForMonitor(screenName) cycleNextForMonitor(screenName);
} else if (currentTime !== settings.time) { } else if (currentTime !== settings.time) {
var newChecks = Object.assign({}, monitorLastTimeChecks) var newChecks = Object.assign({}, monitorLastTimeChecks);
newChecks[screenName] = "" newChecks[screenName] = "";
monitorLastTimeChecks = newChecks monitorLastTimeChecks = newChecks;
} }
} }
} }
@@ -352,7 +365,11 @@ Singleton {
interval: cachedCyclingInterval * 1000 interval: cachedCyclingInterval * 1000
running: false running: false
repeat: true repeat: true
onTriggered: cycleToNextWallpaper() onTriggered: {
if (anyFullscreen)
return;
cycleToNextWallpaper();
}
} }
SystemClock { SystemClock {
@@ -360,7 +377,7 @@ Singleton {
precision: SystemClock.Minutes precision: SystemClock.Minutes
onDateChanged: { onDateChanged: {
if ((SessionData.wallpaperCyclingMode === "time" && cyclingActive) || SessionData.perMonitorWallpaper) { if ((SessionData.wallpaperCyclingMode === "time" && cyclingActive) || SessionData.perMonitorWallpaper) {
checkTimeBasedCycling() checkTimeBasedCycling();
} }
} }
} }
@@ -376,22 +393,23 @@ Singleton {
stdout: StdioCollector { stdout: StdioCollector {
onStreamFinished: { onStreamFinished: {
if (text && text.trim()) { if (text && text.trim()) {
const files = text.trim().split('\n').filter(file => file.length > 0) const files = text.trim().split('\n').filter(file => file.length > 0);
if (files.length <= 1) return if (files.length <= 1)
return;
const wallpaperList = files.sort();
const currentPath = cyclingProcess.currentWallpaper;
let currentIndex = wallpaperList.findIndex(path => path === currentPath);
if (currentIndex === -1)
currentIndex = 0;
const wallpaperList = files.sort() const nextIndex = (currentIndex + 1) % wallpaperList.length;
const currentPath = cyclingProcess.currentWallpaper const nextWallpaper = wallpaperList[nextIndex];
let currentIndex = wallpaperList.findIndex(path => path === currentPath)
if (currentIndex === -1) currentIndex = 0
const nextIndex = (currentIndex + 1) % wallpaperList.length
const nextWallpaper = wallpaperList[nextIndex]
if (nextWallpaper && nextWallpaper !== currentPath) { if (nextWallpaper && nextWallpaper !== currentPath) {
if (cyclingProcess.targetScreenName) { if (cyclingProcess.targetScreenName) {
SessionData.setMonitorWallpaper(cyclingProcess.targetScreenName, nextWallpaper) SessionData.setMonitorWallpaper(cyclingProcess.targetScreenName, nextWallpaper);
} else { } else {
SessionData.setWallpaper(nextWallpaper) SessionData.setWallpaper(nextWallpaper);
} }
} }
} }
@@ -410,27 +428,27 @@ Singleton {
stdout: StdioCollector { stdout: StdioCollector {
onStreamFinished: { onStreamFinished: {
if (text && text.trim()) { if (text && text.trim()) {
const files = text.trim().split('\n').filter(file => file.length > 0) const files = text.trim().split('\n').filter(file => file.length > 0);
if (files.length <= 1) return if (files.length <= 1)
return;
const wallpaperList = files.sort();
const currentPath = prevCyclingProcess.currentWallpaper;
let currentIndex = wallpaperList.findIndex(path => path === currentPath);
if (currentIndex === -1)
currentIndex = 0;
const wallpaperList = files.sort() const prevIndex = currentIndex === 0 ? wallpaperList.length - 1 : currentIndex - 1;
const currentPath = prevCyclingProcess.currentWallpaper const prevWallpaper = wallpaperList[prevIndex];
let currentIndex = wallpaperList.findIndex(path => path === currentPath)
if (currentIndex === -1) currentIndex = 0
const prevIndex = currentIndex === 0 ? wallpaperList.length - 1 : currentIndex - 1
const prevWallpaper = wallpaperList[prevIndex]
if (prevWallpaper && prevWallpaper !== currentPath) { if (prevWallpaper && prevWallpaper !== currentPath) {
if (prevCyclingProcess.targetScreenName) { if (prevCyclingProcess.targetScreenName) {
SessionData.setMonitorWallpaper(prevCyclingProcess.targetScreenName, prevWallpaper) SessionData.setMonitorWallpaper(prevCyclingProcess.targetScreenName, prevWallpaper);
} else { } else {
SessionData.setWallpaper(prevWallpaper) SessionData.setWallpaper(prevWallpaper);
} }
} }
} }
} }
} }
} }
} }