mirror of
https://github.com/Zagrios/bs-manager.git
synced 2026-07-03 14:08:25 +02:00
[feature] disable hardware acceleration and use symlinks work, just still need to translate
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
import path from "path";
|
||||
import { ensureDirSync, existsSync, readFile, writeFile } from "fs-extra";
|
||||
import { BehaviorSubject, Observable, catchError, filter, lastValueFrom, of, take, timeout } from "rxjs";
|
||||
import { ConfigurationService } from "../../configuration.service";
|
||||
import { RequestService } from "../../request.service";
|
||||
import { tryit } from "shared/helpers/error.helpers";
|
||||
import { CACHE_PATH, HTTP_STATUS_CODES } from "main/constants";
|
||||
@@ -12,6 +11,7 @@ import { SongDetails } from "shared/models/maps/song-details-cache/song-details-
|
||||
import { inflate } from "pako";
|
||||
import { RawSongDetailsCache } from "shared/models/maps/song-details-cache/raw-song-details-cache.model";
|
||||
import { RawSongDetailsDeserializer } from "shared/models/maps/song-details-cache/raw-song-details-deserializer.class";
|
||||
import { StaticConfigurationService } from "main/services/static-configuration.service";
|
||||
|
||||
export class SongDetailsCacheService {
|
||||
|
||||
@@ -32,7 +32,7 @@ export class SongDetailsCacheService {
|
||||
private readonly PROTO_CACHE_PATH = path.join(CACHE_PATH, "song-details-cache");
|
||||
private readonly etagKey = "song-details-cache-etag";
|
||||
|
||||
private readonly config: ConfigurationService;
|
||||
private readonly staticConfig: StaticConfigurationService;
|
||||
private readonly request: RequestService;
|
||||
private readonly utils: UtilsService;
|
||||
|
||||
@@ -41,7 +41,7 @@ export class SongDetailsCacheService {
|
||||
private readonly _loaded$ = new BehaviorSubject<boolean>(null);
|
||||
|
||||
private constructor(){
|
||||
this.config = ConfigurationService.getInstance();
|
||||
this.staticConfig = StaticConfigurationService.getInstance();
|
||||
this.request = RequestService.getInstance();
|
||||
this.utils = UtilsService.getInstance();
|
||||
this.loadCache()
|
||||
@@ -49,10 +49,10 @@ export class SongDetailsCacheService {
|
||||
|
||||
private async loadCache(): Promise<void> {
|
||||
const protoCacheExists = existsSync(this.PROTO_CACHE_PATH);
|
||||
const etag = protoCacheExists ? this.config.get<string>(this.etagKey) : null;
|
||||
const etag = protoCacheExists ? this.staticConfig.get(this.etagKey) : null;
|
||||
|
||||
await this.downloadCacheFile(etag).then(etag => {
|
||||
this.config.set(this.etagKey, etag);
|
||||
this.staticConfig.set(this.etagKey, etag);
|
||||
log.info("SongDetailsCache downloaded");
|
||||
this.songDetailsIdIndex = this.createIdIndex(this.songDetailsCache);
|
||||
log.info("SongDetailsIdIndex created");
|
||||
|
||||
@@ -6,6 +6,7 @@ import path from "path";
|
||||
import { copy, readlink } from "fs-extra";
|
||||
import { lastValueFrom } from "rxjs";
|
||||
import { noop } from "shared/helpers/function.helpers";
|
||||
import { StaticConfigurationService } from "./static-configuration.service";
|
||||
|
||||
export class FolderLinkerService {
|
||||
private static instance: FolderLinkerService;
|
||||
@@ -18,9 +19,20 @@ export class FolderLinkerService {
|
||||
}
|
||||
|
||||
private readonly installLocationService = InstallationLocationService.getInstance();
|
||||
private readonly staticConfig: StaticConfigurationService;
|
||||
|
||||
private linkingType: "junction" | "symlink" = "junction";
|
||||
|
||||
private constructor() {
|
||||
this.installLocationService = InstallationLocationService.getInstance();
|
||||
this.staticConfig = StaticConfigurationService.getInstance();
|
||||
|
||||
this.linkingType = this.staticConfig.get("use-symlinks") === true ? "symlink" : "junction";
|
||||
|
||||
this.staticConfig.$watch("use-symlinks").subscribe(({ newValue: useSymlink }) => {
|
||||
this.linkingType = useSymlink === true ? "symlink" : "junction";
|
||||
log.info(`Linking type set to ${this.linkingType}`);
|
||||
});
|
||||
}
|
||||
|
||||
private async sharedFolder(): Promise<string> {
|
||||
@@ -51,6 +63,10 @@ export class FolderLinkerService {
|
||||
});
|
||||
}
|
||||
|
||||
private getLinkingType(): "junction" | undefined {
|
||||
return this.linkingType === "junction" ? "junction" : undefined;
|
||||
}
|
||||
|
||||
public async linkFolder(folderPath: string, options?: LinkOptions): Promise<void> {
|
||||
const sharedPath = await this.getSharedFolder(folderPath, options?.intermediateFolder);
|
||||
|
||||
@@ -62,7 +78,9 @@ export class FolderLinkerService {
|
||||
return;
|
||||
}
|
||||
await unlinkPath(folderPath);
|
||||
return symlink(sharedPath, folderPath, "junction");
|
||||
|
||||
log.info(`Linking ${folderPath} to ${sharedPath}; type: ${this.linkingType}`);
|
||||
return symlink(sharedPath, folderPath, this.getLinkingType());
|
||||
}
|
||||
|
||||
await ensureFolderExist(sharedPath);
|
||||
@@ -79,7 +97,8 @@ export class FolderLinkerService {
|
||||
|
||||
await deleteFolder(folderPath);
|
||||
|
||||
return symlink(sharedPath, folderPath, "junction");
|
||||
log.info(`Linking ${folderPath} to ${sharedPath}; type: ${this.linkingType}`);
|
||||
return symlink(sharedPath, folderPath, this.getLinkingType());
|
||||
}
|
||||
|
||||
public async unlinkFolder(folderPath: string, options?: UnlinkOptions): Promise<void> {
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import path from "path";
|
||||
import { app } from "electron";
|
||||
import ElectronStore from "electron-store";
|
||||
import { copyDirectoryWithJunctions, deleteFolder, ensureFolderExist } from "../helpers/fs.helpers";
|
||||
import { tryit } from "../../shared/helpers/error.helpers";
|
||||
import { pathExistsSync } from "fs-extra";
|
||||
import { StaticConfigurationService } from "./static-configuration.service";
|
||||
|
||||
export class InstallationLocationService {
|
||||
private static instance: InstallationLocationService;
|
||||
@@ -23,15 +23,15 @@ export class InstallationLocationService {
|
||||
|
||||
private readonly STORE_INSTALLATION_PATH_KEY = "installation-folder";
|
||||
|
||||
private readonly installPathConfig: ElectronStore;
|
||||
private readonly staticConfig: StaticConfigurationService;
|
||||
private readonly updateListeners: Set<Listener> = new Set();
|
||||
|
||||
private _installationDirectory: string;
|
||||
|
||||
private constructor() {
|
||||
this.installPathConfig = new ElectronStore({ watch: true });
|
||||
this.staticConfig = StaticConfigurationService.getInstance();
|
||||
|
||||
this.installPathConfig.onDidChange(this.STORE_INSTALLATION_PATH_KEY, () => {
|
||||
this.staticConfig.$watch(this.STORE_INSTALLATION_PATH_KEY).subscribe(() => {
|
||||
this.triggerListeners();
|
||||
});
|
||||
}
|
||||
@@ -48,7 +48,7 @@ export class InstallationLocationService {
|
||||
await copyDirectoryWithJunctions(oldDir, path.join(newDir, this.INSTALLATION_FOLDER), { overwrite: true });
|
||||
|
||||
this._installationDirectory = newDir;
|
||||
this.installPathConfig.set(this.STORE_INSTALLATION_PATH_KEY, newDir);
|
||||
this.staticConfig.set(this.STORE_INSTALLATION_PATH_KEY, newDir);
|
||||
|
||||
deleteFolder(oldDir);
|
||||
|
||||
@@ -66,8 +66,8 @@ export class InstallationLocationService {
|
||||
return this._installationDirectory;
|
||||
}
|
||||
|
||||
if(this.installPathConfig.has(this.STORE_INSTALLATION_PATH_KEY)) {
|
||||
return this.installPathConfig.get(this.STORE_INSTALLATION_PATH_KEY) as string;
|
||||
if(this.staticConfig.has(this.STORE_INSTALLATION_PATH_KEY)) {
|
||||
return this.staticConfig.get(this.STORE_INSTALLATION_PATH_KEY) as string;
|
||||
}
|
||||
|
||||
const { result: oldPath } = tryit(() => path.join(app.getPath("documents"), this.INSTALLATION_FOLDER));
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
import ElectronStore from "electron-store";
|
||||
import { Observable } from "rxjs";
|
||||
|
||||
export class StaticConfigurationService {
|
||||
private static instance: StaticConfigurationService;
|
||||
|
||||
public static getInstance(): StaticConfigurationService {
|
||||
if (!StaticConfigurationService.instance) {
|
||||
StaticConfigurationService.instance = new StaticConfigurationService();
|
||||
}
|
||||
return StaticConfigurationService.instance;
|
||||
}
|
||||
|
||||
private readonly store: ElectronStore;
|
||||
|
||||
private constructor() {
|
||||
this.store = new ElectronStore({ watch: true });
|
||||
}
|
||||
|
||||
public has<K extends StaticConfigKeys>(key: K): boolean {
|
||||
return this.store.has(key);
|
||||
}
|
||||
|
||||
public get<K extends StaticConfigKeys>(key: K): StaticConfigKeyValues[K] {
|
||||
return this.store.get<K>(key) as StaticConfigKeyValues[K];
|
||||
}
|
||||
|
||||
public take<K extends StaticConfigKeys>(key: K, cb: (val: StaticConfigKeyValues[K]) => void): void {
|
||||
cb(this.get(key));
|
||||
}
|
||||
|
||||
public set<K extends StaticConfigKeys>(key: K, value: StaticConfigKeyValues[K]): void {
|
||||
this.store.set(key, value);
|
||||
}
|
||||
|
||||
public delete<K extends StaticConfigKeys>(key: K): void {
|
||||
this.store.delete(key);
|
||||
}
|
||||
|
||||
public getStore(): ElectronStore {
|
||||
return this.store;
|
||||
}
|
||||
|
||||
public $watch<K extends StaticConfigKeys>(key: K): Observable<{ newValue: StaticConfigKeyValues[K], oldValue: StaticConfigKeyValues[K] }> {
|
||||
return new Observable(obs => {
|
||||
const unsub = this.store.onDidChange(key, (newValue, oldValue) => {
|
||||
obs.next({ newValue, oldValue } as { newValue: StaticConfigKeyValues[K], oldValue: StaticConfigKeyValues[K] });
|
||||
});
|
||||
|
||||
return () => unsub();
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
export interface StaticConfigKeyValues {
|
||||
"installation-folder": string;
|
||||
"song-details-cache-etag": string;
|
||||
"disable-hadware-acceleration": boolean;
|
||||
"use-symlinks": boolean;
|
||||
}
|
||||
|
||||
export type StaticConfigKeys = keyof StaticConfigKeyValues;
|
||||
|
||||
export type StaticConfigGetIpcRequestResponse<K extends StaticConfigKeys> = {
|
||||
request: K;
|
||||
response: StaticConfigKeyValues[K];
|
||||
};
|
||||
|
||||
export type StaticConfigSetIpcRequest<K extends StaticConfigKeys> = {
|
||||
request: { key: K, value: StaticConfigKeyValues[K] };
|
||||
response: void;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user