@@ -42,14 +42,30 @@ WallpaperItem {
4242 }
4343 property int currentVideoIndex: 0
4444 property bool resumeLastVideo: main .configuration .ResumeLastVideo
45- property bool dayNightCycle: main .configuration .DayNightCycle
46- property bool isDay: {
47- const currentTime = new Date ().getHours ();
48- return currentTime >= 6 && currentTime < 19 ;
45+ property bool dayNightCycleEnabled: main .configuration .DayNightCycleEnabled
46+
47+ function detectDayTime () {
48+ let mode = main .configuration .DayNightCycleMode ;
49+ switch (mode) {
50+ case Enum .DayNightCycleMode .Time :
51+ // if (KNightTimePlugin) {
52+ // return ...;
53+ // }
54+ const { DayNightCycleSunriseTime , DayNightCycleSunsetTime } = main .configuration ;
55+ const now = new Date ();
56+ const currentTime = now .getHours () * 60 + now .getMinutes ();
57+
58+ return currentTime >= DayNightCycleSunriseTime && currentTime < DayNightCycleSunsetTime;
59+ case Enum .DayNightCycleMode .PlasmaStyle : return Qt .styleHints .colorScheme === Qt .ColorScheme .Light ;
60+ case Enum .DayNightCycleMode .AlwaysNight : return false ;
61+ case Enum .DayNightCycleMode .AlwaysDay :
62+ default : return true ;
63+ }
4964 }
65+ property bool isDay: detectDayTime ()
5066
5167 function getLastVideo () {
52- if (dayNightCycle ) {
68+ if (dayNightCycleEnabled ) {
5369 return main .configuration [isDay ? " LastVideoDay" : " LastVideoNight" ];
5470 }
5571 return main .configuration .LastVideo ;
@@ -220,7 +236,7 @@ WallpaperItem {
220236 }
221237
222238 function getVideos () {
223- if (dayNightCycle ) {
239+ if (dayNightCycleEnabled ) {
224240 return Utils .parseCompat (videoUrls).filter (video => {
225241 const isDayCycle = video .dayNightCycleAssignment !== Enum .DayNightCycleAssignment .Night ;
226242 const isNightCycle = video .dayNightCycleAssignment !== Enum .DayNightCycleAssignment .Day ;
@@ -300,31 +316,20 @@ WallpaperItem {
300316 repeat: true
301317 triggeredOnStart: true
302318 onTriggered: {
303- const dayNightCycleConfigChanged = dayNightCycle !== main .configuration .DayNightCycle ;
304- if (! dayNightCycleConfigChanged && ! main .configuration .DayNightCycle ) {
319+ const dayNightCycleEnabledChanged = dayNightCycleEnabled !== main .configuration .DayNightCycleEnabled ;
320+ if (( ! dayNightCycleEnabledChanged && ! main .configuration .DayNightCycleEnabled ) || main . isLoading ) {
305321 return ;
306322 }
307- dayNightCycle = main .configuration .DayNightCycle ;
323+ dayNightCycleEnabled = main .configuration .DayNightCycleEnabled ;
308324
309- const hours = new Date ().getHours ();
310- const isDay = hours >= 6 && hours < 19 ;
325+ const isDay = detectDayTime ();
311326
312- if ((main .isDay != isDay) || dayNightCycleConfigChanged ) {
327+ if ((main .isDay != isDay) || dayNightCycleEnabledChanged ) {
313328 main .save ();
314329 main .isDay = isDay;
315330 videosConfig = getVideos ();
316331
317- if (getLastVideo () === " " ) {
318- setCurrentSource (0 );
319- return player .next ();
320- }
321-
322- currentVideoIndex = getLastVideoIndex ();
323-
324- if (main .configuration .ResumeLastVideo ) {
325- // TODO: Resume last (day/night) video when changing from day to night or vice versa
326- }
327-
332+ currentVideoIndex = main .configuration .ResumeLastVideo ? getLastVideoIndex () : 0 ;
328333 setCurrentSource (currentVideoIndex);
329334
330335 player .next ();
@@ -538,7 +543,7 @@ WallpaperItem {
538543 // Save last video and position to resume from it on next login/lock
539544 main.configuration.LastVideo = main.currentSource.filename;
540545 main.configuration.LastVideoPosition = player.lastVideoPosition;
541- if(dayNightCycle ) {
546+ if(dayNightCycleEnabled ) {
542547 main.configuration[main.isDay ? "LastVideoDay" : "LastVideoNight"] = main.currentSource.filename;
543548 }
544549 main.configuration.writeConfig();
0 commit comments