Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/app/components/setting-tile/SettingTile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -52,7 +52,7 @@ function SettingTileSettingLinkAction({
: settingTileSettingLinkActionMobileVisible,
].join(' ')}
onClick={async () => {
if (await shareText(copyPath)) setCopied();
if (await copyToClipboard(copyPath)) setCopied();
}}
size="300"
variant="Surface"
Expand Down
46 changes: 46 additions & 0 deletions src/app/utils/platform.test.ts
Original file line number Diff line number Diff line change
@@ -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 changes: 6 additions & 0 deletions src/app/utils/platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading