Skip to content

Commit

Permalink
fix: close tabs by keyboard
Browse files Browse the repository at this point in the history
  • Loading branch information
CyanSalt committed Jan 18, 2021
1 parent d1dc556 commit 95d0488
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 18 deletions.
2 changes: 1 addition & 1 deletion main/internal/shell/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export async function executeCommand(event: IpcMainInvokeEvent, line: string, co
controller.raw ? argv : yargsParser(argv),
event
)
return { code: 0, stdout: String(stdout) }
return { code: 0, stdout: String(stdout ?? '') }
} else {
throw new Error(`command not found: ${command}`)
}
Expand Down
20 changes: 3 additions & 17 deletions renderer/components/app.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,18 @@
import { ipcRenderer } from 'electron'
import { reactive, toRefs, unref, onMounted } from 'vue'
import * as commas from '../../api/renderer'
import type { Launcher } from '../../typings/launcher'
import { loadAddons, loadCustomJS } from '../hooks/addon'
import {
useFullscreen,
handleFrameMessages,
} from '../hooks/frame'
import { runLauncherScript } from '../hooks/launcher'
import { handleLauncherMessages } from '../hooks/launcher'
import {
useIsTabListEnabled,
useWillQuit,
confirmClosing,
handleShellMessages,
} from '../hooks/shell'
import type { CreateTerminalTabOptions } from '../hooks/terminal'
import {
useCurrentTerminal,
useTerminalTabs,
Expand Down Expand Up @@ -84,6 +82,7 @@ export default {
handleFrameMessages()
handleShellMessages()
handleTerminalMessages()
handleLauncherMessages()
const index = process.argv.indexOf('--') + 1
const args = index ? process.argv.slice(index) : []
Expand All @@ -98,22 +97,9 @@ export default {
ipcRenderer.invoke(command, extra)
})
ipcRenderer.on('open-tab', (event, options: CreateTerminalTabOptions) => {
createTerminalTab(options)
})
ipcRenderer.on('run-script', (event, { launcher, index: scriptIndex }: { launcher: Launcher, index: number }) => {
runLauncherScript(launcher, scriptIndex)
})
const willQuitRef = useWillQuit()
ipcRenderer.on('before-quit', () => {
willQuitRef.value = true
})
const tabsRef = useTerminalTabs()
window.addEventListener('beforeunload', async event => {
const willQuit = unref(willQuitRef)
const willQuit = unref(useWillQuit())
const tabs = unref(tabsRef)
if (!willQuit && tabs.length > 1) {
event.returnValue = false
Expand Down
6 changes: 6 additions & 0 deletions renderer/hooks/launcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,9 @@ export function moveLauncher(from: number, to: number) {
}
launchersRef.value = launchers
}

export function handleLauncherMessages() {
ipcRenderer.on('run-script', (event, { launcher, index: scriptIndex }: { launcher: Launcher, index: number }) => {
runLauncherScript(launcher, scriptIndex)
})
}
3 changes: 3 additions & 0 deletions renderer/hooks/shell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,7 @@ export function handleShellMessages() {
ipcRenderer.on('toggle-tab-list', () => {
isTabListEnabledRef.value = !isTabListEnabledRef.value
})
ipcRenderer.on('before-quit', () => {
willQuitRef.value = true
})
}
9 changes: 9 additions & 0 deletions renderer/hooks/terminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,15 @@ function getTerminalTabTitle(tab: TerminalTab) {
}

export function handleTerminalMessages() {
ipcRenderer.on('open-tab', (event, options: CreateTerminalTabOptions) => {
createTerminalTab(options)
})
ipcRenderer.on('close-tab', () => {
const currentTerminal = unref(useCurrentTerminal())
if (currentTerminal) {
closeTerminalTab(currentTerminal)
}
})
ipcRenderer.on('input-terminal', (event, data: Pick<TerminalTab, 'pid' | 'process'> & { data: string }) => {
const tabs = unref(tabsRef)
const tab = tabs.find(item => item.pid === data.pid)
Expand Down

0 comments on commit 95d0488

Please sign in to comment.