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 express from "express";
|
||||||
import * as getPort from "get-port";
|
import * as getPort from "get-port";
|
||||||
import { search } from "youtube-search-without-api-key";
|
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 { Stream } from "stream";
|
||||||
import { networkInterfaces } from "os";
|
import { networkInterfaces } from "os";
|
||||||
import * as mm from 'music-metadata';
|
import * as mm from 'music-metadata';
|
||||||
|
@ -261,8 +261,10 @@ export class BrowserWindow {
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
public static watcher: any;
|
||||||
|
|
||||||
StartWatcher(path: string) {
|
StartWatcher(path: string) {
|
||||||
const watcher = watch(path, {
|
BrowserWindow.watcher = watch(path, {
|
||||||
ignored: /[\/\\]\./,
|
ignored: /[\/\\]\./,
|
||||||
persistent: true
|
persistent: true
|
||||||
});
|
});
|
||||||
|
@ -272,7 +274,7 @@ export class BrowserWindow {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Declare the listeners of the watcher
|
// Declare the listeners of the watcher
|
||||||
watcher
|
BrowserWindow.watcher
|
||||||
.on('add', function (path: string) {
|
.on('add', function (path: string) {
|
||||||
// console.log('File', path, 'has been added');
|
// console.log('File', path, 'has been added');
|
||||||
})
|
})
|
||||||
|
@ -299,6 +301,10 @@ export class BrowserWindow {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async StopWatcher() {
|
||||||
|
await BrowserWindow.watcher.close();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates the browser window
|
* Creates the browser window
|
||||||
* @generator
|
* @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", () => {
|
ipcMain.handle("reinstall-widevine-cdm", () => {
|
||||||
// remove WidevineCDM from appdata folder
|
// remove WidevineCDM from appdata folder
|
||||||
const widevineCdmPath = join(app.getPath("userData"), "./WidevineCdm");
|
const widevineCdmPath = join(app.getPath("userData"), "./WidevineCdm");
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
</div>
|
</div>
|
||||||
<ul class="list-group list-group-flush">
|
<ul class="list-group list-group-flush">
|
||||||
<li @click="addStyle(theme.file)"
|
<li @click="addStyle(theme.file)"
|
||||||
@contextmenu="contextMenu"
|
@contextmenu="contextMenu($event, theme)"
|
||||||
class="list-group-item list-group-item-dark"
|
class="list-group-item list-group-item-dark"
|
||||||
v-for="theme in themes" :value="theme.file"
|
v-for="theme in themes" :value="theme.file"
|
||||||
v-if="!$root.cfg.visual.styles.includes(theme.file)">
|
v-if="!$root.cfg.visual.styles.includes(theme.file)">
|
||||||
|
@ -34,7 +34,7 @@
|
||||||
<b-row>
|
<b-row>
|
||||||
<b-col class="themeLabel">{{theme.name}}</b-col>
|
<b-col class="themeLabel">{{theme.name}}</b-col>
|
||||||
<b-col sm="auto">
|
<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-col>
|
||||||
</b-row>
|
</b-row>
|
||||||
</li>
|
</li>
|
||||||
|
@ -87,25 +87,24 @@
|
||||||
mounted() {
|
mounted() {
|
||||||
console.log(this.themes)
|
console.log(this.themes)
|
||||||
this.themeList = [...this.themes]
|
this.themeList = [...this.themes]
|
||||||
this.themeList.unshift({
|
// this.themeList.unshift({
|
||||||
name: "Acrylic Grain",
|
// name: "Acrylic Grain",
|
||||||
file: "grain.less"
|
// file: "grain.less"
|
||||||
})
|
// })
|
||||||
this.themeList.unshift({
|
// this.themeList.unshift({
|
||||||
name: "Sweetener",
|
// name: "Sweetener",
|
||||||
file: "sweetener.less"
|
// file: "sweetener.less"
|
||||||
})
|
// })
|
||||||
this.themeList.unshift({
|
// this.themeList.unshift({
|
||||||
name: "Reduce Visuals",
|
// name: "Reduce Visuals",
|
||||||
file: "reduce_visuals.less"
|
// file: "reduce_visuals.less"
|
||||||
})
|
// })
|
||||||
this.themeList.unshift({
|
// this.themeList.unshift({
|
||||||
name: "Inline Drawer",
|
// name: "Inline Drawer",
|
||||||
file: "inline_drawer.less"
|
// file: "inline_drawer.less"
|
||||||
})
|
// })
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
|
||||||
gitHubExplore() {
|
gitHubExplore() {
|
||||||
this.$root.appRoute("themes-github")
|
this.$root.appRoute("themes-github")
|
||||||
},
|
},
|
||||||
|
@ -174,25 +173,56 @@
|
||||||
mounted() {
|
mounted() {
|
||||||
this.themes = ipcRenderer.sendSync("get-themes")
|
this.themes = ipcRenderer.sendSync("get-themes")
|
||||||
// this.getRepos();
|
// this.getRepos();
|
||||||
this.getInstalledThemes();
|
this.getThemesList();
|
||||||
// app.checkForThemeUpdates()
|
// app.checkForThemeUpdates()
|
||||||
},
|
},
|
||||||
methods: {
|
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 = {
|
let menu = {
|
||||||
items: [{
|
items: {
|
||||||
name: "Uninstall",
|
"uninstall": {
|
||||||
action: () => {
|
name: "Uninstall",
|
||||||
|
disabled: true,
|
||||||
}
|
action: () => {
|
||||||
},
|
console.debug(theme)
|
||||||
{
|
ipcRenderer.once("theme-uninstalled", (event, args) => {
|
||||||
name: "View Info",
|
console.debug(event, args)
|
||||||
action: () => {
|
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)
|
this.$root.showMenuPanel(menu, event)
|
||||||
},
|
},
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue