mirror of
https://github.com/Zagrios/bs-manager.git
synced 2026-07-03 14:08:25 +02:00
[feature] prepare shortcut creation
This commit is contained in:
@@ -109,6 +109,25 @@ if (!gotTheLock) {
|
||||
ipcMain.on("log-error", (event, args: IpcRequest<any>) => {
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -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<BSLaunchEvent>(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<void>{
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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<string, string|string[]>): URL {
|
||||
return buildUrl({
|
||||
protocol: this.BSM_PROTOCOL,
|
||||
host,
|
||||
search: params
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
export function objectFromEntries<T>(entries: Iterable<readonly [PropertyKey, T]>): Record<PropertyKey, T | T[]> {
|
||||
const temp: Record<PropertyKey, T | T[]> = {};
|
||||
|
||||
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;
|
||||
}
|
||||
@@ -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<string, string | string[]>,
|
||||
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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user