mirror of
https://github.com/Kong/insomnia.git
synced 2026-06-02 13:19:21 -04:00
fix: enhance deep link handling in insomniaFetch function in main (#9977)
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user