Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add the ability to open files from the UI #486

Merged
merged 2 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions components/chat/chatBar/upload/files.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,8 @@ 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.electronAPI.openFile(path.join(file.path, file.name))
}
/>
<Button
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),
});
9 changes: 9 additions & 0 deletions types/window.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
declare global {
interface Window {
electronAPI: {
openFile: (path: string) => void;
};
}
}

export {};
Loading