fix: enhance deep link handling in insomniaFetch function in main (#9977)

This commit is contained in:
Bingbing
2026-05-28 17:04:00 +08:00
committed by GitHub
parent 9c5ae2e307
commit e2878299c1
3 changed files with 10 additions and 5 deletions

View File

@@ -13,9 +13,11 @@ export async function insomniaFetch<T = void>({
origin,
headers,
timeout = INSOMNIA_FETCH_TIME_OUT,
onDeepLink,
}: FetchConfig & {
// It's not used at all, should be removed?
retries?: number;
onDeepLink?: (uri: string) => void;
}): Promise<T> {
const config: RequestInit = {
method,
@@ -39,8 +41,8 @@ export async function insomniaFetch<T = void>({
try {
const response = await fetch((origin || getApiBaseURL()) + path, config);
const uri = response.headers.get('x-insomnia-command');
if (uri) {
window.main.openDeepLink(uri);
if (uri && onDeepLink) {
onDeepLink(uri);
}
const isJson = response.headers.get('content-type')?.includes('application/json') || path.match(/\.json$/);
if (!response.ok) {

View File

@@ -38,7 +38,7 @@ initServices(window._dataServices);
// Remove the global services reference after initialization to improve security by preventing unintended access from the global scope.
delete window._dataServices;
configureFetch(options => insomniaFetch({ ...options }));
configureFetch(options => insomniaFetch({ ...options, onDeepLink: (uri: string) => window.main.openDeepLink(uri) }));
await initPlugins();

View File

@@ -58,7 +58,10 @@ initializeSentry();
registerInsomniaProtocols();
configureFetch(options => insomniaFetch({ ...options }));
let openDeepLinkUrl = async (url: string) => {
console.warn('[main] openDeepLinkUrl function not initialized yet, cannot open URL:', url);
};
configureFetch(options => insomniaFetch({ ...options, onDeepLink: (uri: string) => openDeepLinkUrl(uri) }));
// Handle potential auto-update
if (checkIfRestartNeeded()) {
@@ -245,7 +248,7 @@ const _launchApp = async () => {
});
window = windowUtils.createWindowsAndReturnMain();
const openDeepLinkUrl = async (url: string) => {
openDeepLinkUrl = async (url: string) => {
console.log('[main] Open Deep Link URL', url);
window = windowUtils.createWindowsAndReturnMain();
if (window) {