added uninstall theme
This commit is contained in:
parent
0abc06da18
commit
deae018a9e
2 changed files with 106 additions and 35 deletions
|
@ -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");
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
</div>
|
||||
<ul class="list-group list-group-flush">
|
||||
<li @click="addStyle(theme.file)"
|
||||
@contextmenu="contextMenu"
|
||||
@contextmenu="contextMenu($event, theme)"
|
||||
class="list-group-item list-group-item-dark"
|
||||
v-for="theme in themes" :value="theme.file"
|
||||
v-if="!$root.cfg.visual.styles.includes(theme.file)">
|
||||
|
@ -34,7 +34,7 @@
|
|||
<b-row>
|
||||
<b-col class="themeLabel">{{theme.name}}</b-col>
|
||||
<b-col sm="auto">
|
||||
<button @click.stop="contextMenu" class="themeContextMenu codicon codicon-list-unordered"></button>
|
||||
<button @click.stop="contextMenu($event, theme)" class="themeContextMenu codicon codicon-list-unordered"></button>
|
||||
</b-col>
|
||||
</b-row>
|
||||
</li>
|
||||
|
@ -87,25 +87,24 @@
|
|||
mounted() {
|
||||
console.log(this.themes)
|
||||
this.themeList = [...this.themes]
|
||||
this.themeList.unshift({
|
||||
name: "Acrylic Grain",
|
||||
file: "grain.less"
|
||||
})
|
||||
this.themeList.unshift({
|
||||
name: "Sweetener",
|
||||
file: "sweetener.less"
|
||||
})
|
||||
this.themeList.unshift({
|
||||
name: "Reduce Visuals",
|
||||
file: "reduce_visuals.less"
|
||||
})
|
||||
this.themeList.unshift({
|
||||
name: "Inline Drawer",
|
||||
file: "inline_drawer.less"
|
||||
})
|
||||
// this.themeList.unshift({
|
||||
// name: "Acrylic Grain",
|
||||
// file: "grain.less"
|
||||
// })
|
||||
// this.themeList.unshift({
|
||||
// name: "Sweetener",
|
||||
// file: "sweetener.less"
|
||||
// })
|
||||
// this.themeList.unshift({
|
||||
// name: "Reduce Visuals",
|
||||
// file: "reduce_visuals.less"
|
||||
// })
|
||||
// this.themeList.unshift({
|
||||
// name: "Inline Drawer",
|
||||
// file: "inline_drawer.less"
|
||||
// })
|
||||
},
|
||||
methods: {
|
||||
|
||||
gitHubExplore() {
|
||||
this.$root.appRoute("themes-github")
|
||||
},
|
||||
|
@ -174,25 +173,56 @@
|
|||
mounted() {
|
||||
this.themes = ipcRenderer.sendSync("get-themes")
|
||||
// this.getRepos();
|
||||
this.getInstalledThemes();
|
||||
this.getThemesList();
|
||||
// app.checkForThemeUpdates()
|
||||
},
|
||||
methods: {
|
||||
contextMenu(event) {
|
||||
getThemesList() {
|
||||
let themes = ipcRenderer.sendSync("get-themes")
|
||||
themes.unshift({
|
||||
name: "Acrylic Grain",
|
||||
file: "grain.less"
|
||||
})
|
||||
themes.unshift({
|
||||
name: "Sweetener",
|
||||
file: "sweetener.less"
|
||||
})
|
||||
themes.unshift({
|
||||
name: "Reduce Visuals",
|
||||
file: "reduce_visuals.less"
|
||||
})
|
||||
themes.unshift({
|
||||
name: "Inline Drawer",
|
||||
file: "inline_drawer.less"
|
||||
})
|
||||
this.themes = themes
|
||||
},
|
||||
contextMenu(event, theme) {
|
||||
let self = this
|
||||
let menu = {
|
||||
items: [{
|
||||
name: "Uninstall",
|
||||
action: () => {
|
||||
|
||||
}
|
||||
},
|
||||
{
|
||||
name: "View Info",
|
||||
action: () => {
|
||||
|
||||
items: {
|
||||
"uninstall": {
|
||||
name: "Uninstall",
|
||||
disabled: true,
|
||||
action: () => {
|
||||
console.debug(theme)
|
||||
ipcRenderer.once("theme-uninstalled", (event, args) => {
|
||||
console.debug(event, args)
|
||||
self.getThemesList()
|
||||
})
|
||||
ipcRenderer.invoke("uninstall-theme", theme.path)
|
||||
}
|
||||
},
|
||||
"viewInfo": {
|
||||
name: "View Info",
|
||||
action: () => {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
if (theme.path) {
|
||||
menu.items.uninstall.disabled = false
|
||||
}
|
||||
this.$root.showMenuPanel(menu, event)
|
||||
},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue