fix(tauri): use getAppOrigin() for all origin-dependent paths

This commit is contained in:
Erwan Leboucher committed 2026-07-17 18:18:50 +02:00
1 parent 213b1b8e3a
commit 5670c9ef3f
4 files changed
+19 -11

No files matched your search

+2 -1
View File
@@ -1,6 +1,7 @@
import type { Path } from 'react-router-dom';
import { generatePath } from 'react-router-dom';
import { trimLeadingSlash, trimTrailingSlash } from '$utils/common';
import { getAppOrigin } from '$utils/platform';
import type { HashRouterConfig } from '$hooks/useClientConfig';
import type { SettingsPathSearchParams } from './paths';
import {
@@ -44,7 +45,7 @@ export const encodeSearchParamValueArray = (ids: string[]): string => ids.join('
export const decodeSearchParamValueArray = (idsParam: string): string[] => idsParam.split(',');
export const getOriginBaseUrl = (hashRouterConfig?: HashRouterConfig): string => {
const baseUrl = `${trimTrailingSlash(window.location.origin)}${import.meta.env.BASE_URL}`;
const baseUrl = `${trimTrailingSlash(getAppOrigin())}${import.meta.env.BASE_URL}`;
if (hashRouterConfig?.enabled) {
return `${trimTrailingSlash(baseUrl)}/#${hashRouterConfig.basename}`;
+5 -9
View File
@@ -10,6 +10,7 @@ import {
} from 'matrix-widget-api';
import { CallWidgetDriver } from './CallWidgetDriver';
import { trimTrailingSlash } from '../../utils/common';
import { getAppOrigin } from '../../utils/platform';
import type { ElementCallThemeKind, ElementMediaStateDetail } from './types';
import { color, config } from 'folds';
import { ElementCallIntent, ElementWidgetActions } from './types';
@@ -96,12 +97,7 @@ export class CallEmbed {
): Widget {
const userId = mx.getSafeUserId();
const deviceId = mx.getDeviceId() ?? '';
// window.location.origin is "null" on Tauri (tauri:// is opaque per WHATWG).
// The widget does new URL(parentUrl), which throws on "null".
const clientOrigin =
window.location.origin === 'null'
? `${window.location.protocol}//${window.location.host}`
: window.location.origin;
const clientOrigin = getAppOrigin();
const widgetId = 'call-embed';
const params = new URLSearchParams({
@@ -130,7 +126,7 @@ export class CallEmbed {
let widgetUrl: URL;
if (elementCallUrl && elementCallUrl.trim()) {
try {
widgetUrl = new URL(elementCallUrl, window.location.origin);
widgetUrl = new URL(elementCallUrl, clientOrigin);
} catch (error) {
debugLog.warn(
'call',
@@ -142,13 +138,13 @@ export class CallEmbed {
);
widgetUrl = new URL(
`${trimTrailingSlash(import.meta.env.BASE_URL)}/public/element-call/index.html`,
window.location.origin
clientOrigin
);
}
} else {
widgetUrl = new URL(
`${trimTrailingSlash(import.meta.env.BASE_URL)}/public/element-call/index.html`,
window.location.origin
clientOrigin
);
}
widgetUrl.search = params.toString();
+10
View File
@@ -8,3 +8,13 @@ export function hasServiceWorker(): boolean {
export function hasControllingServiceWorker(): boolean {
return hasServiceWorker() && navigator.serviceWorker.controller !== null;
}
// window.location.origin is the string "null" on Tauri 2.x macOS/Linux because
// tauri:// is a non-standard (opaque) URL scheme per the WHATWG URL spec. Code
// that feeds origin into new URL() or uses it as a redirect/client URI breaks
// silently. Fall back to protocol + host, which yields "tauri://localhost".
export function getAppOrigin(): string {
return window.location.origin === 'null'
? `${window.location.protocol}//${window.location.host}`
: window.location.origin;
}
+2 -1
View File
@@ -8,6 +8,7 @@ import {
} from '$state/sessions';
import { getLocalStorageItem } from '$state/utils/atomWithLocalStorage';
import { pushSessionToSW } from '../sw-session';
import { getAppOrigin } from '$utils/platform';
export class SessionOidcTokenRefresher extends OidcTokenRefresher {
private readonly userId: string;
@@ -21,7 +22,7 @@ export class SessionOidcTokenRefresher extends OidcTokenRefresher {
super(
session.oidc.issuer,
session.oidc.clientId,
window.location.origin,
getAppOrigin(),
session.deviceId,
session.oidc.idTokenClaims ?? ({} as never)
);