Browse Source

dropped winreg in favor of rage-edit

Eugene Pankov 7 years ago
parent
commit
2ec3833977

+ 1 - 1
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",

+ 1 - 1
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": {}

+ 6 - 31
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<boolean>(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)
             }
         }
     }

+ 4 - 4
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"
+
 [email protected]:
   version "2.86.0"
   resolved "https://registry.yarnpkg.com/request/-/request-2.86.0.tgz#2b9497f449b0a32654c081a5cf426bbfb5bf5b69"
@@ -549,10 +553,6 @@ [email protected]:
     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"

+ 0 - 1
terminus-plugin-manager/webpack.config.js

@@ -44,7 +44,6 @@ module.exports = {
     'path',
     'mz/fs',
     'mz/child_process',
-    'winreg',
     /^rxjs/,
     /^@angular/,
     /^@ng-bootstrap/,

+ 2 - 3
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": {}
 }

+ 2 - 14
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<string>(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 []

+ 2 - 14
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<string>(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 []

+ 2 - 15
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<string>(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<string>(resolve => {

+ 2 - 15
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<string>(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 []

+ 0 - 1
terminus-terminal/webpack.config.js

@@ -57,7 +57,6 @@ module.exports = {
     'node-pty-tmp',
     'mz/fs',
     'mz/child_process',
-    'winreg',
     /^rxjs/,
     /^@angular/,
     /^@ng-bootstrap/,

+ 4 - 8
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"