Skip to content

Commit

Permalink
feat: add the ability to open files from the UI
Browse files Browse the repository at this point in the history
Signed-off-by: tylerslaton <[email protected]>
  • Loading branch information
tylerslaton committed Sep 10, 2024
1 parent e6f2a4a commit bc31a17
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
5 changes: 3 additions & 2 deletions components/chat/chatBar/upload/files.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@ const Files: React.FC<FilesProps> = ({ files, setFiles }) => {
color="primary"
radius="full"
onPress={async () =>
window.alert(
'Coming soon, we promise! This will open your file.'
// This submits a request to the electron main process to open the file
(window as any).electronAPI.openFile(
path.join(file.path, file.name)
)
}
/>
Expand Down
6 changes: 6 additions & 0 deletions electron/main.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { existsSync, mkdirSync, writeFileSync } from 'fs';
import fixPath from 'fix-path';
import os from 'os';
import { config } from './config.mjs';
import { ipcMain } from 'electron/main';

app.on('window-all-closed', () => app.quit());
app.on('ready', startServer);
Expand Down Expand Up @@ -73,6 +74,11 @@ function createWindow(url) {
},
});

// This is necessary to allow the renderer process (NextJS) to open files in the default system application
ipcMain.on('open-file', (event, arg) => {
shell.openPath(arg);
});

// Check if the platform is macOS before calling setWindowButtonVisibility
if (isMac) {
win.setWindowButtonVisibility(true);
Expand Down
1 change: 1 addition & 0 deletions electron/preload.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ contextBridge.exposeInMainWorld('electronAPI', {
send: (channel, args) => {
ipcRenderer.send(channel, args);
},
openFile: (file) => ipcRenderer.send('open-file', file),
});

0 comments on commit bc31a17

Please sign in to comment.