From 26fbff107bd34f289eb4cd7f692ff042f63b9ff0 Mon Sep 17 00:00:00 2001 From: 7w1 Date: Tue, 21 Jul 2026 23:25:57 -0500 Subject: [PATCH] fix: tauri settings links and copying to clipboard instead of share --- .../components/setting-tile/SettingTile.tsx | 4 +- src/app/utils/platform.test.ts | 46 +++++++++++++++++++ src/app/utils/platform.ts | 6 +++ 3 files changed, 54 insertions(+), 2 deletions(-) create mode 100644 src/app/utils/platform.test.ts diff --git a/src/app/components/setting-tile/SettingTile.tsx b/src/app/components/setting-tile/SettingTile.tsx index d37c87e859..53b5a56bb3 100644 --- a/src/app/components/setting-tile/SettingTile.tsx +++ b/src/app/components/setting-tile/SettingTile.tsx @@ -3,7 +3,7 @@ import { Box, IconButton, Text } from 'folds'; import { Check, Link, sizedIcon } from '$components/icons/phosphor'; import { BreakWord } from '$styles/Text.css'; import { buildSettingsLink } from '$features/settings/settingsLink'; -import { shareText } from '$utils/share'; +import { copyToClipboard } from '$utils/dom'; import { ScreenSize, useScreenSizeContext } from '$hooks/useScreenSize'; import { useTimeoutToggle } from '$hooks/useTimeoutToggle'; import { useSettingsLinkContext } from '$features/settings/SettingsLinkContext'; @@ -52,7 +52,7 @@ function SettingTileSettingLinkAction({ : settingTileSettingLinkActionMobileVisible, ].join(' ')} onClick={async () => { - if (await shareText(copyPath)) setCopied(); + if (await copyToClipboard(copyPath)) setCopied(); }} size="300" variant="Surface" diff --git a/src/app/utils/platform.test.ts b/src/app/utils/platform.test.ts new file mode 100644 index 0000000000..6a322b9bdf --- /dev/null +++ b/src/app/utils/platform.test.ts @@ -0,0 +1,46 @@ +import { describe, expect, it, vi, beforeEach, afterEach } from 'vitest'; +import { getAppOrigin } from './platform'; +import { isTauri } from '@tauri-apps/api/core'; + +vi.mock('@tauri-apps/api/core', () => ({ + isTauri: vi.fn<() => boolean>(), +})); + +vi.mock('@tauri-apps/plugin-os', () => ({ + type: vi.fn<() => string>(() => 'windows'), +})); + +describe('getAppOrigin', () => { + beforeEach(() => { + vi.mocked(isTauri).mockReturnValue(false); + }); + + afterEach(() => { + vi.unstubAllGlobals(); + }); + + it('returns https://app.sable.moe when running inside Tauri', () => { + vi.mocked(isTauri).mockReturnValue(true); + expect(getAppOrigin()).toBe('https://app.sable.moe'); + }); + + it('returns https://app.sable.moe when hostname is tauri.localhost', () => { + vi.stubGlobal('location', { + origin: 'http://tauri.localhost', + hostname: 'tauri.localhost', + protocol: 'http:', + host: 'tauri.localhost', + }); + expect(getAppOrigin()).toBe('https://app.sable.moe'); + }); + + it('returns window.location.origin in normal web environment', () => { + vi.stubGlobal('location', { + origin: 'https://app.sable.moe', + hostname: 'app.sable.moe', + protocol: 'https:', + host: 'app.sable.moe', + }); + expect(getAppOrigin()).toBe('https://app.sable.moe'); + }); +}); diff --git a/src/app/utils/platform.ts b/src/app/utils/platform.ts index cfec9cbe25..9cfc1eeb22 100644 --- a/src/app/utils/platform.ts +++ b/src/app/utils/platform.ts @@ -18,6 +18,12 @@ export function hasControllingServiceWorker(): boolean { // window.location.origin is "null" on Tauri (tauri:// is opaque per WHATWG). export function getAppOrigin(): string { + if ( + isTauri() || + (typeof window !== 'undefined' && window.location.hostname === 'tauri.localhost') + ) { + return 'https://app.sable.moe'; + } return window.location.origin === 'null' ? `${window.location.protocol}//${window.location.host}` : window.location.origin;