Skip to content
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
2 changes: 2 additions & 0 deletions web-app/src/locales/en/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,8 @@
"showInFileExplorer": "Show in File Explorer",
"openContainingFolder": "Open Containing Folder",
"failedToRelocateDataFolder": "Failed to relocate data folder",
"couldNotRelocateToRoot": "Cannot relocate data folder to root directory. Please choose another location.",
"couldNotResetRootDirectory": "Cannot reset data folder when it's set to a root directory. Please delete the data folder manually.",
"failedToRelocateDataFolderDesc": "Failed to relocate data folder. Please try again.",
"devVersion": "Development version detected",
"noUpdateAvailable": "You're running the latest version",
Expand Down
2 changes: 2 additions & 0 deletions web-app/src/locales/id/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,8 @@
"showInFinder": "Tampilkan di Finder",
"showInFileExplorer": "Tampilkan di File Explorer",
"openContainingFolder": "Buka Folder Induk",
"couldNotRelocateToRoot": "Tidak dapat memindahkan folder data ke direktori root. Silakan pilih lokasi lain.",
"couldNotResetRootDirectory": "Tidak dapat mengatur ulang folder data saat diatur ke direktori root. Silakan hapus folder data secara manual.",
"failedToRelocateDataFolder": "Gagal memindahkan folder data",
"failedToRelocateDataFolderDesc": "Gagal memindahkan folder data. Silakan coba lagi.",
"devVersion": "Versi pengembangan terdeteksi",
Expand Down
2 changes: 2 additions & 0 deletions web-app/src/locales/pl/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,8 @@
"showInFinder": "Pokaż w Finderze",
"showInFileExplorer": "Pokaż w Explorerze",
"openContainingFolder": "Otwórz Katalog Nadrzędny",
"couldNotRelocateToRoot": "Nie można przenieść folderu danych do katalogu głównego. Proszę wybrać inną lokalizację.",
"couldNotResetRootDirectory": "Nie można zresetować folderu danych, gdy jest ustawiony na katalog główny. Proszę ręcznie usunąć folder danych.",
"failedToRelocateDataFolder": "Błąd zmiany katalogu danych",
"failedToRelocateDataFolderDesc": "Nie udało się przenieść katalogu danych. Proszę spróbować później.",
"devVersion": "Wykryto wersję deweloperską",
Expand Down
2 changes: 2 additions & 0 deletions web-app/src/locales/vn/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,8 @@
"showInFinder": "Hiển thị trong Finder",
"showInFileExplorer": "Hiển thị trong File Explorer",
"openContainingFolder": "Mở Thư mục Chứa",
"couldNotRelocateToRoot": "Không thể di chuyển thư mục dữ liệu đến thư mục gốc. Vui lòng chọn vị trí khác.",
"couldNotResetRootDirectory": "Không thể đặt lại thư mục dữ liệu khi nó được đặt thành thư mục gốc. Vui lòng xóa thư mục dữ liệu thủ công.",
"failedToRelocateDataFolder": "Không thể di chuyển thư mục dữ liệu",
"failedToRelocateDataFolderDesc": "Không thể di chuyển thư mục dữ liệu. Vui lòng thử lại.",
"devVersion": "Đã phát hiện phiên bản phát triển",
Expand Down
2 changes: 2 additions & 0 deletions web-app/src/locales/zh-CN/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,8 @@
"showInFinder": "在 Finder 中显示",
"showInFileExplorer": "在文件资源管理器中显示",
"openContainingFolder": "打开包含文件夹",
"couldNotRelocateToRoot": "无法将数据文件夹重新定位到根目录。请选择其他位置。",
"couldNotResetRootDirectory": "当数据文件夹设置为根目录时,无法重置。请手动删除数据文件夹。",
"failedToRelocateDataFolder": "无法重新定位数据文件夹",
"failedToRelocateDataFolderDesc": "无法重新定位数据文件夹。请重试。",
"devVersion": "检测到开发版本",
Expand Down
2 changes: 2 additions & 0 deletions web-app/src/locales/zh-TW/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,8 @@
"showInFinder": "在 Finder 中顯示",
"showInFileExplorer": "在檔案總管中顯示",
"openContainingFolder": "打開包含資料夾",
"couldNotRelocateToRoot": "無法將資料夾重新定位到根目錄。請選擇其他位置。",
"couldNotResetRootDirectory": "當資料檔案夾設定為根目錄時,無法重置。請手動刪除資料檔案夾。",
"failedToRelocateDataFolder": "無法重新定位資料夾",
"failedToRelocateDataFolderDesc": "無法重新定位資料夾。請重試。",
"devVersion": "檢測到開發版本",
Expand Down
9 changes: 9 additions & 0 deletions web-app/src/routes/settings/general.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import LanguageSwitcher from '@/containers/LanguageSwitcher'
import { PlatformFeatures } from '@/lib/platform/const'
import { PlatformFeature } from '@/lib/platform/types'
import { isRootDir } from '@/utils/path'

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export const Route = createFileRoute(route.settings.general as any)({
Expand All @@ -48,12 +49,12 @@

const openFileTitle = (): string => {
if (IS_MACOS) {
return t('settings:general.showInFinder')

Check warning on line 52 in web-app/src/routes/settings/general.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

52 line is not covered with tests
} else if (IS_WINDOWS) {
return t('settings:general.showInFileExplorer')
} else {
return t('settings:general.openContainingFolder')
}

Check warning on line 57 in web-app/src/routes/settings/general.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

56-57 lines are not covered with tests
}
const { checkForUpdate } = useAppUpdater()
const { pausePolling } = useHardware()
Expand All @@ -73,10 +74,15 @@
}, [serviceHub])

