Skip to content

A free and open source instant messaging and VoIP chat app built for friends, groups, and communities.

TypeScript fluxerfluxerapp

fix(app): open middle-clicked links in a background tab (#3663)

Hampusd12625284444
diff --git a/fluxer_app/src/features/messaging/utils/AttachmentCdnUrl.ts b/fluxer_app/src/features/messaging/utils/AttachmentCdnUrl.ts
index 901a6eed0..0abc64c81 100644
--- a/fluxer_app/src/features/messaging/utils/AttachmentCdnUrl.ts
+++ b/fluxer_app/src/features/messaging/utils/AttachmentCdnUrl.ts
@@ -196,3 +196,7 @@ export function attachmentUrlNeedsRefresh(url: string, nowMs: number): boolean {
if (signature === null) return true;
return signature.expiresAtMs <= nowMs + ATTACHMENT_URL_REFRESH_MARGIN_MS;
}
+
+export function attachmentUrlMayNeedRefresh(url: string, nowMs: number): boolean {
+ return url.includes(ATTACHMENT_PATH_SEGMENT) && attachmentUrlNeedsRefresh(url, nowMs);
+}
diff --git a/fluxer_app/src/features/ui/utils/NativeUtils.ts b/fluxer_app/src/features/ui/utils/NativeUtils.ts
index 5674ffa1b..21bf4237d 100644
--- a/fluxer_app/src/features/ui/utils/NativeUtils.ts
+++ b/fluxer_app/src/features/ui/utils/NativeUtils.ts
@@ -1,5 +1,6 @@
// SPDX-License-Identifier: AGPL-3.0-or-later
+import {attachmentUrlMayNeedRefresh} from '@app/features/messaging/utils/AttachmentCdnUrl';
import {unwrapDesktopLocalResourceURL} from '@app/features/messaging/utils/DesktopLocalResourceTarget';
import {Logger} from '@app/features/platform/utils/AppLogger';
import {hasUnavailableElectronNativeContext, isElectron} from '@app/features/ui/utils/ElectronRuntime';
@@ -200,8 +201,12 @@ async function refreshAttachmentUrl(url: string): Promise<string> {
export async function openExternalUrl(url: string, target: string = '_blank') {
const safeUrl = getSafeExternalUrl(url);
if (!safeUrl) return;
- const refreshedUrl = await refreshAttachmentUrl(safeUrl);
const electronApi = getElectronAPI();
+ if (!electronApi && !attachmentUrlMayNeedRefresh(safeUrl, Date.now())) {
+ window.open(safeUrl, target, 'noopener,noreferrer');
+ return;
+ }
+ const refreshedUrl = await refreshAttachmentUrl(safeUrl);
if (electronApi) {
try {
await electronApi.openExternal(refreshedUrl);