From cbc63da8310178bafe700cdb8583c3933ab02a4d Mon Sep 17 00:00:00 2001 From: NamH Date: Thu, 28 Dec 2023 13:00:20 +0700 Subject: [PATCH] fix: #1183 Reveal in finder does not work on windows (#1239) * fix(OpenFile): #1183 reveal in finder does not work on windows Signed-off-by: James --------- Signed-off-by: James --- core/src/api/index.ts | 1 + core/src/core.ts | 8 +++++++ electron/handlers/app.ts | 7 ++++++ web/containers/CardSidebar/index.tsx | 9 +++++++- web/next.config.js | 3 +++ web/screens/Chat/Sidebar/index.tsx | 22 ++++++++----------- .../ExtensionsCatalog/index.tsx | 5 ----- web/types/index.d.ts | 3 +++ 8 files changed, 39 insertions(+), 19 deletions(-) diff --git a/core/src/api/index.ts b/core/src/api/index.ts index 64e781096..4f2b45f5f 100644 --- a/core/src/api/index.ts +++ b/core/src/api/index.ts @@ -10,6 +10,7 @@ export enum AppRoute { openAppDirectory = 'openAppDirectory', openFileExplore = 'openFileExplorer', relaunch = 'relaunch', + joinPath = 'joinPath' } export enum AppEvent { diff --git a/core/src/core.ts b/core/src/core.ts index f268233b7..0f20feb1e 100644 --- a/core/src/core.ts +++ b/core/src/core.ts @@ -44,6 +44,13 @@ const getUserSpace = (): Promise => global.core.api?.getUserSpace() const openFileExplorer: (path: string) => Promise = (path) => global.core.api?.openFileExplorer(path) +/** + * Joins multiple paths together. + * @param paths - The paths to join. + * @returns {Promise} A promise that resolves with the joined path. + */ +const joinPath: (paths: string[]) => Promise = (paths) => global.core.api?.joinPath(paths) + const getResourcePath: () => Promise = () => global.core.api?.getResourcePath() /** @@ -66,4 +73,5 @@ export { getUserSpace, openFileExplorer, getResourcePath, + joinPath, } diff --git a/electron/handlers/app.ts b/electron/handlers/app.ts index fc2d0ee59..ff88cd8f1 100644 --- a/electron/handlers/app.ts +++ b/electron/handlers/app.ts @@ -48,6 +48,13 @@ export function handleAppIPCs() { shell.openPath(url) }) + /** + * Joins multiple paths together, respect to the current OS. + */ + ipcMain.handle(AppRoute.joinPath, async (_event, paths: string[]) => + join(...paths) + ) + /** * Relaunches the app in production - reload window in development. * @param _event - The IPC event object. diff --git a/web/containers/CardSidebar/index.tsx b/web/containers/CardSidebar/index.tsx index 8c7fe3314..e3851214b 100644 --- a/web/containers/CardSidebar/index.tsx +++ b/web/containers/CardSidebar/index.tsx @@ -29,6 +29,13 @@ export default function CardSidebar({ useClickOutside(() => setMore(false), null, [menu, toggle]) + let openFolderTitle: string = 'Open Containing Folder' + if (isMac) { + openFolderTitle = 'Reveal in Finder' + } else if (isWindows) { + openFolderTitle = 'Reveal in File Explorer' + } + return (
- Reveal in Finder + {openFolderTitle}
{ const assistantId = activeThread.assistants[0]?.assistant_id switch (type) { case 'Thread': - filePath = join('threads', activeThread.id) + filePath = await joinPath(['threads', activeThread.id]) break case 'Model': if (!selectedModel) return - filePath = join('models', selectedModel.id) + filePath = await joinPath(['models', selectedModel.id]) break case 'Assistant': if (!assistantId) return - filePath = join('assistants', assistantId) + filePath = await joinPath(['assistants', assistantId]) break default: break } if (!filePath) return - - const fullPath = join(userSpace, filePath) + const fullPath = await joinPath([userSpace, filePath]) openFileExplorer(fullPath) } @@ -87,23 +84,22 @@ const Sidebar: React.FC = () => { const assistantId = activeThread.assistants[0]?.assistant_id switch (type) { case 'Thread': - filePath = join('threads', activeThread.id, 'thread.json') + filePath = await joinPath(['threads', activeThread.id, 'thread.json']) break case 'Model': if (!selectedModel) return - filePath = join('models', selectedModel.id, 'model.json') + filePath = await joinPath(['models', selectedModel.id, 'model.json']) break case 'Assistant': if (!assistantId) return - filePath = join('assistants', assistantId, 'assistant.json') + filePath = await joinPath(['assistants', assistantId, 'assistant.json']) break default: break } if (!filePath) return - - const fullPath = join(userSpace, filePath) + const fullPath = await joinPath([userSpace, filePath]) openFileExplorer(fullPath) } diff --git a/web/screens/Settings/CoreExtensions/ExtensionsCatalog/index.tsx b/web/screens/Settings/CoreExtensions/ExtensionsCatalog/index.tsx index b7ac59aa6..e2a6f3e13 100644 --- a/web/screens/Settings/CoreExtensions/ExtensionsCatalog/index.tsx +++ b/web/screens/Settings/CoreExtensions/ExtensionsCatalog/index.tsx @@ -5,8 +5,6 @@ import React, { useState, useEffect, useRef, useContext } from 'react' import { Button } from '@janhq/uikit' -import Loader from '@/containers/Loader' - import { FeatureToggleContext } from '@/context/FeatureToggle' import { useGetAppVersion } from '@/hooks/useGetAppVersion' @@ -18,7 +16,6 @@ import { extensionManager } from '@/extension' const ExtensionCatalog = () => { const [activeExtensions, setActiveExtensions] = useState([]) const [extensionCatalog, setExtensionCatalog] = useState([]) - const [isLoading, setIsLoading] = useState(false) const fileInputRef = useRef(null) const { version } = useGetAppVersion() const { experimentalFeatureEnabed } = useContext(FeatureToggleContext) @@ -95,8 +92,6 @@ const ExtensionCatalog = () => { } } - if (isLoading) return - return (
{extensionCatalog diff --git a/web/types/index.d.ts b/web/types/index.d.ts index 5e7b401ae..bd46b8a6f 100644 --- a/web/types/index.d.ts +++ b/web/types/index.d.ts @@ -8,6 +8,9 @@ declare global { declare const VERSION: string declare const ANALYTICS_ID: string declare const ANALYTICS_HOST: string + declare const isMac: boolean + declare const isWindows: boolean + declare const isLinux: boolean interface Core { api: APIFunctions events: EventEmitter