Skip to content

Commit

Permalink
fix(OpenFile): #1183 reveal in finder does not work on windows
Browse files Browse the repository at this point in the history
Signed-off-by: James <[email protected]>
  • Loading branch information
James committed Dec 28, 2023
1 parent c580b4c commit dfcf44d
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 12 deletions.
1 change: 1 addition & 0 deletions core/src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export enum AppRoute {
openAppDirectory = 'openAppDirectory',
openFileExplore = 'openFileExplorer',
relaunch = 'relaunch',
janJoin = 'janJoin'
}

export enum AppEvent {
Expand Down
3 changes: 3 additions & 0 deletions core/src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ const getUserSpace = (): Promise<string> => global.core.api?.getUserSpace()
const openFileExplorer: (path: string) => Promise<any> = (path) =>
global.core.api?.openFileExplorer(path)

const janJoin: (dirs: string[]) => Promise<string> = (dirs) => global.core.api?.janJoin(dirs)

const getResourcePath: () => Promise<string> = () => global.core.api?.getResourcePath()

/**
Expand All @@ -66,4 +68,5 @@ export {
getUserSpace,
openFileExplorer,
getResourcePath,
janJoin,
}
4 changes: 4 additions & 0 deletions electron/handlers/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ export function handleAppIPCs() {
shell.openPath(url)
})

ipcMain.handle("janJoin", async (_event, stringArray) => {
return join(stringArray)
})

/**
* Relaunches the app in production - reload window in development.
* @param _event - The IPC event object.
Expand Down
21 changes: 9 additions & 12 deletions web/screens/Chat/Sidebar/index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { join } from 'path'

import React from 'react'

import { getUserSpace, openFileExplorer } from '@janhq/core'
import { getUserSpace, openFileExplorer, janJoin } from '@janhq/core'

import { Input, Textarea } from '@janhq/uikit'

Expand Down Expand Up @@ -54,23 +52,22 @@ const Sidebar: React.FC = () => {
const assistantId = activeThread.assistants[0]?.assistant_id
switch (type) {
case 'Thread':
filePath = join('threads', activeThread.id)
filePath = await janJoin(['threads', activeThread.id])
break
case 'Model':
if (!selectedModel) return
filePath = join('models', selectedModel.id)
filePath = await janJoin(['models', selectedModel.id])
break
case 'Assistant':
if (!assistantId) return
filePath = join('assistants', assistantId)
filePath = await janJoin(['assistants', assistantId])
break
default:
break
}

if (!filePath) return

const fullPath = join(userSpace, filePath)
const fullPath = await janJoin([userSpace, filePath])
openFileExplorer(fullPath)
}

Expand All @@ -87,23 +84,23 @@ const Sidebar: React.FC = () => {
const assistantId = activeThread.assistants[0]?.assistant_id
switch (type) {
case 'Thread':
filePath = join('threads', activeThread.id, 'thread.json')
filePath = await janJoin(['threads', activeThread.id, 'thread.json'])
break
case 'Model':
if (!selectedModel) return
filePath = join('models', selectedModel.id, 'model.json')
filePath = await janJoin(['models', selectedModel.id, 'model.json'])
break
case 'Assistant':
if (!assistantId) return
filePath = join('assistants', assistantId, 'assistant.json')
filePath = await janJoin(['assistants', assistantId, 'assistant.json'])
break
default:
break
}

if (!filePath) return

const fullPath = join(userSpace, filePath)
const fullPath = await janJoin([userSpace, filePath])
openFileExplorer(fullPath)
}

Expand Down

0 comments on commit dfcf44d

Please sign in to comment.