From 2ec3833977a6791f3a0bdc7d01a54e4addb6757f Mon Sep 17 00:00:00 2001 From: Eugene Pankov Date: Mon, 8 Oct 2018 13:40:16 -0700 Subject: [PATCH] dropped winreg in favor of rage-edit --- package.json | 2 +- terminus-core/package.json | 2 +- .../src/services/shellIntegration.service.ts | 37 +++---------------- terminus-core/yarn.lock | 8 ++-- terminus-plugin-manager/webpack.config.js | 1 - terminus-terminal/package.json | 5 +-- terminus-terminal/src/shells/cygwin32.ts | 16 +------- terminus-terminal/src/shells/cygwin64.ts | 16 +------- terminus-terminal/src/shells/gitBash.ts | 17 +-------- .../src/shells/powershellCore.ts | 17 +-------- terminus-terminal/webpack.config.js | 1 - terminus-terminal/yarn.lock | 12 ++---- 12 files changed, 26 insertions(+), 108 deletions(-) diff --git a/package.json b/package.json index 7be6bdda..84c4c9f0 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "@types/electron-debug": "^1.1.0", "@types/fs-promise": "1.0.1", "@types/js-yaml": "^3.11.2", - "@types/node": "7.0.5", + "@types/node": "^10.11.4", "@types/webpack-env": "1.13.0", "apply-loader": "0.1.0", "awesome-typescript-loader": "^5.0.0", diff --git a/terminus-core/package.json b/terminus-core/package.json index 404ff996..db1f0ed1 100644 --- a/terminus-core/package.json +++ b/terminus-core/package.json @@ -27,6 +27,7 @@ "electron-updater": "^2.8.9", "ng2-dnd": "^5.0.2", "ngx-perfect-scrollbar": "^6.0.0", + "rage-edit": "^1.1.0", "shell-escape": "^0.2.0", "universal-analytics": "^0.4.17" }, @@ -43,7 +44,6 @@ "dependencies": { "deepmerge": "^1.5.0", "js-yaml": "^3.9.0", - "winreg": "^1.2.4", "winston": "^2.4.0" }, "false": {} diff --git a/terminus-core/src/services/shellIntegration.service.ts b/terminus-core/src/services/shellIntegration.service.ts index f51fe116..f55dcb6a 100644 --- a/terminus-core/src/services/shellIntegration.service.ts +++ b/terminus-core/src/services/shellIntegration.service.ts @@ -1,15 +1,11 @@ import * as path from 'path' import * as fs from 'mz/fs' +import { Registry } from 'rage-edit' import { exec } from 'mz/child_process' import { Injectable } from '@angular/core' import { ElectronService } from './electron.service' import { HostAppService, Platform } from './hostApp.service' -let Registry = null -try { - Registry = require('winreg') -} catch (_) { } // tslint:disable-line no-empty - @Injectable() export class ShellIntegrationService { private automatorWorkflows = ['Open Terminus here.workflow', 'Paste path into Terminus.workflow'] @@ -17,11 +13,11 @@ export class ShellIntegrationService { private automatorWorkflowsDestination: string private registryKeys = [ { - path: '\\Software\\Classes\\Directory\\Background\\shell\\Open Terminus here', + path: 'HKCU\\Software\\Classes\\Directory\\Background\\shell\\Open Terminus here', command: 'open "%V"' }, { - path: '\\Software\\Classes\\*\\shell\\Paste path into Terminus', + path: 'HKCU\\Software\\Classes\\*\\shell\\Paste path into Terminus', command: 'paste "%V"' }, ] @@ -54,10 +50,7 @@ export class ShellIntegrationService { if (this.hostApp.platform === Platform.macOS) { return await fs.exists(path.join(this.automatorWorkflowsDestination, this.automatorWorkflows[0])) } else if (this.hostApp.platform === Platform.Windows) { - return await new Promise(resolve => { - let reg = new Registry({ hive: Registry.HKCU, key: this.registryKeys[0].path, arch: 'x64' }) - reg.keyExists((err, exists) => resolve(!err && exists)) - }) + return await Registry.has(this.registryKeys[0].path) } return true } @@ -69,26 +62,8 @@ export class ShellIntegrationService { } } else if (this.hostApp.platform === Platform.Windows) { for (let registryKey of this.registryKeys) { - let reg = new Registry({ hive: Registry.HKCU, key: registryKey.path, arch: 'x64' }) - await new Promise(resolve => { - reg.set('Icon', Registry.REG_SZ, this.electron.app.getPath('exe'), () => { - reg.create(() => { - let cmd = new Registry({ - hive: Registry.HKCU, - key: registryKey.path + '\\command', - arch: 'x64' - }) - cmd.create(() => { - cmd.set( - '', - Registry.REG_SZ, - this.electron.app.getPath('exe') + ' ' + registryKey.command, - () => resolve() - ) - }) - }) - }) - }) + await Registry.set(registryKey.path, 'Icon', this.electron.app.getPath('exe')) + await Registry.set(registryKey.path + '\\command', '', this.electron.app.getPath('exe') + ' ' + registryKey.command) } } } diff --git a/terminus-core/yarn.lock b/terminus-core/yarn.lock index 9da91dfd..faca1c1a 100644 --- a/terminus-core/yarn.lock +++ b/terminus-core/yarn.lock @@ -414,6 +414,10 @@ qs@~6.5.1: version "6.5.2" resolved "https://registry.yarnpkg.com/qs/-/qs-6.5.2.tgz#cb3ae806e8740444584ef154ce8ee98d403f3e36" +rage-edit@^1.1.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/rage-edit/-/rage-edit-1.1.0.tgz#8a5f0bf5c5ff4ab31ad086fa27a55be20fcd0357" + request@2.86.0: version "2.86.0" resolved "https://registry.yarnpkg.com/request/-/request-2.86.0.tgz#2b9497f449b0a32654c081a5cf426bbfb5bf5b69" @@ -549,10 +553,6 @@ verror@1.10.0: core-util-is "1.0.2" extsprintf "^1.2.0" -winreg@^1.2.4: - version "1.2.4" - resolved "https://registry.yarnpkg.com/winreg/-/winreg-1.2.4.tgz#ba065629b7a925130e15779108cf540990e98d1b" - winston@^2.4.0: version "2.4.0" resolved "https://registry.yarnpkg.com/winston/-/winston-2.4.0.tgz#808050b93d52661ed9fb6c26b3f0c826708b0aee" diff --git a/terminus-plugin-manager/webpack.config.js b/terminus-plugin-manager/webpack.config.js index 78a3f8a3..82a8e7dc 100644 --- a/terminus-plugin-manager/webpack.config.js +++ b/terminus-plugin-manager/webpack.config.js @@ -44,7 +44,6 @@ module.exports = { 'path', 'mz/fs', 'mz/child_process', - 'winreg', /^rxjs/, /^@angular/, /^@ng-bootstrap/, diff --git a/terminus-terminal/package.json b/terminus-terminal/package.json index a1c5b57e..1bc3e7ea 100644 --- a/terminus-terminal/package.json +++ b/terminus-terminal/package.json @@ -21,10 +21,10 @@ "@types/mz": "0.0.31", "@types/node": "7.0.12", "@types/webpack-env": "1.13.0", - "@types/winreg": "^1.2.30", "dataurl": "0.1.0", "deep-equal": "1.0.1", "file-loader": "^0.11.2", + "rage-edit": "^1.1.0", "xterm": "^3.6.0" }, "peerDependencies": { @@ -45,8 +45,7 @@ "mz": "^2.6.0", "node-pty-tmp": "0.7.2", "ps-node": "^0.1.6", - "runes": "^0.4.2", - "winreg": "^1.2.3" + "runes": "^0.4.2" }, "false": {} } diff --git a/terminus-terminal/src/shells/cygwin32.ts b/terminus-terminal/src/shells/cygwin32.ts index 3c0ce996..76a44bd7 100644 --- a/terminus-terminal/src/shells/cygwin32.ts +++ b/terminus-terminal/src/shells/cygwin32.ts @@ -1,14 +1,10 @@ import * as path from 'path' import { Injectable } from '@angular/core' +import { Registry } from 'rage-edit' import { HostAppService, Platform } from 'terminus-core' import { ShellProvider, IShell } from '../api' -let Registry = null -try { - Registry = require('winreg') -} catch (_) { } // tslint:disable-line no-empty - @Injectable() export class Cygwin32ShellProvider extends ShellProvider { constructor ( @@ -22,15 +18,7 @@ export class Cygwin32ShellProvider extends ShellProvider { return [] } - let cygwinPath = await new Promise(resolve => { - let reg = new Registry({ hive: Registry.HKLM, key: '\\Software\\Cygwin\\setup', arch: 'x86' }) - reg.get('rootdir', (err, item) => { - if (err || !item) { - return resolve(null) - } - resolve(item.value) - }) - }) + let cygwinPath = await Registry.get('HKLM\\Software\\WOW6432Node\\Cygwin\\setup', 'rootdir') if (!cygwinPath) { return [] diff --git a/terminus-terminal/src/shells/cygwin64.ts b/terminus-terminal/src/shells/cygwin64.ts index 2d3f73cb..b4301947 100644 --- a/terminus-terminal/src/shells/cygwin64.ts +++ b/terminus-terminal/src/shells/cygwin64.ts @@ -1,14 +1,10 @@ import * as path from 'path' import { Injectable } from '@angular/core' +import { Registry } from 'rage-edit' import { HostAppService, Platform } from 'terminus-core' import { ShellProvider, IShell } from '../api' -let Registry = null -try { - Registry = require('winreg') -} catch (_) { } // tslint:disable-line no-empty - @Injectable() export class Cygwin64ShellProvider extends ShellProvider { constructor ( @@ -22,15 +18,7 @@ export class Cygwin64ShellProvider extends ShellProvider { return [] } - let cygwinPath = await new Promise(resolve => { - let reg = new Registry({ hive: Registry.HKLM, key: '\\Software\\Cygwin\\setup', arch: 'x64' }) - reg.get('rootdir', (err, item) => { - if (err || !item) { - return resolve(null) - } - resolve(item.value) - }) - }) + let cygwinPath = await Registry.get('HKLM\\Software\\Cygwin\\setup', 'rootdir') if (!cygwinPath) { return [] diff --git a/terminus-terminal/src/shells/gitBash.ts b/terminus-terminal/src/shells/gitBash.ts index 43f2995d..c394871e 100644 --- a/terminus-terminal/src/shells/gitBash.ts +++ b/terminus-terminal/src/shells/gitBash.ts @@ -1,14 +1,10 @@ import * as path from 'path' import { Injectable } from '@angular/core' +import { Registry } from 'rage-edit' import { HostAppService, Platform } from 'terminus-core' import { ShellProvider, IShell } from '../api' -let Registry = null -try { - Registry = require('winreg') -} catch (_) { } // tslint:disable-line no-empty - @Injectable() export class GitBashShellProvider extends ShellProvider { constructor ( @@ -22,16 +18,7 @@ export class GitBashShellProvider extends ShellProvider { return [] } - let gitBashPath = await new Promise(resolve => { - let reg = new Registry({ hive: Registry.HKLM, key: '\\Software\\GitForWindows' }) - reg.get('InstallPath', (err, item) => { - if (err || !item) { - resolve(null) - return - } - resolve(item.value) - }) - }) + let gitBashPath = await Registry.get('HKLM\\Software\\GitForWindows', 'InstallPath') if (!gitBashPath) { gitBashPath = await new Promise(resolve => { diff --git a/terminus-terminal/src/shells/powershellCore.ts b/terminus-terminal/src/shells/powershellCore.ts index 0ac20791..3044dc34 100644 --- a/terminus-terminal/src/shells/powershellCore.ts +++ b/terminus-terminal/src/shells/powershellCore.ts @@ -1,13 +1,8 @@ import { Injectable } from '@angular/core' +import { Registry } from 'rage-edit' import { HostAppService, Platform } from 'terminus-core' - import { ShellProvider, IShell } from '../api' -let Registry = null -try { - Registry = require('winreg') -} catch (_) { } // tslint:disable-line no-empty - @Injectable() export class PowerShellCoreShellProvider extends ShellProvider { constructor ( @@ -21,15 +16,7 @@ export class PowerShellCoreShellProvider extends ShellProvider { return [] } - let pwshPath = await new Promise(resolve => { - let reg = new Registry({ hive: Registry.HKLM, key: '\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\pwsh.exe', arch: 'x64' }) - reg.get('', (err, item) => { - if (err || !item) { - return resolve(null) - } - resolve(item.value) - }) - }) + let pwshPath = await Registry.get('HKLM\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\pwsh.exe', '') if (!pwshPath) { return [] diff --git a/terminus-terminal/webpack.config.js b/terminus-terminal/webpack.config.js index fa749071..a6be6b1e 100644 --- a/terminus-terminal/webpack.config.js +++ b/terminus-terminal/webpack.config.js @@ -57,7 +57,6 @@ module.exports = { 'node-pty-tmp', 'mz/fs', 'mz/child_process', - 'winreg', /^rxjs/, /^@angular/, /^@ng-bootstrap/, diff --git a/terminus-terminal/yarn.lock b/terminus-terminal/yarn.lock index 10528059..603a4fd2 100644 --- a/terminus-terminal/yarn.lock +++ b/terminus-terminal/yarn.lock @@ -24,10 +24,6 @@ version "1.13.0" resolved "https://registry.yarnpkg.com/@types/webpack-env/-/webpack-env-1.13.0.tgz#3044381647e11ee973c5af2e925323930f691d80" -"@types/winreg@^1.2.30": - version "1.2.30" - resolved "https://registry.yarnpkg.com/@types/winreg/-/winreg-1.2.30.tgz#91d6710e536d345b9c9b017c574cf6a8da64c518" - any-promise@^1.0.0: version "1.3.0" resolved "https://registry.yarnpkg.com/any-promise/-/any-promise-1.3.0.tgz#abc6afeedcea52e809cdc0376aed3ce39635d17f" @@ -112,6 +108,10 @@ ps-node@^0.1.6: dependencies: table-parser "^0.1.3" +rage-edit@^1.1.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/rage-edit/-/rage-edit-1.1.0.tgz#8a5f0bf5c5ff4ab31ad086fa27a55be20fcd0357" + runes@^0.4.2: version "0.4.2" resolved "https://registry.yarnpkg.com/runes/-/runes-0.4.2.tgz#1ddc1ea41de769cb32fc068a64fbbc45cd21052e" @@ -134,10 +134,6 @@ thenify-all@^1.0.0: dependencies: any-promise "^1.0.0" -winreg@^1.2.3: - version "1.2.4" - resolved "https://registry.yarnpkg.com/winreg/-/winreg-1.2.4.tgz#ba065629b7a925130e15779108cf540990e98d1b" - xterm@^3.6.0: version "3.6.0" resolved "https://registry.yarnpkg.com/xterm/-/xterm-3.6.0.tgz#9b95cd23a338e5842343aec1a104f094c5153e7c"