diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 535b58c99..247662d0d 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -1,4 +1,4 @@ -import { Component, NgZone } from '@angular/core'; +import { Component } from '@angular/core'; import { MatDialog } from '@angular/material/dialog'; import { MatSnackBar } from '@angular/material/snack-bar'; import { Router } from '@angular/router'; @@ -37,7 +37,7 @@ import { SearchResultsComponent } from './xtream-tauri/search-results/search-res @Component({ selector: 'app-root', templateUrl: './app.component.html', - standalone: false + standalone: false, }) export class AppComponent { /** Visibility flag of the "what is new" modal dialog */ @@ -68,7 +68,6 @@ export class AppComponent { private dataService: DataService, private dialog: MatDialog, private epgService: EpgService, - private ngZone: NgZone, private playlistService: PlaylistsService, private router: Router, private store: Store, @@ -166,7 +165,7 @@ export class AppComponent { } async triggerAutoUpdateMechanism() { - if (this.dataService.isElectron) { + if (isTauri()) { const playlistForAutoUpdate = await firstValueFrom( this.playlistService.getPlaylistsForAutoUpdate() ); @@ -183,19 +182,13 @@ export class AppComponent { */ setRendererListeners(): void { this.commandsList.forEach((command) => { - if (this.dataService.isElectron) { - this.dataService.listenOn(command.id, () => - this.ngZone.run((data) => command.callback(data)) - ); - } else { - const cb = (response) => { - if (response.data.type === command.id) { - command.callback(response.data); - } - }; - this.dataService.listenOn(command.id, cb); - this.listeners.push(cb); - } + const cb = (response) => { + if (response.data.type === command.id) { + command.callback(response.data); + } + }; + this.dataService.listenOn(command.id, cb); + this.listeners.push(cb); }); } diff --git a/src/app/home/recent-playlists/recent-playlists.component.ts b/src/app/home/recent-playlists/recent-playlists.component.ts index 2ff797b8e..ac8cb000a 100644 --- a/src/app/home/recent-playlists/recent-playlists.component.ts +++ b/src/app/home/recent-playlists/recent-playlists.component.ts @@ -134,10 +134,12 @@ export class RecentPlaylistsComponent implements OnDestroy { }, { id: AUTO_UPDATE_PLAYLISTS_RESPONSE, - execute: (playlists: Playlist[]) => { + execute: (response: { + payload: { message: string; playlists: Playlist[] }; + }) => { this.store.dispatch( PlaylistActions.updateManyPlaylists({ - playlists, + playlists: response.payload.playlists, }) ); }, diff --git a/src/app/services/tauri.service.ts b/src/app/services/tauri.service.ts index 2586d2e5d..452424a15 100644 --- a/src/app/services/tauri.service.ts +++ b/src/app/services/tauri.service.ts @@ -5,6 +5,8 @@ import { readTextFile } from '@tauri-apps/plugin-fs'; import { fetch } from '@tauri-apps/plugin-http'; import { parse } from 'iptv-playlist-parser'; import { + AUTO_UPDATE_PLAYLISTS, + AUTO_UPDATE_PLAYLISTS_RESPONSE, EPG_GET_PROGRAM_DONE, ERROR, PLAYLIST_PARSE_BY_URL, @@ -108,6 +110,30 @@ export class TauriService extends DataService { type: EPG_GET_PROGRAM_DONE, payload, }); + } else if (type === AUTO_UPDATE_PLAYLISTS) { + const playlists = []; + const data = payload as Playlist[]; + + for await (const item of data) { + if (item.filePath) { + const playlist = await readTextFile(item.filePath); + const parsedPlaylist = parse(playlist); + const playlistObject = createPlaylistObject( + item.title, + parsedPlaylist, + item.filePath, + 'FILE' + ); + playlists.push({ ...playlistObject, _id: item._id }); + } + } + window.postMessage({ + type: AUTO_UPDATE_PLAYLISTS_RESPONSE, + payload: { + message: 'Success! The playlists were successfully updated', + playlists, + }, + }); } else { console.log('Unknown type', type); }