mirror of
https://git.quad4.io/RNS-Things/MeshChatX.git
synced 2026-10-22 21:01:14 +00:00
feat(electron): add file and directory selection dialogs; implement open path functionality
This commit is contained in:
3 files changed
+95
No files matched your search
@@ -17,6 +17,17 @@ const crypto = require("crypto");
|
||||
// remember main window
|
||||
var mainWindow = null;
|
||||
|
||||
function getDialogParentWindow() {
|
||||
const focused = BrowserWindow.getFocusedWindow();
|
||||
if (focused && !focused.isDestroyed()) {
|
||||
return focused;
|
||||
}
|
||||
if (mainWindow && !mainWindow.isDestroyed()) {
|
||||
return mainWindow;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// power save blocker id
|
||||
var activePowerSaveBlockerId = null;
|
||||
|
||||
@@ -190,6 +201,38 @@ ipcMain.handle("showPathInFolder", (event, path) => {
|
||||
shell.showItemInFolder(path);
|
||||
});
|
||||
|
||||
ipcMain.handle("open-path", (event, p) => {
|
||||
return shell.openPath(p);
|
||||
});
|
||||
|
||||
ipcMain.handle("pick-file", async () => {
|
||||
const win = getDialogParentWindow();
|
||||
if (!win) {
|
||||
return null;
|
||||
}
|
||||
const { canceled, filePaths } = await dialog.showOpenDialog(win, {
|
||||
properties: ["openFile"],
|
||||
});
|
||||
if (canceled || !filePaths || filePaths.length === 0) {
|
||||
return null;
|
||||
}
|
||||
return filePaths[0];
|
||||
});
|
||||
|
||||
ipcMain.handle("pick-directory", async () => {
|
||||
const win = getDialogParentWindow();
|
||||
if (!win) {
|
||||
return null;
|
||||
}
|
||||
const { canceled, filePaths } = await dialog.showOpenDialog(win, {
|
||||
properties: ["openDirectory"],
|
||||
});
|
||||
if (canceled || !filePaths || filePaths.length === 0) {
|
||||
return null;
|
||||
}
|
||||
return filePaths[0];
|
||||
});
|
||||
|
||||
function log(message) {
|
||||
// log to stdout of this process
|
||||
console.log(message);
|
||||
|
||||
@@ -21,6 +21,17 @@ const crypto = require("crypto");
|
||||
// remember main window
|
||||
var mainWindow = null;
|
||||
|
||||
function getDialogParentWindow() {
|
||||
const focused = BrowserWindow.getFocusedWindow();
|
||||
if (focused && !focused.isDestroyed()) {
|
||||
return focused;
|
||||
}
|
||||
if (mainWindow && !mainWindow.isDestroyed()) {
|
||||
return mainWindow;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// tray instance
|
||||
var tray = null;
|
||||
|
||||
@@ -265,6 +276,38 @@ ipcMain.handle("showPathInFolder", (event, path) => {
|
||||
shell.showItemInFolder(path);
|
||||
});
|
||||
|
||||
ipcMain.handle("open-path", (event, p) => {
|
||||
return shell.openPath(p);
|
||||
});
|
||||
|
||||
ipcMain.handle("pick-file", async () => {
|
||||
const win = getDialogParentWindow();
|
||||
if (!win) {
|
||||
return null;
|
||||
}
|
||||
const { canceled, filePaths } = await dialog.showOpenDialog(win, {
|
||||
properties: ["openFile"],
|
||||
});
|
||||
if (canceled || !filePaths || filePaths.length === 0) {
|
||||
return null;
|
||||
}
|
||||
return filePaths[0];
|
||||
});
|
||||
|
||||
ipcMain.handle("pick-directory", async () => {
|
||||
const win = getDialogParentWindow();
|
||||
if (!win) {
|
||||
return null;
|
||||
}
|
||||
const { canceled, filePaths } = await dialog.showOpenDialog(win, {
|
||||
properties: ["openDirectory"],
|
||||
});
|
||||
if (canceled || !filePaths || filePaths.length === 0) {
|
||||
return null;
|
||||
}
|
||||
return filePaths[0];
|
||||
});
|
||||
|
||||
function log(message) {
|
||||
// log to stdout of this process
|
||||
console.log(message);
|
||||
|
||||
@@ -63,6 +63,15 @@ contextBridge.exposeInMainWorld("electron", {
|
||||
showPathInFolder: async function (path) {
|
||||
return await ipcRenderer.invoke("showPathInFolder", path);
|
||||
},
|
||||
openPath: async function (path) {
|
||||
return await ipcRenderer.invoke("open-path", path);
|
||||
},
|
||||
pickFile: async function () {
|
||||
return await ipcRenderer.invoke("pick-file");
|
||||
},
|
||||
pickDirectory: async function () {
|
||||
return await ipcRenderer.invoke("pick-directory");
|
||||
},
|
||||
// allow checking hardware acceleration status
|
||||
isHardwareAccelerationEnabled: async function () {
|
||||
return await ipcRenderer.invoke("is-hardware-acceleration-enabled");
|
||||
|
||||
Reference in new issue
Block a user