Merge pull request #603 from silentrald/ui/default-page

[feat] defaultly open to the last version launched on startup
This commit is contained in:
MathieuG-P
2024-12-28 23:22:09 +01:00
committed by GitHub
16 changed files with 110 additions and 18 deletions
+1 -1
View File
@@ -150,7 +150,7 @@
}
},
"available-versions": {
"title": "Wähle eine Version",
"title": "Eine Version herunterladen",
"steam-release": "Versionsseite",
"dropdown": {
"refresh": "Aktualisiere die Versionen",
+1 -1
View File
@@ -150,7 +150,7 @@
}
},
"available-versions": {
"title": "Select a version",
"title": "Download a version",
"steam-release": "Release page",
"dropdown": {
"refresh": "Refresh versions",
+1 -1
View File
@@ -150,7 +150,7 @@
}
},
"available-versions": {
"title": "Selecciona una versión",
"title": "Descargar una versión",
"steam-release": "Anuncio en Steam",
"dropdown": {
"refresh": "Actualizar las versiones",
+1 -1
View File
@@ -150,7 +150,7 @@
}
},
"available-versions": {
"title": "Choisis une version",
"title": "Télécharger une version",
"steam-release": "Notes de version",
"dropdown": {
"refresh": "Actualiser les versions",
+1 -1
View File
@@ -150,7 +150,7 @@
}
},
"available-versions": {
"title": "バージョンを選択",
"title": "バージョンをダウンロード",
"steam-release": "リリースページ",
"dropdown": {
"refresh": "バージョンの更新",
+1 -1
View File
@@ -150,7 +150,7 @@
}
},
"available-versions": {
"title": "Выберите версию",
"title": "Скачать версию",
"steam-release": "Список изменений",
"dropdown": {
"refresh": "Обновить версии",
+1 -1
View File
@@ -150,7 +150,7 @@
}
},
"available-versions": {
"title": "選擇版本",
"title": "下載一個版本",
"steam-release": "發布頁面",
"dropdown": {
"refresh": "刷新版本",
+1 -1
View File
@@ -150,7 +150,7 @@
}
},
"available-versions": {
"title": "选择版本",
"title": "下载一个版本",
"steam-release": "发布页面",
"dropdown": {
"refresh": "刷新版本",
@@ -12,3 +12,7 @@ ipc.on("static-configuration.get", (args, reply) => {
ipc.on("static-configuration.set", (args, reply) => {
reply(from(staticConfig.set(args.key, args.value)));
});
ipc.on("static-configuration.delete", (key, reply) => {
reply(of(staticConfig.delete(key)));
});
@@ -21,6 +21,7 @@ import { OculusLauncherService } from "./oculus-launcher.service";
import { BSVersion } from "shared/bs-version.interface";
import { BsStore } from "../../../shared/models/bs-store.enum";
import { LaunchMod, LaunchMods } from "shared/models/bs-launch/launch-option.interface";
import { StaticConfigurationService } from "../static-configuration.service";
export class BSLauncherService {
private static instance: BSLauncherService;
@@ -32,6 +33,7 @@ export class BSLauncherService {
private readonly remoteVersion: BSVersionLibService;
private readonly steamLauncher: SteamLauncherService;
private readonly oculusLauncher: OculusLauncherService;
private readonly staticConfig: StaticConfigurationService;
public static getInstance(): BSLauncherService {
if (!BSLauncherService.instance) {
@@ -48,6 +50,7 @@ export class BSLauncherService {
this.remoteVersion = BSVersionLibService.getInstance();
this.steamLauncher = SteamLauncherService.getInstance();
this.oculusLauncher = OculusLauncherService.getInstance();
this.staticConfig = StaticConfigurationService.getInstance();
this.bsmProtocolService.on("launch", link => {
log.info("Launch from bsm protocol", link.toString());
@@ -73,6 +76,8 @@ export class BSLauncherService {
return throwError(() => new Error("Unable to get launcher for the provided version"));
}
this.staticConfig.set("last-version-launched", launchOptions.version);
return launcher.launch(launchOptions);
}
@@ -18,6 +18,7 @@ import { Observable, Subject, catchError, finalize, from, map, switchMap, throwE
import { BsStore } from "../../shared/models/bs-store.enum";
import { CustomError } from "../../shared/models/exceptions/custom-error.class";
import crypto from "crypto";
import { StaticConfigurationService } from "./static-configuration.service";
export class BSLocalVersionService {
@@ -32,6 +33,7 @@ export class BSLocalVersionService {
private readonly remoteVersionService: BSVersionLibService;
private readonly configService: ConfigurationService;
private readonly linker: FolderLinkerService;
private readonly staticConfig: StaticConfigurationService;
private readonly _loadedVersions$: Subject<BSVersion[]>;
public static getInstance(): BSLocalVersionService {
@@ -48,6 +50,7 @@ export class BSLocalVersionService {
this.remoteVersionService = BSVersionLibService.getInstance();
this.configService = ConfigurationService.getInstance();
this.linker = FolderLinkerService.getInstance();
this.staticConfig = StaticConfigurationService.getInstance();
this._loadedVersions$ = new Subject<BSVersion[]>();
}
@@ -171,6 +174,24 @@ export class BSLocalVersionService {
this.setCustomVersions([...this.getCustomVersions() ?? [], version]);
}
private updateLastVersionLaunched(version: BSVersion, editedVersion: BSVersion): void {
const lastVersion = this.staticConfig.get("last-version-launched");
if (!lastVersion) {
return;
}
if (
version.BSVersion !== lastVersion.BSVersion
|| version.name !== lastVersion.name
|| version.steam !== lastVersion.steam
|| version.oculus !== lastVersion.oculus
) {
return;
}
this.staticConfig.set("last-version-launched", editedVersion);
}
private getCustomVersions(): BSVersion[]{
return this.configService.get<BSVersion[]>(this.CUSTOM_VERSIONS_KEY) || [];
}
@@ -317,6 +338,7 @@ export class BSLocalVersionService {
if(oldPath === newPath){
this.deleteCustomVersion(version);
this.addCustomVersion(editedVersion);
this.updateLastVersionLaunched(version, editedVersion);
return editedVersion;
}
@@ -327,6 +349,7 @@ export class BSLocalVersionService {
return rename(oldPath, newPath).then(() => {
this.deleteCustomVersion(version);
this.addCustomVersion(editedVersion);
this.updateLastVersionLaunched(version, editedVersion);
return editedVersion;
}).catch((err: Error) => {
log.error("edit version error", err, version, name, color);
@@ -89,6 +89,7 @@ export interface StaticConfigKeyValues {
"disable-hadware-acceleration": boolean;
"use-symlinks": boolean;
"use-system-proxy": boolean;
"last-version-launched": BSVersion;
// Linux Specific static configs
"proton-folder": string;
@@ -1,5 +1,5 @@
import { BSVersion } from "shared/bs-version.interface";
import { BehaviorSubject, Observable, Subscription, lastValueFrom, shareReplay, throwError } from "rxjs";
import { BehaviorSubject, Observable, Subscription, lastValueFrom, map, share, shareReplay, throwError } from "rxjs";
import { IpcService } from "./ipc.service";
import { ModalExitCode, ModalService } from "./modale.service";
import { NotificationService } from "./notification.service";
@@ -19,6 +19,7 @@ export class BSVersionManagerService {
private readonly progressBar: ProgressBarService;
private readonly modals: ModalService;
private askInstalledVersionsObserver$: Observable<BSVersion[]> | null = null;
public readonly installedVersions$: BehaviorSubject<BSVersion[]> = new BehaviorSubject([]);
public readonly availableVersions$: BehaviorSubject<BSVersion[]> = new BehaviorSubject([]);
@@ -28,7 +29,9 @@ export class BSVersionManagerService {
this.notification = NotificationService.getInstance();
this.progressBar = ProgressBarService.getInstance();
this.modals = ModalService.getInstance();
this.askAvailableVersions().then(() => this.askInstalledVersions());
this.askAvailableVersions();
this.askInstalledVersions();
}
public static getInstance() {
@@ -54,15 +57,47 @@ export class BSVersionManagerService {
});
}
public askInstalledVersions(): Promise<BSVersion[]> {
return lastValueFrom(this.ipcService.sendV2("bs-version.installed-versions")).then(res => {
this.setInstalledVersions(res);
return res;
});
public async askInstalledVersions(): Promise<BSVersion[]> {
if (this.askInstalledVersionsObserver$) {
return lastValueFrom(this.askInstalledVersionsObserver$);
}
this.askInstalledVersionsObserver$ = this.ipcService
.sendV2("bs-version.installed-versions")
.pipe(
map(versions => {
let processed = BSVersionManagerService.sortVersions(versions);
processed = BSVersionManagerService.removeDuplicateVersions(processed);
return processed;
}),
share(),
);
return lastValueFrom(this.askInstalledVersionsObserver$)
.then(versions => {
this.setInstalledVersions(versions);
return versions;
})
.finally(() => {
this.askInstalledVersionsObserver$ = null;
});
}
public isVersionInstalled(version: BSVersion): boolean {
return !!this.getInstalledVersions().find(v => v.BSVersion === version.BSVersion && v.steam === version.steam && v.oculus === version.oculus);
public async isVersionInstalled(version: BSVersion): Promise<boolean> {
try {
const versions: BSVersion[] = this.askInstalledVersionsObserver$
? await lastValueFrom(this.askInstalledVersionsObserver$)
: this.getInstalledVersions();
return !!versions.find(v =>
v.BSVersion === version.BSVersion
&& v.name === version.name
&& v.steam === version.steam
&& v.oculus === version.oculus
);
} catch (error) {
return false;
}
}
public async editVersion(version: BSVersion): Promise<BSVersion> {
@@ -27,4 +27,8 @@ export class StaticConfigurationService {
return lastValueFrom(this.ipc.sendV2("static-configuration.set", { key, value }));
}
public delete<K extends StaticConfigKeys>(key: K): Promise<void> {
return lastValueFrom(this.ipc.sendV2("static-configuration.delete", key));
}
}
+20 -1
View File
@@ -23,6 +23,8 @@ import { ConfigurationService } from "renderer/services/configuration.service";
import { OsDiagnosticService } from "renderer/services/os-diagnostic.service";
import { useService } from "renderer/hooks/use-service.hook";
import { SetupService } from "renderer/services/setup.service";
import { StaticConfigurationService } from "renderer/services/static-configuration.service";
import { BSVersionManagerService } from "renderer/services/bs-version-manager.service";
export default function App() {
@@ -34,6 +36,8 @@ export default function App() {
const notification = useService(NotificationService);
const config = useService(ConfigurationService);
const setup = useService(SetupService);
const staticConfig = useService(StaticConfigurationService);
const versionManager = useService(BSVersionManagerService);
const location = useLocation();
const navigate = useNavigate();
@@ -41,10 +45,25 @@ export default function App() {
useEffect(() => {
setup.check()
.then(() => {
navigateToDefaultPage();
checkOneClicks();
})
});
}, []);
const navigateToDefaultPage = async () => {
const version = await staticConfig.get("last-version-launched");
if (!version) {
return;
}
if (!await versionManager.isVersionInstalled(version)) {
await staticConfig.delete("last-version-launched");
return;
}
navigate(`/bs-version/${version.BSVersion}`, { state: version });
};
const checkOneClicks = async () => {
if (config.get("not-remind-oneclick") === true) {
+1
View File
@@ -156,6 +156,7 @@ export interface IpcChannelMapping {
/* ** static-configuration.ipcs ** */
"static-configuration.get": StaticConfigGetIpcRequestResponse<StaticConfigKeys>;
"static-configuration.set": StaticConfigSetIpcRequest<StaticConfigKeys>;
"static-configuration.delete": { request: StaticConfigKeys; response: void };
/* ** linux.ipcs ** */
"linux.verify-proton-folder": { request: void, response: boolean };