diff --git a/src/main/main.ts b/src/main/main.ts index 0a77a075..02dcf132 100644 --- a/src/main/main.ts +++ b/src/main/main.ts @@ -109,6 +109,25 @@ if (!gotTheLock) { ipcMain.on("log-error", (event, args: IpcRequest) => { log.error(args?.args); }); + + // TODO : remove this + BSLauncherService.getInstance().createLaunchShortcut({ + debug: false, + oculus: true, + desktop: true, + version: { + BSVersion: '1.29.1', + BSManifest: '886973241045584398', + ReleaseURL: 'https://steamcommunity.com/games/620980/announcements/detail/6169409105101272202', + ReleaseImg: 'https://cdn.akamai.steamstatic.com/steamcommunity/public/images/clans/32055887/c328e407367e9914abaf92f609501877ee5abb63.png', + ReleaseDate: '1680623885', + year: '2023', + name: 'Hi Twitter', + ino: 2533274792493431, + color: '#6545ff af' + }, + additionalArgs: [ '--nowait', '-omgargs' ] + }); }).catch(log.error); } diff --git a/src/main/services/bs-launcher.service.ts b/src/main/services/bs-launcher.service.ts index 04593b84..71c6d246 100644 --- a/src/main/services/bs-launcher.service.ts +++ b/src/main/services/bs-launcher.service.ts @@ -11,6 +11,8 @@ import { rename } from "fs/promises"; import log from "electron-log"; import { Observable, lastValueFrom, timer } from "rxjs"; import { BsmProtocolService } from "./bsm-protocol.service"; +import { app, shell } from "electron"; +import { objectFromEntries } from "../../shared/helpers/object.helpers"; export class BSLauncherService { private static instance: BSLauncherService; @@ -124,6 +126,8 @@ export class BSLauncherService { // t.searchParams.set("launchOptions", JSON.stringify(launchOptions)); // console.log(t.toString()); + console.log(launchOptions); + return new Observable(obs => {(async () => { if(await this.isBsRunning()){ @@ -174,5 +178,48 @@ export class BSLauncherService { obs.error({type: BSLaunchErrorType.UNKNOWN_ERROR, data: err} as BSLaunchErrorEvent); })}); } + + private launchOptionToShortcutParams(launchOptions: LaunchOption): ShortcutParams{ + const res: ShortcutParams = { version: launchOptions.version.BSVersion }; + + if(launchOptions.version.name){ res.versionName = launchOptions.version.name; } + if(launchOptions.version.steam){ res.versionSteam = `${launchOptions.version.steam}`; } + if(launchOptions.version.oculus){ res.versionOculus = `${launchOptions.version.oculus}`; } + if(launchOptions.version.ino){ res.versionIno = `${launchOptions.version.ino}`; } + + if(launchOptions.oculus){ res.oculusMode = "true"; } + if(launchOptions.desktop){ res.desktopMode = "true"; } + if(launchOptions.debug){ res.debug = "true"; } + if(launchOptions.additionalArgs){ res.additionalArgs = launchOptions.additionalArgs; } + + return res; + } + + public async createLaunchShortcut(launchOptions: LaunchOption): Promise{ + const shortcutParams = this.launchOptionToShortcutParams(launchOptions); + const shortcutUrl = this.bsmProtocolService.buildLink("launch", shortcutParams); + + console.log(objectFromEntries(shortcutUrl.searchParams.entries())); + + // shell.writeShortcutLink(path.join(app.getPath("desktop"), "test.lnk"), "create", { + // target: shortcutUrl.toString(), + // description: "test allo allo", + + // }); + + + } } + +type ShortcutParams = { + oculusMode?: string; + desktopMode?: string; + debug?: string; + additionalArgs?: string[]; + version: string; + versionName?: string; + versionIno?: string; + versionSteam?: string; + versionOculus?: string; +} diff --git a/src/main/services/bs-local-version.service.ts b/src/main/services/bs-local-version.service.ts index 73c687c4..a33b421a 100644 --- a/src/main/services/bs-local-version.service.ts +++ b/src/main/services/bs-local-version.service.ts @@ -221,11 +221,11 @@ export class BSLocalVersionService { if(!rawVersion){ continue; } - const bsVersion = {...await this.remoteVersionService.getVersionDetails(rawVersion.BSVersion)}; + const vertionDetails = await this.remoteVersionService.getVersionDetails(rawVersion.BSVersion); - if(!bsVersion){ continue; } + if(!vertionDetails){ continue; } - bsVersion.name = path.basename(f) !== bsVersion.BSVersion ? path.basename(f) : undefined; + const bsVersion: BSVersion = {...vertionDetails, ...rawVersion}; const customVersion = this.getCustomVersions().find(custom => custom.BSVersion === bsVersion.BSVersion && custom.name === bsVersion.name); diff --git a/src/main/services/bsm-protocol.service.ts b/src/main/services/bsm-protocol.service.ts index ec68f57e..4e2d1c67 100644 --- a/src/main/services/bsm-protocol.service.ts +++ b/src/main/services/bsm-protocol.service.ts @@ -1,7 +1,7 @@ import { Subject, Subscription, filter } from "rxjs"; import { DeepLinkService } from "./deep-link.service"; import { URL } from "url"; -import { isValidUrl } from "../../shared/helpers/url.helpers"; +import { buildUrl, isValidUrl } from "../../shared/helpers/url.helpers"; export class BsmProtocolService { @@ -38,4 +38,12 @@ export class BsmProtocolService { return this.linkeReceived$.pipe(filter(link => link.host === host)).subscribe(listener); } + public buildLink(host: string, params?: Record): URL { + return buildUrl({ + protocol: this.BSM_PROTOCOL, + host, + search: params + }); + } + } \ No newline at end of file diff --git a/src/shared/helpers/object.helpers.ts b/src/shared/helpers/object.helpers.ts new file mode 100644 index 00000000..5b7f272f --- /dev/null +++ b/src/shared/helpers/object.helpers.ts @@ -0,0 +1,13 @@ +export function objectFromEntries(entries: Iterable): Record { + const temp: Record = {}; + + for (const [key, value] of entries) { + if (temp[key]) { + temp[key] = Array.isArray(temp[key]) ? [...(temp[key] as T[]), value] : [(temp[key] as T), value]; + } else { + temp[key] = value; + } + } + + return temp; +} \ No newline at end of file diff --git a/src/shared/helpers/url.helpers.ts b/src/shared/helpers/url.helpers.ts index bdd2ea21..4f1e21a9 100644 --- a/src/shared/helpers/url.helpers.ts +++ b/src/shared/helpers/url.helpers.ts @@ -6,3 +6,30 @@ export function isValidUrl(url: string): boolean { return false; } } + +export function buildUrl({ + protocol = "https", + host = "about:blank", + path = "", + search = {}, + hash = "" + }: { + protocol?: string, + host?: string, + path?: string, + search?: Record, + hash?: string + }): URL { + const url = new URL(`${protocol}://${host}${path}`); + url.hash = hash; + + for (const [key, value] of Object.entries(search)) { + if (Array.isArray(value)) { + value.forEach(v => url.searchParams.append(key, v)); + } else { + url.searchParams.append(key, value); + } + } + + return url; + }