fix: tauri settings links and copying to clipboard instead of share

This commit is contained in:
7w1 committed 2026-07-21 23:25:57 -05:00
1 parent b1abf99174
commit 26fbff107b
3 files changed
+54 -2

No files matched your search

@@ -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"
+46
View File
@@ -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');
});
});
+6
View File
@@ -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;