@@ -42,29 +42,7 @@ 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 ;
49- }
50-
51- function getLastVideo () {
52- if (dayNightCycle) {
53- return main .configuration [isDay ? " LastVideoDay" : " LastVideoNight" ];
54- }
55- return main .configuration .LastVideo ;
56- }
57- function getLastVideoIndex () {
58- const lastVideo = getLastVideo ();
59- for (let index = 0 ; index < videosConfig .length ; index++ ) {
60- if (videosConfig[index].filename === lastVideo) {
61- return index;
62- }
63- }
64-
65- return 0 ;
66- }
67-
45+ property alias isDay: dayNightCycleController .isDay
6846 property var currentSource: {
6947 const lastVideo = getLastVideo ();
7048 if (resumeLastVideo && lastVideo !== " " ) {
@@ -220,7 +198,7 @@ WallpaperItem {
220198 }
221199
222200 function getVideos () {
223- if (dayNightCycle ) {
201+ if (main . configuration . DayNightCycleEnabled ) {
224202 return Utils .parseCompat (videoUrls).filter (video => {
225203 const isDayCycle = video .dayNightCycleAssignment !== Enum .DayNightCycleAssignment .Night ;
226204 const isNightCycle = video .dayNightCycleAssignment !== Enum .DayNightCycleAssignment .Day ;
@@ -231,6 +209,21 @@ WallpaperItem {
231209
232210 return Utils .parseCompat (videoUrls).filter (video => video .enabled );
233211 }
212+ function getLastVideo () {
213+ if (main .configuration .DayNightCycleEnabled ) {
214+ return main .configuration [main .isDay ? " LastVideoDay" : " LastVideoNight" ];
215+ }
216+ return main .configuration .LastVideo ;
217+ }
218+ function getLastVideoIndex () {
219+ const lastVideo = getLastVideo ();
220+ for (let index = 0 ; index < videosConfig .length ; index++ ) {
221+ if (videosConfig[index].filename === lastVideo) {
222+ return index;
223+ }
224+ }
225+ return 0 ;
226+ }
234227
235228 onPlayingChanged: {
236229 playing && ! isLoading ? main .play () : main .pause ();
@@ -293,42 +286,19 @@ WallpaperItem {
293286 }
294287 }
295288
296- Timer {
297- id: dayNightCycleTimer
298- interval: 1000
299- running: true
300- repeat: true
301- triggeredOnStart: true
302- onTriggered: {
303- const dayNightCycleConfigChanged = dayNightCycle !== main .configuration .DayNightCycle ;
304- if (! dayNightCycleConfigChanged && ! main .configuration .DayNightCycle ) {
305- return ;
306- }
307- dayNightCycle = main .configuration .DayNightCycle ;
308-
309- const hours = new Date ().getHours ();
310- const isDay = hours >= 6 && hours < 19 ;
311-
312- if ((main .isDay != isDay) || dayNightCycleConfigChanged) {
313- main .save ();
314- main .isDay = isDay;
315- videosConfig = getVideos ();
316-
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-
328- setCurrentSource (currentVideoIndex);
329-
330- player .next ();
331- }
289+ DayNightCycleController {
290+ id: dayNightCycleController
291+ enabled: main .configuration .DayNightCycleEnabled
292+ mode: main .configuration .DayNightCycleMode
293+ sunriseTime: main .configuration .DayNightCycleSunriseTime
294+ sunsetTime: main .configuration .DayNightCycleSunsetTime
295+ isLoading: main .isLoading
296+ onBeforeChanged: { main .save (); }
297+ onChanged: {
298+ videosConfig = getVideos ();
299+ currentVideoIndex = resumeLastVideo ? getLastVideoIndex () : 0 ;
300+ setCurrentSource (currentVideoIndex);
301+ player .next ();
332302 }
333303 }
334304
@@ -526,7 +496,6 @@ WallpaperItem {
526496
527497 Component.onCompleted: {
528498 startTimer.start();
529- dayNightCycleTimer.start();
530499 Qt.callLater(() => {
531500 player.currentSource = Qt.binding(() => {
532501 return main.currentSource;
@@ -538,7 +507,7 @@ WallpaperItem {
538507 // Save last video and position to resume from it on next login/lock
539508 main.configuration.LastVideo = main.currentSource.filename;
540509 main.configuration.LastVideoPosition = player.lastVideoPosition;
541- if(dayNightCycle ) {
510+ if (main.configuration.DayNightCycleEnabled ) {
542511 main.configuration[main.isDay ? "LastVideoDay" : "LastVideoNight"] = main.currentSource.filename;
543512 }
544513 main.configuration.writeConfig();
0 commit comments