Adds a Service URLs setting (ask / in-Paseo / external browser) that controls where URLs from running scripts open on desktop. First click prompts with a "don't ask again" checkbox; in-Paseo opens a workspace browser tab. Closing a browser tab now clears its session partition.
82 lines
2.7 KiB
TypeScript
82 lines
2.7 KiB
TypeScript
import { dialog, ipcMain, BrowserWindow } from "electron";
|
|
|
|
interface AskOptions {
|
|
title?: string;
|
|
okLabel?: string;
|
|
cancelLabel?: string;
|
|
kind?: "info" | "warning" | "error";
|
|
}
|
|
|
|
interface AskWithCheckboxOptions extends AskOptions {
|
|
checkboxLabel: string;
|
|
checkboxChecked?: boolean;
|
|
}
|
|
|
|
interface OpenOptions {
|
|
title?: string;
|
|
defaultPath?: string;
|
|
directory?: boolean;
|
|
multiple?: boolean;
|
|
filters?: Array<{ name: string; extensions: string[] }>;
|
|
}
|
|
|
|
function resolveDialogType(kind: AskOptions["kind"]): "warning" | "error" | "question" {
|
|
if (kind === "warning") return "warning";
|
|
if (kind === "error") return "error";
|
|
return "question";
|
|
}
|
|
|
|
export function registerDialogHandlers(): void {
|
|
ipcMain.handle("paseo:dialog:ask", async (event, message: string, options?: AskOptions) => {
|
|
const win = BrowserWindow.fromWebContents(event.sender);
|
|
const result = await dialog.showMessageBox(win ?? BrowserWindow.getFocusedWindow()!, {
|
|
type: resolveDialogType(options?.kind),
|
|
title: options?.title ?? "Confirm",
|
|
message,
|
|
buttons: [options?.cancelLabel ?? "Cancel", options?.okLabel ?? "OK"],
|
|
defaultId: 1,
|
|
cancelId: 0,
|
|
});
|
|
return result.response === 1;
|
|
});
|
|
|
|
ipcMain.handle(
|
|
"paseo:dialog:askWithCheckbox",
|
|
async (event, message: string, options: AskWithCheckboxOptions) => {
|
|
const win = BrowserWindow.fromWebContents(event.sender);
|
|
const result = await dialog.showMessageBox(win ?? BrowserWindow.getFocusedWindow()!, {
|
|
type: resolveDialogType(options.kind),
|
|
title: options.title ?? "Confirm",
|
|
message,
|
|
buttons: [options.cancelLabel ?? "Cancel", options.okLabel ?? "OK"],
|
|
defaultId: 1,
|
|
cancelId: 0,
|
|
checkboxLabel: options.checkboxLabel,
|
|
checkboxChecked: options.checkboxChecked ?? false,
|
|
});
|
|
return {
|
|
confirmed: result.response === 1,
|
|
dontAskAgain: result.checkboxChecked,
|
|
};
|
|
},
|
|
);
|
|
|
|
ipcMain.handle("paseo:dialog:open", async (event, options?: OpenOptions) => {
|
|
const win = BrowserWindow.fromWebContents(event.sender);
|
|
const properties: Electron.OpenDialogOptions["properties"] = [];
|
|
if (options?.directory) properties.push("openDirectory");
|
|
if (options?.multiple) properties.push("multiSelections");
|
|
if (!options?.directory) properties.push("openFile");
|
|
|
|
const result = await dialog.showOpenDialog(win ?? BrowserWindow.getFocusedWindow()!, {
|
|
title: options?.title,
|
|
defaultPath: options?.defaultPath,
|
|
properties,
|
|
filters: options?.filters,
|
|
});
|
|
|
|
if (result.canceled) return null;
|
|
return options?.multiple ? result.filePaths : (result.filePaths[0] ?? null);
|
|
});
|
|
}
|