fix: fix playlist update mechanism and improve response handling in Tauri service

This commit is contained in:
4gray committed 2025-03-10 22:04:41 +01:00
1 parent bfe061d8b7
commit 119a7b156b
3 files changed
+40 -19

No files matched your search

+10 -17
View File
@@ -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);
});
}
@@ -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,
})
);
},
+26
View File
@@ -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);
}