const resetApp = async () => {
// Prevent resetting if data folder is root directory
if (isRootDir(janDataFolder ?? '/')) {
toast.error(t('settings:general.couldNotResetRootDirectory'))
return
}
pausePolling()

Check warning on line 82 in web-app/src/routes/settings/general.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

78-82 lines are not covered with tests
// TODO: Loading indicator
await serviceHub.app().factoryReset()
}

Check warning on line 85 in web-app/src/routes/settings/general.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

84-85 lines are not covered with tests

const handleOpenLogs = async () => {
try {
Expand All @@ -87,53 +93,56 @@
}

const copyToClipboard = async (text: string) => {
try {
await navigator.clipboard.writeText(text)
setIsCopied(true)
setTimeout(() => setIsCopied(false), 2000) // Reset after 2 seconds
} catch (error) {
console.error('Failed to copy to clipboard:', error)
}
}

Check warning on line 103 in web-app/src/routes/settings/general.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

96-103 lines are not covered with tests

const handleDataFolderChange = async () => {
const selectedPath = await serviceHub.dialog().open({
multiple: false,
directory: true,
defaultPath: janDataFolder,
})

Check warning on line 110 in web-app/src/routes/settings/general.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

106-110 lines are not covered with tests

if (selectedPath === janDataFolder) return
if (selectedPath !== null) {
setSelectedNewPath(selectedPath as string)
setIsDialogOpen(true)
}
}

Check warning on line 117 in web-app/src/routes/settings/general.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

112-117 lines are not covered with tests

const confirmDataFolderChange = async () => {
if (selectedNewPath) {
try {
await serviceHub.models().stopAllModels()
serviceHub.events().emit(SystemEvent.KILL_SIDECAR)
setTimeout(async () => {
try {

Check warning on line 125 in web-app/src/routes/settings/general.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

120-125 lines are not covered with tests
// Prevent relocating to root directory (e.g., C:\ or D:\ on Windows, / on Unix)
if (isRootDir(selectedNewPath))
throw new Error(t('settings:general.couldNotRelocateToRoot'))
await serviceHub.app().relocateJanDataFolder(selectedNewPath)
setJanDataFolder(selectedNewPath)

Check warning on line 130 in web-app/src/routes/settings/general.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

127-130 lines are not covered with tests
// Only relaunch if relocation was successful
window.core?.api?.relaunch()
setSelectedNewPath(null)
setIsDialogOpen(false)
} catch (error) {
console.error(error)
toast.error(
error instanceof Error
? error.message
: t('settings:general.failedToRelocateDataFolder')
)
}
}, 1000)
} catch (error) {
console.error('Failed to relocate data folder:', error)

Check warning on line 145 in web-app/src/routes/settings/general.tsx

View workflow job for this annotation

GitHub Actions / coverage-check

132-145 lines are not covered with tests
// Revert the data folder path on error
const originalPath = await serviceHub.app().getJanDataFolder()
setJanDataFolder(originalPath)
Expand Down
29 changes: 29 additions & 0 deletions web-app/src/utils/path.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* Determines if the given path is a root directory.
*
* On Windows, this checks for drive roots such as `C:\` or `D:\`.
* On Mac/Linux, this checks if the path is `/`.
*
* @param selectedNewPath - The path to check.
* @returns `true` if the path is a root directory, otherwise `false`.
*/
export const isRootDir = (selectedNewPath: string) => {
// Windows root: C:\, D:\, etc.
if (IS_WINDOWS) {
return /^[a-zA-Z]:\\?$/.test(selectedNewPath)
}
// Linux/Mac root: /, /mnt, /media, etc.
const linuxRoots = [
'/',
'/mnt',
'/media',
'/boot',
'/home',
'/opt',
'/var',
'/usr',
]
const normalized =
selectedNewPath.replace(/\\/g, '/').replace(/\/+$/, '') || '/'
return linuxRoots.some((root) => normalized === root)
}
Loading