mirror of
https://github.com/Zagrios/bs-manager.git
synced 2026-07-03 14:08:25 +02:00
[feature-107] Implement playlists linking + remove possibility to play a playlist for now + some refacto
This commit is contained in:
@@ -13,7 +13,7 @@ import { ConfigurationService } from "./configuration.service";
|
||||
import { ArchiveProgress } from "shared/models/archive.interface";
|
||||
import { map, last, catchError } from "rxjs/operators";
|
||||
import { ProgressionInterface } from "shared/models/progress-bar";
|
||||
import { FolderLinkState, VersionFolderLinkerService, VersionLinkerActionType } from "./version-folder-linker.service";
|
||||
import { FolderLinkState, VersionFolderLinkerService } from "./version-folder-linker.service";
|
||||
|
||||
export class MapsManagerService {
|
||||
private static instance: MapsManagerService;
|
||||
@@ -64,7 +64,6 @@ export class MapsManagerService {
|
||||
|
||||
return this.linker.linkVersionFolder({
|
||||
version,
|
||||
type: VersionLinkerActionType.Link,
|
||||
relativeFolder: MapsManagerService.RELATIVE_MAPS_FOLDER,
|
||||
options: { keepContents: !!modalRes.data },
|
||||
});
|
||||
@@ -79,7 +78,6 @@ export class MapsManagerService {
|
||||
|
||||
return this.linker.unlinkVersionFolder({
|
||||
version,
|
||||
type: VersionLinkerActionType.Unlink,
|
||||
relativeFolder: MapsManagerService.RELATIVE_MAPS_FOLDER,
|
||||
options: { keepContents: !!modalRes.data },
|
||||
});
|
||||
|
||||
@@ -4,6 +4,10 @@ import { Observable, lastValueFrom } from "rxjs";
|
||||
import { FolderLinkState, VersionFolderLinkerService } from "./version-folder-linker.service";
|
||||
import { Progression } from "main/helpers/fs.helpers";
|
||||
import { LocalBPList } from "shared/models/playlists/local-playlist.models";
|
||||
import { ModalExitCode, ModalService } from "./modale.service";
|
||||
import { LinkMapsModal } from "renderer/components/modal/modal-types/link-maps-modal.component";
|
||||
import { UnlinkPlaylistModal } from "renderer/components/modal/modal-types/unlink-playlist-modal.component";
|
||||
import { LinkPlaylistModal } from "renderer/components/modal/modal-types/link-playlist-modal.component";
|
||||
|
||||
export class PlaylistsManagerService {
|
||||
private static instance: PlaylistsManagerService;
|
||||
@@ -19,16 +23,46 @@ export class PlaylistsManagerService {
|
||||
|
||||
private readonly ipc: IpcService;
|
||||
private readonly linker: VersionFolderLinkerService;
|
||||
private readonly modal: ModalService;
|
||||
|
||||
private constructor() {
|
||||
this.ipc = IpcService.getInstance();
|
||||
this.linker = VersionFolderLinkerService.getInstance();
|
||||
this.modal = ModalService.getInstance();
|
||||
}
|
||||
|
||||
public getVersionPlaylists(version: BSVersion): Observable<Progression<LocalBPList[]>> {
|
||||
return this.ipc.sendV2("get-version-playlists", { args: version });
|
||||
}
|
||||
|
||||
public async linkVersion(version: BSVersion): Promise<boolean> {
|
||||
const modalRes = await this.modal.openModal(LinkPlaylistModal);
|
||||
|
||||
if (modalRes.exitCode !== ModalExitCode.COMPLETED) {
|
||||
return Promise.resolve(false);
|
||||
}
|
||||
|
||||
return this.linker.linkVersionFolder({
|
||||
version,
|
||||
relativeFolder: PlaylistsManagerService.RELATIVE_PLAYLISTS_FOLDER,
|
||||
options: { keepContents: !!modalRes.data },
|
||||
});
|
||||
}
|
||||
|
||||
public async unlinkVersion(version: BSVersion): Promise<boolean> {
|
||||
const modalRes = await this.modal.openModal(UnlinkPlaylistModal);
|
||||
|
||||
if (modalRes.exitCode !== ModalExitCode.COMPLETED) {
|
||||
return Promise.resolve(false);
|
||||
}
|
||||
|
||||
return this.linker.unlinkVersionFolder({
|
||||
version,
|
||||
relativeFolder: PlaylistsManagerService.RELATIVE_PLAYLISTS_FOLDER,
|
||||
options: { keepContents: !!modalRes.data },
|
||||
});
|
||||
}
|
||||
|
||||
public isDeepLinksEnabled(): Promise<boolean> {
|
||||
return lastValueFrom(this.ipc.sendV2<boolean>("is-playlists-deep-links-enabled"));
|
||||
}
|
||||
|
||||
@@ -82,7 +82,7 @@ export class VersionFolderLinkerService {
|
||||
this.onVersionFolderLinked(callBack);
|
||||
});
|
||||
|
||||
this._queue$.next([...this._queue$.value, action]);
|
||||
this._queue$.next([...this._queue$.value, {...action, type: VersionLinkerActionType.Link}]);
|
||||
|
||||
return promise;
|
||||
}
|
||||
@@ -100,7 +100,7 @@ export class VersionFolderLinkerService {
|
||||
this.onVersionFolderUnlinked(callBack);
|
||||
});
|
||||
|
||||
this._queue$.next([...this._queue$.value, action]);
|
||||
this._queue$.next([...this._queue$.value, {...action, type: VersionLinkerActionType.Unlink}]);
|
||||
|
||||
return promise;
|
||||
}
|
||||
@@ -136,7 +136,7 @@ export class VersionFolderLinkerService {
|
||||
if(currentAction && equal(currentAction.version, version) && currentAction.relativeFolder === relativeFolder) {
|
||||
return of(FolderLinkState.Processing)
|
||||
}
|
||||
|
||||
|
||||
if(queue.some(action => equal(action.version, version) && action.relativeFolder === relativeFolder)) {
|
||||
return of(FolderLinkState.Pending);
|
||||
}
|
||||
@@ -146,7 +146,7 @@ export class VersionFolderLinkerService {
|
||||
);
|
||||
}),
|
||||
distinctUntilChanged(),
|
||||
shareReplay(1)
|
||||
shareReplay(1)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -179,14 +179,8 @@ export interface VersionLinkerAction {
|
||||
options?: LinkOptions;
|
||||
}
|
||||
|
||||
export interface VersionLinkFolderAction extends VersionLinkerAction {
|
||||
type: VersionLinkerActionType.Link;
|
||||
}
|
||||
|
||||
export interface VersionUnlinkFolderAction extends VersionLinkerAction {
|
||||
type: VersionLinkerActionType.Unlink;
|
||||
options?: UnlinkOptions;
|
||||
}
|
||||
export type VersionLinkFolderAction = Omit<VersionLinkerAction, "type">;
|
||||
export type VersionUnlinkFolderAction = Omit<VersionLinkerAction, "type">;
|
||||
|
||||
export type VersionLinkerActionListener = (action: VersionLinkerAction, linked: boolean) => void;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user