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
6 changes: 4 additions & 2 deletions dist/virtualfs-debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -18897,7 +18897,7 @@ let $f1a90a4a391136ce$var$preferNodeWs = false, $f1a90a4a391136ce$var$forceNodeW
options = options || {
multiple: false
};
if (!options.defaultPath) options.defaultPath = await globalObject.electronAPI.getDocumentsDir();
if (!options.defaultPath) options.defaultPath = await globalObject.electronAPI.documentDir();
const dialogOptions = {
defaultPath: options.defaultPath,
title: options.title,
Expand Down Expand Up @@ -18927,7 +18927,7 @@ let $f1a90a4a391136ce$var$preferNodeWs = false, $f1a90a4a391136ce$var$forceNodeW
* @returns {Promise<string|null>} A promise that resolves to the selected file path or null.
*/ async function $f1a90a4a391136ce$var$openElectronFileSaveDialogueAsync(options) {
options = options || {};
if (!options.defaultPath) options.defaultPath = await globalObject.electronAPI.getDocumentsDir();
if (!options.defaultPath) options.defaultPath = await globalObject.electronAPI.documentDir();
const dialogOptions = {
defaultPath: options.defaultPath,
title: options.title
Expand Down Expand Up @@ -20076,6 +20076,8 @@ function $e3f139c5065f0041$var$_isSubPathOf(dir, subDir) {
}
const $e3f139c5065f0041$var$fileSystemLib = {
mountNativeFolder: async function(...args) {
// Opens a file picker(or use provided handle) to open the folder in the system with fs access api.
// to be used in browsers like chrome/edge that supports fs access apis
return $e3f139c5065f0041$require$NativeFS.mountNativeFolder(...args);
},
openTauriFilePickerAsync: function(options) {
Expand Down
2 changes: 1 addition & 1 deletion dist/virtualfs-debug.js.map

Large diffs are not rendered by default.

8 changes: 5 additions & 3 deletions dist/virtualfs.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/virtualfs.js.map

Large diffs are not rendered by default.

23 changes: 19 additions & 4 deletions src-electron/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,18 @@ ipcMain.handle('get-app-path', () => {

// Directory APIs
ipcMain.handle('get-documents-dir', () => {
return path.join(os.homedir(), 'Documents');
// Match Tauri's documentDir which ends with a trailing slash
return path.join(os.homedir(), 'Documents') + path.sep;
});

ipcMain.handle('get-home-dir', () => {
// Match Tauri's homeDir which ends with a trailing slash
const home = os.homedir();
return home.endsWith(path.sep) ? home : home + path.sep;
});

ipcMain.handle('get-temp-dir', () => {
return os.tmpdir();
});

ipcMain.handle('get-app-data-dir', () => {
Expand All @@ -121,14 +132,18 @@ ipcMain.handle('get-app-data-dir', () => {
// macOS: ~/Library/Application Support/fs.phcode/
// Windows: %LOCALAPPDATA%/fs.phcode/
const home = os.homedir();
let appDataDir;
switch (process.platform) {
case 'darwin':
return path.join(home, 'Library', 'Application Support', APP_IDENTIFIER);
appDataDir = path.join(home, 'Library', 'Application Support', APP_IDENTIFIER);
break;
case 'win32':
return path.join(process.env.LOCALAPPDATA || path.join(home, 'AppData', 'Local'), APP_IDENTIFIER);
appDataDir = path.join(process.env.LOCALAPPDATA || path.join(home, 'AppData', 'Local'), APP_IDENTIFIER);
break;
default:
return path.join(process.env.XDG_DATA_HOME || path.join(home, '.local', 'share'), APP_IDENTIFIER);
appDataDir = path.join(process.env.XDG_DATA_HOME || path.join(home, '.local', 'share'), APP_IDENTIFIER);
}
return appDataDir + path.sep;
});

// Get Windows drive letters (returns null on non-Windows platforms)
Expand Down
11 changes: 9 additions & 2 deletions src-electron/preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,18 @@ contextBridge.exposeInMainWorld('electronAPI', {
// Flag to identify Electron environment
isElectron: true,

// Path utilities
path: {
sep: process.platform === 'win32' ? '\\' : '/'
},

// CLI and paths
getCliArgs: () => ipcRenderer.invoke('get-cli-args'),
getAppPath: () => ipcRenderer.invoke('get-app-path'),
getDocumentsDir: () => ipcRenderer.invoke('get-documents-dir'),
getAppDataDir: () => ipcRenderer.invoke('get-app-data-dir'),
documentDir: () => ipcRenderer.invoke('get-documents-dir'),
homeDir: () => ipcRenderer.invoke('get-home-dir'),
tempDir: () => ipcRenderer.invoke('get-temp-dir'),
appLocalDataDir: () => ipcRenderer.invoke('get-app-data-dir'),
getWindowsDrives: () => ipcRenderer.invoke('get-windows-drives'),
showOpenDialog: (options) => ipcRenderer.invoke('show-open-dialog', options),
showSaveDialog: (options) => ipcRenderer.invoke('show-save-dialog', options),
Expand Down
4 changes: 2 additions & 2 deletions src/fslib_electron.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ async function openElectronFilePickerAsync(options) {
options = options || { multiple: false };

if (!options.defaultPath) {
options.defaultPath = await globalObject.electronAPI.getDocumentsDir();
options.defaultPath = await globalObject.electronAPI.documentDir();
}

const dialogOptions = {
Expand Down Expand Up @@ -150,7 +150,7 @@ async function openElectronFileSaveDialogueAsync(options) {
options = options || {};

if (!options.defaultPath) {
options.defaultPath = await globalObject.electronAPI.getDocumentsDir();
options.defaultPath = await globalObject.electronAPI.documentDir();
}

const dialogOptions = {
Expand Down
4 changes: 2 additions & 2 deletions test/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@
}
// Electron detection and setup
if(window.electronAPI){
window.electronAPI.getDocumentsDir().then(d => console.log("Electron documentsDir:", d));
window.electronAPI.getAppDataDir().then(d => console.log("Electron appDataDir:", d));
window.electronAPI.documentDir().then(d => console.log("Electron documentsDir:", d));
window.electronAPI.appLocalDataDir().then(d => console.log("Electron appDataDir:", d));
window.electronAPI.getAppPath().then(appPath => {
const nodeSrcPath = appPath + "/../src-tauri/node-src/index.js";
return window.electronAPI.spawnProcess('node', ['--inspect', nodeSrcPath]);
Expand Down
2 changes: 1 addition & 1 deletion test/test-copy.browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function _setupTests(testTypeSrc, testTypeDst) {
return window.__TAURI__.path.appLocalDataDir();
}
if(window.__ELECTRON__) {
return await window.electronAPI.getAppDataDir() + "/";
return window.electronAPI.appLocalDataDir();
}
throw new Error("No native environment detected");
}
Expand Down
4 changes: 2 additions & 2 deletions test/test-dir.browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function _setupTests(testType) {
return window.__TAURI__.path.appLocalDataDir();
}
if(window.__ELECTRON__) {
return await window.electronAPI.getAppDataDir() + "/";
return window.electronAPI.appLocalDataDir();
}
throw new Error("No native environment detected");
}
Expand Down Expand Up @@ -624,4 +624,4 @@ describe(`Dir: Should misc tests`, async function () {
await _RenameFailsWith(`/tauri`, `/some/a/b`, fs.ERR_CODES.EPERM);
await _RenameFailsWith( `/some/a/b`, `/tauri`, fs.ERR_CODES.EPERM);
});
});
});
2 changes: 1 addition & 1 deletion test/test-file.browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function _setupTests(testType) {
return window.__TAURI__.path.appLocalDataDir();
}
if(window.__ELECTRON__) {
return await window.electronAPI.getAppDataDir() + "/";
return window.electronAPI.appLocalDataDir();
}
throw new Error("No native environment detected");
}
Expand Down
Loading
Loading