Skip to content

Commit 2306868

Browse files
committed
fix(camera): open file after recording
1 parent d466152 commit 2306868

File tree

6 files changed

+32
-25
lines changed

6 files changed

+32
-25
lines changed

addons/camera/src/renderer/RecorderAnchor.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,10 @@ async function stopCapturing() {
2626
const { startedAt, data } = terminal.addons.recorder.save()
2727
commas.context.invoke('toggle-recorder', terminal, false)
2828
const date = new Date(startedAt)
29-
await ipcRenderer.invoke('save-file', commas.remote.translate('Terminal Recording ${date}#!camera.1', {
29+
const file = await ipcRenderer.invoke('save-file', commas.remote.translate('Terminal Recording ${date}#!camera.1', {
3030
date: `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, '0')}-${String(date.getDate()).padStart(2, '0')} ${String(date.getHours()).padStart(2, '0')}.${String(date.getMinutes()).padStart(2, '0')}.${String(date.getSeconds()).padStart(2, '0')}`,
3131
}) + '.ttyrec', data)
32+
commas.remote.addFile(file)
3233
}
3334
3435
const isCapturing = $computed(() => {

src/api/modules/remote.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
useSettings,
77
useSettingsSpecs,
88
} from '../../renderer/compositions/settings'
9-
import { openDirectory, openFile, openFileExternally, openURL, openURLExternally, showDirectory, showFileExternally } from '../../renderer/compositions/shell'
9+
import { addFile, openDirectory, openFile, openFileExternally, openURL, openURLExternally, showDirectory, showFileExternally } from '../../renderer/compositions/shell'
1010
import { useIsLightTheme, useTheme } from '../../renderer/compositions/theme'
1111
import { translate } from '../../renderer/utils/i18n'
1212
import type { RendererAPIContext } from '../types'
@@ -59,4 +59,5 @@ export {
5959
showDirectory,
6060
openURL,
6161
openURLExternally,
62+
addFile,
6263
}

src/api/renderer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ declare module './modules/context' {
1616
},
1717
'terminal.file-opener': {
1818
extensions: string[],
19-
handler: (file: string) => void,
19+
handler: (file: string) => Promise<void> | void,
2020
},
2121
}
2222
}

src/main/lib/message.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ declare module '@commas/electron-ipc' {
3232
'preview-file': (file: string) => void,
3333
'open-path': (uri: string) => void,
3434
'open-url': (uri: string) => void,
35-
'save-file': (name: string, content: Buffer | string) => Promise<void>,
35+
'save-file': (name: string, content: Buffer | string) => Promise<string>,
3636
}
3737
export interface Events {
3838
'get-path': (name?: Parameters<typeof app['getPath']>[0]) => string,
@@ -219,11 +219,10 @@ function handleMessages() {
219219
ipcMain.handle('open-url', (event, url) => {
220220
shell.openExternal(url)
221221
})
222-
ipcMain.handle('save-file', (event, name, content) => {
223-
return fs.promises.writeFile(
224-
path.join(app.getPath('downloads'), name),
225-
content,
226-
)
222+
ipcMain.handle('save-file', async (event, name, content) => {
223+
const file = path.join(app.getPath('downloads'), name)
224+
await fs.promises.writeFile(file, content)
225+
return file
227226
})
228227
let watcherCollections = new WeakMap<WebContents, Map<string, any>>()
229228
ipcMain.handle('get-ref:file', (event, file: string) => {

src/renderer/compositions/shell.ts

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,12 @@ export async function confirmClosing() {
6767
return response === 0
6868
}
6969

70+
function getFileOpener(file: string) {
71+
const ext = path.extname(file).toLowerCase()
72+
const openers = commas.proxy.context.getCollection('terminal.file-opener')
73+
return openers.find(item => item.extensions.includes(ext))
74+
}
75+
7076
/**
7177
* {@link https://en.wikipedia.org/wiki/Quick_Look#Supported_file_types_by_default}
7278
*/
@@ -113,6 +119,10 @@ const QUICK_LOOK_EXTENSIONS = [
113119
]
114120

115121
export function openFile(file: string) {
122+
const opener = getFileOpener(file)
123+
if (opener) {
124+
return opener.handler(file)
125+
}
116126
if (process.platform === 'darwin') {
117127
const ext = path.extname(file).toLowerCase()
118128
if (QUICK_LOOK_EXTENSIONS.includes(ext)) {
@@ -122,6 +132,14 @@ export function openFile(file: string) {
122132
return globalHandler.invoke('global-renderer:open-file', file)
123133
}
124134

135+
export async function addFile(file: string) {
136+
const opener = getFileOpener(file)
137+
if (opener) {
138+
return opener.handler(file)
139+
}
140+
return globalHandler.invoke('global-renderer:add-file', file)
141+
}
142+
125143
export function showFileExternally(file: string) {
126144
return ipcRenderer.invoke('show-file', file)
127145
}
@@ -134,10 +152,6 @@ export function openFileExternally(file: string) {
134152
return ipcRenderer.invoke('open-path', file)
135153
}
136154

137-
export async function addFile(file: string) {
138-
return ipcRenderer.invoke('open-file', file)
139-
}
140-
141155
export function showDirectory(file: string) {
142156
return globalHandler.invoke('global-renderer:show-directory', file)
143157
}
@@ -172,15 +186,8 @@ export function handleShellMessages() {
172186
ipcRenderer.on('before-quit', () => {
173187
willQuit = true
174188
})
175-
const openers = commas.proxy.context.getCollection('terminal.file-opener')
176189
ipcRenderer.on('add-file', (event, file) => {
177-
const ext = path.extname(file).toLowerCase()
178-
const opener = openers.find(item => item.extensions.includes(ext))
179-
if (opener) {
180-
opener.handler(file)
181-
} else {
182-
globalHandler.invoke('global-renderer:add-file', file)
183-
}
190+
return addFile(file)
184191
})
185192
globalHandler.handle('global-renderer:open-file', (file) => {
186193
return showFileExternally(file)
@@ -194,4 +201,7 @@ export function handleShellMessages() {
194201
globalHandler.handle('global-renderer:open-url', (url) => {
195202
return openURLExternally(url)
196203
})
204+
globalHandler.handle('global-renderer:add-file', (file) => {
205+
// pass
206+
})
197207
}

src/renderer/compositions/terminal.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import { ipcRenderer } from '@commas/electron-ipc'
2020
import type { KeyBindingCommand, MenuItem } from '@commas/types/menu'
2121
import type { ReadonlyTerminalTabAddons, TerminalContext, TerminalTab, TerminalTabCharacter, TerminalTabCharacterCommand } from '@commas/types/terminal'
2222
import * as commas from '../../api/core-renderer'
23-
import { globalHandler } from '../../shared/handler'
2423
import { createIDGenerator } from '../../shared/helper'
2524
import { openContextMenu } from '../utils/frame'
2625
import { translate } from '../utils/i18n'
@@ -1123,7 +1122,4 @@ export function handleTerminalMessages() {
11231122
?? []
11241123
return count ? commands.slice(0 - count) : commands
11251124
})
1126-
globalHandler.handle('global-renderer:add-file', (file) => {
1127-
// pass
1128-
})
11291125
}

0 commit comments

Comments
 (0)