Something went wrong. Try again.
Synapse is a study workspace. Organize courses read and annotate the material, train with generated exercises and watch your progress forked from denishovart.com/synapse
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283// Where the app runs and which server (if any) this device talks to. In the// browser the API is same-origin and these helpers are inert; in a native// shell (Tauri) the app is standalone by default and a server is an explicit,// device-level choice stored locally.
import { setApiBase, setAuthToken } from './api';
const SERVER_URL_KEY = 'synapse.serverUrl';const TOKEN_KEY = 'synapse.serverToken';const AUTOSYNC_KEY = 'synapse.autoSync';
export function isTauri(): boolean { return typeof window !== 'undefined' && '__TAURI_INTERNALS__' in window;}
// A desktop native shell (macOS/Windows/Linux), as opposed to the iOS/Android// shells. Desktop-only features (local LibreOffice/pandoc conversion, "reveal in// file manager") gate on this, not on isTauri, so they stay hidden on phones// where they are meaningless.export function isDesktopShell(): boolean { if (!isTauri()) return false; const ua = typeof navigator === 'undefined' ? '' : navigator.userAgent; return !/Mobi|Android|iPhone|iPad|iPod/i.test(ua);}
// Web client build: the app served from a static host, no server anywhere// (pnpm --filter @synapse/web build:web-client). Same standalone semantics// as a native shell without a configured server.export function isWebClient(): boolean { return import.meta.env.VITE_WEB_CLIENT === '1';}
// No server in play: the workspace lives on this device alone, features that// need a server (accounts, server AI, uploads through the API) stand down.export function standalone(): boolean { return (isTauri() || isWebClient()) && !deviceServer();}
export interface DeviceServer { url: string; token: string | null;}
export function deviceServer(): DeviceServer | null { if (typeof localStorage === 'undefined') return null; const url = localStorage.getItem(SERVER_URL_KEY); if (!url) return null; return { url, token: localStorage.getItem(TOKEN_KEY) };}
export function setDeviceServer(url: string, token: string | null): void { localStorage.setItem(SERVER_URL_KEY, url.replace(/\/+$/, '')); if (token) localStorage.setItem(TOKEN_KEY, token); else localStorage.removeItem(TOKEN_KEY); applyDeviceServer();}
export function clearDeviceServer(): void { localStorage.removeItem(SERVER_URL_KEY); localStorage.removeItem(TOKEN_KEY); setApiBase(''); setAuthToken(null);}
// Opt-in background sync with nearby devices. Off by default, stored locally.export function autoSyncEnabled(): boolean { return typeof localStorage !== 'undefined' && localStorage.getItem(AUTOSYNC_KEY) === '1';}
export function setAutoSyncEnabled(on: boolean): void { if (typeof localStorage === 'undefined') return; if (on) localStorage.setItem(AUTOSYNC_KEY, '1'); else localStorage.removeItem(AUTOSYNC_KEY);}
// Point the api client at the configured server (boot + after changes).export function applyDeviceServer(): void { const server = deviceServer(); if (!server) return; setApiBase(server.url); setAuthToken(server.token);}