Open-source and local-first Slack and Notion alternative that puts you in control of your data
TypeScript chatchat-applicationcrdteditorelectronknowledge-baselocal-firstnotionnotion-alternativerealtime-collaborationself-hostedslacksqliteteam-collaborationwikiyjs
Add open file feature
Hakan Shehu98cb77b46690
diff --git a/desktop/src/main.ts b/desktop/src/main.tsindex 1527ec39..c4d0d726 100644--- a/desktop/src/main.ts+++ b/desktop/src/main.ts@@ -127,3 +127,15 @@ ipcMain.handle(return dialog.showOpenDialog(BrowserWindow.getFocusedWindow(), options);},);++ipcMain.handle(+ 'open-file',+ async (+ _: unknown,+ userId: string,+ id: string,+ extension: string,+ ): Promise<void> => {+ return fileManager.openFile(userId, id, extension);+ },+);diff --git a/desktop/src/main/file-manager.ts b/desktop/src/main/file-manager.tsindex c1f29968..ad58de5f 100644--- a/desktop/src/main/file-manager.ts+++ b/desktop/src/main/file-manager.ts@@ -1,4 +1,4 @@-import { app, net } from 'electron';+import { net, shell } from 'electron';import path from 'path';import fs from 'fs';import axios from 'axios';@@ -47,6 +47,12 @@ class FileManager {fs.copyFileSync(filePath, destinationFilePath);}+ public openFile(userId: string, id: string, extension: string): void {+ const filesDir = getWorkspaceFilesDirectoryPath(userId);+ const filePath = path.join(filesDir, `${id}${extension}`);+ shell.openPath(filePath);+ }+public async checkForUploads(credentials: WorkspaceCredentials,): Promise<void> {diff --git a/desktop/src/preload.ts b/desktop/src/preload.tsindex ca15deae..38c61b51 100644--- a/desktop/src/preload.ts+++ b/desktop/src/preload.ts@@ -33,6 +33,10 @@ contextBridge.exposeInMainWorld('neuron', {openFileDialog: (options: Electron.OpenDialogOptions) => {return ipcRenderer.invoke('open-file-dialog', options);},++ openFile: (userId: string, id: string, extension: string) => {+ return ipcRenderer.invoke('open-file', userId, id, extension);+ },});contextBridge.exposeInMainWorld('eventBus', {diff --git a/desktop/src/renderer/components/files/file-container.tsx b/desktop/src/renderer/components/files/file-container.tsxindex 60f355be..02c5dacf 100644--- a/desktop/src/renderer/components/files/file-container.tsx+++ b/desktop/src/renderer/components/files/file-container.tsx@@ -3,6 +3,8 @@ import { useWorkspace } from '@/renderer/contexts/workspace';import { useQuery } from '@/renderer/hooks/use-query';import { FilePreview } from '@/renderer/components/files/file-preview';import { FileSidebar } from '@/renderer/components/files/file-sidebar';+import { Button } from '@/renderer/components/ui/button';+import { Icon } from '@/renderer/components/ui/icon';interface FileContainerProps {nodeId: string;@@ -22,8 +24,21 @@ export const FileContainer = ({ nodeId }: FileContainerProps) => {return (<div className="flex h-full max-h-full w-full flex-row items-center gap-2">- <div className="flex h-full max-h-full w-full max-w-full flex-grow items-center justify-center overflow-hidden">- <FilePreview file={data} />+ <div className="flex h-full max-h-full w-full max-w-full flex-grow flex-col items-center justify-center overflow-hidden">+ <div className="mr-2 flex w-full flex-row justify-end gap-2">+ <Button+ variant="outline"+ size="sm"+ onClick={() =>+ window.neuron.openFile(workspace.userId, data.id, data.extension)+ }+ >+ <Icon name="external-link-line" className="mr-1" /> Open+ </Button>+ </div>+ <div className="flex w-full max-w-full flex-grow items-center justify-center overflow-hidden">+ <FilePreview file={data} />+ </div></div><div className="h-full w-72 min-w-72 overflow-hidden border-l border-gray-100 p-2 pl-3"><FileSidebar file={data} />diff --git a/desktop/src/types/window.d.ts b/desktop/src/types/window.d.tsindex bfcabb03..3b82bd79 100644--- a/desktop/src/types/window.d.ts+++ b/desktop/src/types/window.d.ts@@ -27,6 +27,8 @@ interface NeuronApi {openFileDialog: (options: Electron.OpenDialogOptions,) => Promise<Electron.OpenDialogReturnValue>;++ openFile: (userId: string, id: string, extension: string) => Promise<void>;}declare global {