mirror of
https://github.com/Eugeny/tabby.git
synced 2025-10-04 14:04:56 +00:00
shell context menu integration (fixes #362)
This commit is contained in:
@@ -43,6 +43,7 @@
|
||||
"dependencies": {
|
||||
"deepmerge": "^1.5.0",
|
||||
"js-yaml": "^3.9.0",
|
||||
"winreg": "^1.2.4",
|
||||
"winston": "^2.4.0"
|
||||
},
|
||||
"false": {}
|
||||
|
@@ -13,4 +13,5 @@ export { Logger, LogService } from '../services/log.service'
|
||||
export { HomeBaseService } from '../services/homeBase.service'
|
||||
export { HotkeysService } from '../services/hotkeys.service'
|
||||
export { HostAppService, Platform } from '../services/hostApp.service'
|
||||
export { ShellIntegrationService } from '../services/shellIntegration.service'
|
||||
export { ThemesService } from '../services/themes.service'
|
||||
|
@@ -14,6 +14,7 @@ import { LogService } from './services/log.service'
|
||||
import { HomeBaseService } from './services/homeBase.service'
|
||||
import { HotkeysService, AppHotkeyProvider } from './services/hotkeys.service'
|
||||
import { DockingService } from './services/docking.service'
|
||||
import { ShellIntegrationService } from './services/shellIntegration.service'
|
||||
import { TabRecoveryService } from './services/tabRecovery.service'
|
||||
import { ThemesService } from './services/themes.service'
|
||||
import { TouchbarService } from './services/touchbar.service'
|
||||
@@ -51,6 +52,7 @@ const PROVIDERS = [
|
||||
HostAppService,
|
||||
HotkeysService,
|
||||
LogService,
|
||||
ShellIntegrationService,
|
||||
TabRecoveryService,
|
||||
ThemesService,
|
||||
TouchbarService,
|
||||
|
85
terminus-core/src/services/shellIntegration.service.ts
Normal file
85
terminus-core/src/services/shellIntegration.service.ts
Normal file
@@ -0,0 +1,85 @@
|
||||
import * as path from 'path'
|
||||
import * as fs from 'mz/fs'
|
||||
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']
|
||||
private automatorWorkflowsLocation: string
|
||||
private automatorWorkflowsDestination: string
|
||||
private registryKeys = [
|
||||
{
|
||||
path: '\\Software\\Classes\\Directory\\Background\\shell\\Open Terminus here',
|
||||
command: 'open "%V"'
|
||||
},
|
||||
{
|
||||
path: '\\Software\\Classes\\*\\shell\\Paste path into Terminus',
|
||||
command: 'paste "%V"'
|
||||
},
|
||||
]
|
||||
constructor (
|
||||
private electron: ElectronService,
|
||||
private hostApp: HostAppService,
|
||||
) {
|
||||
if (this.hostApp.platform === Platform.macOS) {
|
||||
this.automatorWorkflowsLocation = path.join(
|
||||
path.dirname(path.dirname(this.electron.app.getPath('exe'))),
|
||||
'Resources',
|
||||
'extras',
|
||||
'automator-workflows',
|
||||
)
|
||||
this.automatorWorkflowsDestination = path.join(process.env.HOME, 'Library', 'Services')
|
||||
}
|
||||
}
|
||||
|
||||
async isInstalled (): Promise<boolean> {
|
||||
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 true
|
||||
}
|
||||
|
||||
async install () {
|
||||
if (this.hostApp.platform === Platform.macOS) {
|
||||
for (let wf of this.automatorWorkflows) {
|
||||
await exec(`cp -r "${this.automatorWorkflowsLocation}/${wf}" "${this.automatorWorkflowsDestination}"`)
|
||||
}
|
||||
} 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()
|
||||
)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -549,6 +549,10 @@ 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"
|
||||
|
Reference in New Issue
Block a user