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.
52 lines
1.5 KiB
TypeScript
52 lines
1.5 KiB
TypeScript
import { getDesktopHost, isElectronRuntime } from "@/desktop/host";
|
|
import {
|
|
loadAppSettingsFromStorage,
|
|
persistAppSettings,
|
|
type ServiceUrlBehavior,
|
|
} from "@/hooks/use-settings";
|
|
import { openExternalUrl } from "@/utils/open-external-url";
|
|
|
|
export interface OpenServiceUrlOptions {
|
|
openInApp?: (url: string) => void;
|
|
}
|
|
|
|
export async function openServiceUrl(url: string, options?: OpenServiceUrlOptions): Promise<void> {
|
|
const openInApp = options?.openInApp;
|
|
if (!openInApp || !isElectronRuntime()) {
|
|
await openExternalUrl(url);
|
|
return;
|
|
}
|
|
|
|
const behavior = await resolveBehavior(url);
|
|
if (behavior === "in-app") {
|
|
openInApp(url);
|
|
return;
|
|
}
|
|
await openExternalUrl(url);
|
|
}
|
|
|
|
async function resolveBehavior(url: string): Promise<Exclude<ServiceUrlBehavior, "ask">> {
|
|
const settings = await loadAppSettingsFromStorage();
|
|
if (settings.serviceUrlBehavior === "in-app" || settings.serviceUrlBehavior === "external") {
|
|
return settings.serviceUrlBehavior;
|
|
}
|
|
|
|
const askWithCheckbox = getDesktopHost()?.dialog?.askWithCheckbox;
|
|
if (typeof askWithCheckbox !== "function") {
|
|
return "external";
|
|
}
|
|
|
|
const result = await askWithCheckbox(`Open ${url}?`, {
|
|
title: "Open service URL",
|
|
okLabel: "In Paseo",
|
|
cancelLabel: "External browser",
|
|
checkboxLabel: "Don't ask again",
|
|
});
|
|
|
|
const choice: Exclude<ServiceUrlBehavior, "ask"> = result.confirmed ? "in-app" : "external";
|
|
if (result.dontAskAgain) {
|
|
await persistAppSettings({ serviceUrlBehavior: choice });
|
|
}
|
|
return choice;
|
|
}
|