diff --git a/app/main.ts b/app/main.ts index 8bb6f35..9305108 100644 --- a/app/main.ts +++ b/app/main.ts @@ -201,7 +201,6 @@ function isConnectedToWiFi(): Promise { // Check if the output indicates a connected status if (stdout) { const components: string[] = stdout.split("\n"); - console.log(components); components.forEach((component: string) => { if (component.includes('wifi') && !component.includes('--')) { diff --git a/src/app/core/services/daemon/daemon-data.service.ts b/src/app/core/services/daemon/daemon-data.service.ts index 3fe29c2..e6dbde6 100644 --- a/src/app/core/services/daemon/daemon-data.service.ts +++ b/src/app/core/services/daemon/daemon-data.service.ts @@ -250,6 +250,8 @@ export class DaemonDataService { throw new Error("Loop already started"); } this._firstRefresh = true; + this.syncDisabledByPeriodPolicy = false; + this.syncDisabledByWifiPolicy = false; this.refresh().then(() => { this.refreshInterval = setInterval(() => { @@ -327,6 +329,40 @@ export class DaemonDataService { } + public syncDisabledByWifiPolicy: boolean = false; + public syncDisabledByPeriodPolicy: boolean = false; + + private isInTimeRange(fromHours: string, toHours: string): boolean { + const now = new Date(); + + // Estraiamo l'ora e i minuti dalla stringa in formato hh:mm + const [fromHour, fromMinute] = fromHours.split(":").map(Number); + const [toHour, toMinute] = toHours.split(":").map(Number); + + // Otteniamo l'ora corrente in ore e minuti + const currentHour = now.getHours(); + const currentMinute = now.getMinutes(); + + // Creiamo oggetti Date per le ore 'from', 'to', e l'ora attuale + const currentTime = new Date(); + currentTime.setHours(currentHour, currentMinute, 0, 0); + + const fromTime = new Date(); + fromTime.setHours(fromHour, fromMinute, 0, 0); + + const toTime = new Date(); + toTime.setHours(toHour, toMinute, 0, 0); + + // Gestione del caso in cui la fascia oraria attraversi la mezzanotte + if (fromTime > toTime) { + // Se l'ora attuale è dopo 'fromTime' o prima di 'toTime' + return currentTime >= fromTime || currentTime <= toTime; + } else { + // Caso normale: la fascia oraria è nello stesso giorno + return currentTime >= fromTime && currentTime <= toTime; + } + } + private async refresh(): Promise { if (this.refreshing || this.tooEarlyForRefresh) { return; @@ -351,6 +387,7 @@ export class DaemonDataService { if (wifiConnected) { console.log("Disabling sync ..."); await this.daemonService.disableSync(); + this.syncDisabledByWifiPolicy = true; } } else if (!settings.noSync && syncAlreadyDisabled && !settings.syncOnWifi) { @@ -360,8 +397,23 @@ export class DaemonDataService { console.log("Enabling sync ..."); await this.daemonService.enableSync(); + this.syncDisabledByWifiPolicy = false; } + else { + this.syncDisabledByWifiPolicy = true; + } + } + else { + this.syncDisabledByWifiPolicy = false; + } + if (!syncAlreadyDisabled && !this.syncDisabledByPeriodPolicy && settings.syncPeriodEnabled && !this.isInTimeRange(settings.syncPeriodFrom, settings.syncPeriodTo)) { + await this.daemonService.disableSync(); + this.syncDisabledByPeriodPolicy = true; + } + else if (syncAlreadyDisabled && this.syncDisabledByPeriodPolicy && settings.syncPeriodEnabled && this.isInTimeRange(settings.syncPeriodFrom, settings.syncPeriodTo)) { + await this.daemonService.enableSync(); + this.syncDisabledByPeriodPolicy = false; } this.syncStart.emit({ first: this._firstRefresh }); diff --git a/src/app/pages/detail/detail.component.html b/src/app/pages/detail/detail.component.html index a416a27..c2f0eac 100644 --- a/src/app/pages/detail/detail.component.html +++ b/src/app/pages/detail/detail.component.html @@ -12,6 +12,19 @@ + + +
diff --git a/src/app/pages/detail/detail.component.ts b/src/app/pages/detail/detail.component.ts index d25aaec..b64a7c5 100644 --- a/src/app/pages/detail/detail.component.ts +++ b/src/app/pages/detail/detail.component.ts @@ -28,6 +28,21 @@ export class DetailComponent implements AfterViewInit, OnDestroy { public readonly navbarLinks: NavbarLink[]; + public get syncDisabledByWifiPolicy(): boolean { + return this.daemonData.syncDisabledByWifiPolicy; + } + + public get syncDisabledByPeriodPolicy(): boolean { + return this.daemonData.syncDisabledByPeriodPolicy; + } + + public get syncDisabledFrom(): string { + return this.daemonService.settings.syncPeriodFrom; + } + + public get syncDisabledTo(): string { + return this.daemonService.settings.syncPeriodTo; + } //#region Sync Info private get height(): number { diff --git a/src/app/shared/components/navbar/navbar.component.html b/src/app/shared/components/navbar/navbar.component.html index a68b304..2c2d6d6 100644 --- a/src/app/shared/components/navbar/navbar.component.html +++ b/src/app/shared/components/navbar/navbar.component.html @@ -24,7 +24,7 @@