-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Preparing for QueuePersister * Adds hook to perform closing tasks * Prepares PlaybackService for saving and restoring of queue * Saving of queue on close works * Restoring works
- Loading branch information
Showing
24 changed files
with
319 additions
and
67 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,11 @@ | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
import {Observable} from "rxjs"; | ||
import {IIndexingMessage} from "../../services/indexing/messages/i-indexing-message"; | ||
import { Observable } from 'rxjs'; | ||
import { IIndexingMessage } from '../../services/indexing/messages/i-indexing-message'; | ||
|
||
export abstract class IpcProxyBase { | ||
public abstract onIndexingWorkerMessage$: Observable<IIndexingMessage>; | ||
public abstract onIndexingWorkerExit$: Observable<void>; | ||
public abstract onApplicationClose$: Observable<void>; | ||
|
||
public abstract sendToMainProcess(channel: string, arg: unknown): void; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export class QueuedTrack { | ||
public constructor(public path: string) {} | ||
|
||
public queuedTrackId: number; | ||
public isPlaying: number; | ||
public progressSeconds: number; | ||
public orderId: number; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { QueuedTrack } from '../entities/queued-track'; | ||
|
||
export abstract class QueuedTrackRepositoryBase { | ||
public abstract getSavedQueuedTracks(): QueuedTrack[] | undefined; | ||
public abstract saveQueuedTracks(tracks: QueuedTrack[]): void; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* eslint-disable @typescript-eslint/no-unsafe-return */ | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
/* eslint-disable @typescript-eslint/no-unsafe-call */ | ||
/* eslint-disable @typescript-eslint/no-unsafe-member-access */ | ||
/* eslint-disable @typescript-eslint/no-unsafe-assignment */ | ||
import { Injectable } from '@angular/core'; | ||
import { QueuedTrackRepositoryBase } from './queued-track-repository.base'; | ||
import { DatabaseFactory } from '../database-factory'; | ||
import { QueuedTrack } from '../entities/queued-track'; | ||
|
||
@Injectable() | ||
export class QueuedTrackRepository implements QueuedTrackRepositoryBase { | ||
public constructor(private databaseFactory: DatabaseFactory) {} | ||
|
||
public getSavedQueuedTracks(): QueuedTrack[] | undefined { | ||
const database: any = this.databaseFactory.create(); | ||
|
||
const statement = database.prepare( | ||
`SELECT QueuedTrackID as queuedTrackId, | ||
Path as path, | ||
IsPlaying as isPlaying, | ||
ProgressSeconds as progressSeconds, | ||
OrderID as orderId | ||
FROM QueuedTrack | ||
ORDER BY QueuedTrackID;`, | ||
); | ||
|
||
const queuedTracks: QueuedTrack[] | undefined = statement.all(); | ||
|
||
return queuedTracks; | ||
} | ||
|
||
public saveQueuedTracks(tracks: QueuedTrack[]): void { | ||
const database: any = this.databaseFactory.create(); | ||
|
||
database.exec('BEGIN TRANSACTION;'); | ||
|
||
// First, clear old queued tracks. | ||
database.exec('DELETE FROM QueuedTrack;'); | ||
|
||
// Then, insert new queued tracks. | ||
for (const track of tracks) { | ||
const statement = database.prepare( | ||
'INSERT INTO QueuedTrack (Path, SafePath, IsPlaying, ProgressSeconds, OrderID) VALUES (?, ?, ?, ?, ?);', | ||
); | ||
statement.run(track.path, track.path.toLowerCase(), track.isPlaying, track.progressSeconds, track.orderId); | ||
} | ||
|
||
database.exec('COMMIT;'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { IpcProxyBase } from '../../common/io/ipc-proxy.base'; | ||
import { Injectable } from '@angular/core'; | ||
import { PlaybackServiceBase } from '../playback/playback.service.base'; | ||
|
||
@Injectable({ providedIn: 'root' }) | ||
export class LifetimeService { | ||
public constructor( | ||
private playbackService: PlaybackServiceBase, | ||
private ipcProxy: IpcProxyBase, | ||
) {} | ||
|
||
public initialize(): void { | ||
this.ipcProxy.onApplicationClose$.subscribe(() => { | ||
this.performClosingTasks(); | ||
}); | ||
} | ||
|
||
private performClosingTasks(): void { | ||
this.playbackService.saveQueue(); | ||
|
||
this.ipcProxy.sendToMainProcess('closing-tasks-performed', undefined); | ||
} | ||
} |
Oops, something went wrong.