@@ -14,6 +14,29 @@ function fsResult(promise) {
1414 } ) ;
1515}
1616
17+ /**
18+ * Returns the app's local data directory path with trailing separator.
19+ * Matches Tauri's appLocalDataDir which uses the bundle identifier.
20+ * - Linux: ~/.local/share/{APP_IDENTIFIER}/
21+ * - macOS: ~/Library/Application Support/{APP_IDENTIFIER}/
22+ * - Windows: %LOCALAPPDATA%/{APP_IDENTIFIER}/
23+ */
24+ function getAppDataDir ( ) {
25+ const home = os . homedir ( ) ;
26+ let appDataDir ;
27+ switch ( process . platform ) {
28+ case 'darwin' :
29+ appDataDir = path . join ( home , 'Library' , 'Application Support' , APP_IDENTIFIER ) ;
30+ break ;
31+ case 'win32' :
32+ appDataDir = path . join ( process . env . LOCALAPPDATA || path . join ( home , 'AppData' , 'Local' ) , APP_IDENTIFIER ) ;
33+ break ;
34+ default :
35+ appDataDir = path . join ( process . env . XDG_DATA_HOME || path . join ( home , '.local' , 'share' ) , APP_IDENTIFIER ) ;
36+ }
37+ return appDataDir + path . sep ;
38+ }
39+
1740function registerFsIpcHandlers ( ) {
1841 // Directory APIs
1942 ipcMain . handle ( 'get-documents-dir' , ( ) => {
@@ -31,25 +54,7 @@ function registerFsIpcHandlers() {
3154 return os . tmpdir ( ) ;
3255 } ) ;
3356
34- ipcMain . handle ( 'get-app-data-dir' , ( ) => {
35- // Match Tauri's appLocalDataDir which uses the bundle identifier "fs.phcode"
36- // Linux: ~/.local/share/fs.phcode/
37- // macOS: ~/Library/Application Support/fs.phcode/
38- // Windows: %LOCALAPPDATA%/fs.phcode/
39- const home = os . homedir ( ) ;
40- let appDataDir ;
41- switch ( process . platform ) {
42- case 'darwin' :
43- appDataDir = path . join ( home , 'Library' , 'Application Support' , APP_IDENTIFIER ) ;
44- break ;
45- case 'win32' :
46- appDataDir = path . join ( process . env . LOCALAPPDATA || path . join ( home , 'AppData' , 'Local' ) , APP_IDENTIFIER ) ;
47- break ;
48- default :
49- appDataDir = path . join ( process . env . XDG_DATA_HOME || path . join ( home , '.local' , 'share' ) , APP_IDENTIFIER ) ;
50- }
51- return appDataDir + path . sep ;
52- } ) ;
57+ ipcMain . handle ( 'get-app-data-dir' , ( ) => getAppDataDir ( ) ) ;
5358
5459 // Get Windows drive letters (returns null on non-Windows platforms)
5560 ipcMain . handle ( 'get-windows-drives' , async ( ) => {
@@ -118,5 +123,6 @@ function registerFsIpcHandlers() {
118123}
119124
120125module . exports = {
121- registerFsIpcHandlers
126+ registerFsIpcHandlers,
127+ getAppDataDir
122128} ;
0 commit comments