From deae018a9e1df20bc632a38f575eda5be440948c Mon Sep 17 00:00:00 2001 From: booploops <49113086+booploops@users.noreply.github.com> Date: Wed, 4 May 2022 14:25:50 -0700 Subject: [PATCH] added uninstall theme --- src/main/base/browserwindow.ts | 47 +++++++++- src/renderer/views/pages/installed-themes.ejs | 94 ++++++++++++------- 2 files changed, 106 insertions(+), 35 deletions(-) diff --git a/src/main/base/browserwindow.ts b/src/main/base/browserwindow.ts index 6f3d6994..b920b66e 100644 --- a/src/main/base/browserwindow.ts +++ b/src/main/base/browserwindow.ts @@ -4,7 +4,7 @@ import * as windowStateKeeper from "electron-window-state"; import * as express from "express"; import * as getPort from "get-port"; import { search } from "youtube-search-without-api-key"; -import { existsSync, rmSync, mkdirSync, readdirSync, readFileSync, writeFileSync, statSync } from "fs"; +import { existsSync, rmSync, mkdirSync, readdirSync, readFileSync, writeFileSync, statSync, unlinkSync, rmdirSync, lstatSync } from "fs"; import { Stream } from "stream"; import { networkInterfaces } from "os"; import * as mm from 'music-metadata'; @@ -261,8 +261,10 @@ export class BrowserWindow { }, }; + public static watcher: any; + StartWatcher(path: string) { - const watcher = watch(path, { + BrowserWindow.watcher = watch(path, { ignored: /[\/\\]\./, persistent: true }); @@ -272,7 +274,7 @@ export class BrowserWindow { } // Declare the listeners of the watcher - watcher + BrowserWindow.watcher .on('add', function (path: string) { // console.log('File', path, 'has been added'); }) @@ -299,6 +301,10 @@ export class BrowserWindow { }); } + async StopWatcher() { + await BrowserWindow.watcher.close(); + } + /** * Creates the browser window * @generator @@ -703,6 +709,41 @@ export class BrowserWindow { }; }) + ipcMain.handle("uninstall-theme", async (event, path) => { + await this.StopWatcher() + const themesDir = utils.getPath("themes") + // validate the path is in the themes directory + try { + if (path.startsWith(themesDir)) { + // if path is directory, delete it + if (lstatSync(path).isDirectory()) { + await rmdirSync(path, { recursive: true }); + }else{ + // if path is file, delete it + await unlinkSync(path); + } + // return the path + BrowserWindow.win.webContents.send("theme-uninstalled", { + path: path, + status: 0 + }); + }else{ + BrowserWindow.win.webContents.send("theme-uninstalled", { + path: path, + status: 1 + }); + } + }catch(e: any) { + BrowserWindow.win.webContents.send("theme-uninstalled", { + path: path, + message: e.message, + status: 2 + }); + } + + this.StartWatcher(utils.getPath('themes')) + }) + ipcMain.handle("reinstall-widevine-cdm", () => { // remove WidevineCDM from appdata folder const widevineCdmPath = join(app.getPath("userData"), "./WidevineCdm"); diff --git a/src/renderer/views/pages/installed-themes.ejs b/src/renderer/views/pages/installed-themes.ejs index 20ef4a5d..5a23eb05 100644 --- a/src/renderer/views/pages/installed-themes.ejs +++ b/src/renderer/views/pages/installed-themes.ejs @@ -26,7 +26,7 @@