From 825b35d164bcae9e05e931b72f5e8b60f6b17763 Mon Sep 17 00:00:00 2001 From: MathieuG-P <40181755+Zagrios@users.noreply.github.com> Date: Wed, 13 Sep 2023 00:14:38 +0200 Subject: [PATCH] [feature] create LIV service --- src/main/services/liv.service.ts | 69 ++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 src/main/services/liv.service.ts diff --git a/src/main/services/liv.service.ts b/src/main/services/liv.service.ts new file mode 100644 index 00000000..717e5f9d --- /dev/null +++ b/src/main/services/liv.service.ts @@ -0,0 +1,69 @@ +import { execOnOs } from "../helpers/env.helpers"; +import path from "path"; +import regedit from "regedit"; + +export class LivService { + + private static instance: LivService; + + public static getInstance(): LivService { + if (!LivService.instance) { + LivService.instance = new LivService(); + } + return LivService.instance; + } + + private readonly livRegeditKey: string = path.join("HKCU", "SOFTWARE", "LIV.App"); + + private constructor() { + + } + + public isLivInstalled(): Promise { + return execOnOs({ + win32: async () => { + const regRes = await regedit.promisified.list([this.livRegeditKey]).then(res => res[this.livRegeditKey]); + return regRes !== undefined && regRes.exists; + } + }); + } + + public async createLivShortcut(entry: LivEntry): Promise { + return execOnOs({ + win32: async () => { + const livExternalAppsRegeditKey = path.join(this.livRegeditKey, "ExternalApplications", entry.id); + await regedit.promisified.createKey([livExternalAppsRegeditKey]); + await regedit.promisified.putValue({ + [livExternalAppsRegeditKey]: { + "InstallPath": { + value: entry.installPath, + type: "REG_SZ" + }, + "Executable": { + value: entry.executable, + type: "REG_SZ" + }, + "Arguments": { + value: entry.arguments, + type: "REG_SZ" + }, + "Name": { + value: entry.name, + type: "REG_SZ" + } + } + }); + } + }); + } + +} + +export interface LivEntry { + id: string, + name: string, + installPath: string, + executable: string, + arguments: string +} +