Expand fs paths with homedir

This commit is contained in:
Alex Gleason committed 2025-10-30 18:05:03 -05:00
1 parent 1bd21f2625
commit b0c0b5c9a4
3 files changed
+29

No files matched your search

+20
View File
@@ -58,8 +58,14 @@ export function AppProvider(props: AppProviderProps) {
setConfig(updater);
};
// Merge default config with stored config
const config = { ...defaultConfig, ...rawConfig };
// Expand filesystem paths
config.fsPathConfig = expandPath(config.fsPathConfig);
config.fsPathProjects = expandPath(config.fsPathProjects);
config.fsPathTmp = expandPath(config.fsPathTmp);
const appContextValue: AppContextType = {
config,
updateConfig,
@@ -127,4 +133,18 @@ function useApplyLanguage(language?: string): void {
useEffect(() => {
i18n.changeLanguage(language ?? navigator.language);
}, [language]);
}
/** Expand FS paths with the user's home directory, if available. */
function expandPath(path: string): string {
const homedir = window.electron?.homedir;
if (!homedir) {
return path;
} else if (path.startsWith('~/')) {
return homedir + path.slice(1);
} else if (path === '~') {
return homedir;
} else {
return path;
}
}