This commit is contained in:
Eugene Pankov
2021-01-01 18:25:54 +01:00
parent bacb475896
commit c8c00a2c9b
12 changed files with 1080 additions and 2071 deletions

View File

@@ -1,6 +1,8 @@
import { app, ipcMain, Menu, Tray, shell, screen, globalShortcut, MenuItemConstructorOptions } from 'electron'
import * as promiseIpc from 'electron-promise-ipc'
import { loadConfig } from './config'
import { Window, WindowOptions } from './window'
import { pluginManager } from './pluginManager'
export class Application {
private tray: Tray
@@ -20,6 +22,14 @@ export class Application {
}
})
;(promiseIpc as any).on('plugin-manager:install', (path, name, version) => {
return pluginManager.install(path, name, version)
})
;(promiseIpc as any).on('plugin-manager:uninstall', (path, name) => {
return pluginManager.uninstall(path, name)
})
const configData = loadConfig()
if (process.platform === 'linux') {
app.commandLine.appendSwitch('no-sandbox')

View File

@@ -1,4 +1,5 @@
import './portable'
import 'source-map-support/register'
import './sentry'
import './lru'
import { app, ipcMain, Menu } from 'electron'

40
app/lib/pluginManager.ts Normal file
View File

@@ -0,0 +1,40 @@
import { promisify } from 'util'
export class PluginManager {
npm: any
npmReady?: Promise<void>
async ensureLoaded (): Promise<void> {
if (!this.npmReady) {
this.npmReady = new Promise(resolve => {
const npm = require('npm')
npm.load(err => {
if (err) {
console.error(err)
return
}
npm.config.set('global', false)
this.npm = npm
resolve()
})
})
}
return this.npmReady
}
async install (path: string, name: string, version: string): Promise<void> {
await this.ensureLoaded()
this.npm.prefix = path
return promisify(this.npm.commands.install)([`${name}@${version}`])
}
async uninstall (path: string, name: string): Promise<void> {
await this.ensureLoaded()
this.npm.prefix = path
return promisify(this.npm.commands.remove)([name])
}
}
export const pluginManager = new PluginManager()

View File

@@ -31,7 +31,7 @@
"keytar": "^7.2.0",
"mz": "^2.7.0",
"ngx-toastr": "^12.0.1",
"npm": "6.9.0",
"npm": "7",
"path": "0.12.7",
"rxjs": "^6.5.5",
"rxjs-compat": "^6.6.0",
@@ -48,7 +48,8 @@
"devDependencies": {
"@types/mz": "0.0.32",
"@types/node": "14.14.14",
"node-abi": "2.19.3"
"node-abi": "2.19.3",
"source-map-support": "^0.5.19"
},
"peerDependencies": {
"terminus-community-color-schemes": "*",

View File

@@ -35,12 +35,16 @@ module.exports = {
externals: {
electron: 'commonjs electron',
'electron-config': 'commonjs electron-config',
'electron-promise-ipc': 'commonjs electron-promise-ipc',
'electron-vibrancy': 'commonjs electron-vibrancy',
fs: 'commonjs fs',
glasstron: 'commonjs glasstron',
mz: 'commonjs mz',
npm: 'commonjs npm',
path: 'commonjs path',
yargs: 'commonjs yargs',
util: 'commonjs util',
'source-map-support': 'commonjs source-map-support',
'windows-swca': 'commonjs windows-swca',
'windows-blurbehind': 'commonjs windows-blurbehind',
},

File diff suppressed because it is too large Load Diff