mirror of
https://github.com/SableClient/Sable.git
synced 2026-11-24 02:51:17 -08:00
move SSS to general, add toggle on login and load, remove config option
This commit is contained in:
1 parent
d8938a625d
commit
4e11c125eb
8 files changed
+103
-105
No files matched your search
@@ -16,10 +16,6 @@
|
||||
"themeCatalogBaseUrl": "https://raw.githubusercontent.com/SableClient/themes/main/",
|
||||
"themeCatalogApprovedHostPrefixes": ["https://raw.githubusercontent.com/SableClient/themes/"],
|
||||
|
||||
"slidingSync": {
|
||||
"enabled": true
|
||||
},
|
||||
|
||||
"featuredCommunities": {
|
||||
"openAsDefault": false,
|
||||
"spaces": [
|
||||
|
||||
@@ -7,7 +7,6 @@ import { useSetting } from '$state/hooks/settings';
|
||||
import { SequenceCardStyle } from '$features/common-settings/styles.css';
|
||||
import { SettingTile } from '$components/setting-tile';
|
||||
import { SequenceCard } from '$components/sequence-card';
|
||||
import { Sync } from '../general';
|
||||
import { SettingsSectionPage } from '../SettingsSectionPage';
|
||||
import { BandwidthSavingEmojis } from './BandwithSavingEmojis';
|
||||
import { MSC4268HistoryShare } from './MSC4268HistoryShare';
|
||||
@@ -60,7 +59,6 @@ export function Experimental({ requestBack, requestClose }: Readonly<Experimenta
|
||||
/>
|
||||
<br />
|
||||
<Box direction="Column" gap="700">
|
||||
<Sync />
|
||||
<MSC4268HistoryShare />
|
||||
<BandwidthSavingEmojis />
|
||||
<PersonaToggle />
|
||||
|
||||
@@ -49,8 +49,6 @@ import { useMessageSpacingItems } from '$hooks/useMessageSpacing';
|
||||
import { useDateFormatItems } from '$hooks/useDateFormat';
|
||||
import { SequenceCardStyle } from '$features/settings/styles.css';
|
||||
import { sessionsAtom, activeSessionIdAtom } from '$state/sessions';
|
||||
import { useClientConfig } from '$hooks/useClientConfig';
|
||||
import { resolveSlidingEnabled } from '$client/initMatrix';
|
||||
import { isKeyHotkey } from 'is-hotkey';
|
||||
import { settingsSyncLastSyncedAtom, settingsSyncStatusAtom } from '$hooks/useSettingsSync';
|
||||
import { exportSettingsAsJson, importSettingsFromJson } from '$utils/settingsSync';
|
||||
@@ -1380,14 +1378,17 @@ function Embeds() {
|
||||
);
|
||||
}
|
||||
|
||||
export function Sync() {
|
||||
const clientConfig = useClientConfig();
|
||||
type GeneralProps = {
|
||||
requestBack?: () => void;
|
||||
requestClose: () => void;
|
||||
};
|
||||
|
||||
function Sync() {
|
||||
const sessions = useAtomValue(sessionsAtom);
|
||||
const activeSessionId = useAtomValue(activeSessionIdAtom);
|
||||
const setSessions = useSetAtom(sessionsAtom);
|
||||
const activeSession = sessions.find((s) => s.userId === activeSessionId) ?? sessions[0];
|
||||
|
||||
const serverSlidingEnabled = resolveSlidingEnabled(clientConfig.slidingSync?.enabled);
|
||||
const useSlidingSync = activeSession?.slidingSyncOptIn === true;
|
||||
|
||||
const handleSetSlidingSync = (value: boolean) => {
|
||||
@@ -1402,76 +1403,6 @@ export function Sync() {
|
||||
window.location.reload();
|
||||
};
|
||||
|
||||
return (
|
||||
<Box direction="Column" gap="100">
|
||||
<Text size="L400" style={{ opacity: serverSlidingEnabled ? 1 : 0.5 }}>
|
||||
Sync
|
||||
</Text>
|
||||
<SequenceCard
|
||||
className={SequenceCardStyle}
|
||||
variant="SurfaceVariant"
|
||||
direction="Column"
|
||||
style={{ opacity: serverSlidingEnabled ? 1 : 0.5 }}
|
||||
>
|
||||
<SettingTile
|
||||
title="Use Sliding Sync"
|
||||
focusId="use-sliding-sync"
|
||||
description={
|
||||
serverSlidingEnabled ? (
|
||||
<>
|
||||
Enable Sliding Sync for this current login/session. Requires server support and
|
||||
admin configuration.{' '}
|
||||
<a
|
||||
href="https://github.com/matrix-org/matrix-spec-proposals/blob/erikj/sss/proposals/4186-simplified-sliding-sync.md"
|
||||
target="_blank"
|
||||
rel="noreferrer"
|
||||
>
|
||||
More info/Documentation
|
||||
</a>
|
||||
.{' '}
|
||||
<a
|
||||
href="https://github.com/SableClient/Sable/issues/39"
|
||||
target="_blank"
|
||||
rel="noreferrer"
|
||||
>
|
||||
Known issues (Sable GitHub)
|
||||
</a>
|
||||
.
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
Unavailable: the server has disabled Sliding Sync in its config.{' '}
|
||||
<a
|
||||
href="https://github.com/matrix-org/matrix-spec-proposals/blob/erikj/sss/proposals/4186-simplified-sliding-sync.md"
|
||||
target="_blank"
|
||||
rel="noreferrer"
|
||||
>
|
||||
More info
|
||||
</a>
|
||||
.
|
||||
</>
|
||||
)
|
||||
}
|
||||
after={
|
||||
<Switch
|
||||
variant="Primary"
|
||||
value={useSlidingSync}
|
||||
onChange={handleSetSlidingSync}
|
||||
disabled={!serverSlidingEnabled}
|
||||
/>
|
||||
}
|
||||
/>
|
||||
</SequenceCard>
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
|
||||
type GeneralProps = {
|
||||
requestBack?: () => void;
|
||||
requestClose: () => void;
|
||||
};
|
||||
|
||||
function SettingsSyncSection() {
|
||||
const [syncEnabled, setSyncEnabled] = useSetting(settingsAtom, 'settingsSyncEnabled');
|
||||
const lastSynced = useAtomValue(settingsSyncLastSyncedAtom);
|
||||
const syncStatus = useAtomValue(settingsSyncStatusAtom);
|
||||
@@ -1500,7 +1431,7 @@ function SettingsSyncSection() {
|
||||
|
||||
return (
|
||||
<Box direction="Column" gap="100">
|
||||
<Text size="L400">Settings Sync & Backup</Text>
|
||||
<Text size="L400">Data Syncing</Text>
|
||||
<SequenceCard
|
||||
className={SequenceCardStyle}
|
||||
variant="SurfaceVariant"
|
||||
@@ -1508,7 +1439,34 @@ function SettingsSyncSection() {
|
||||
gap="400"
|
||||
>
|
||||
<SettingTile
|
||||
title="Sync across devices"
|
||||
title="Use Sliding Sync"
|
||||
focusId="use-sliding-sync"
|
||||
description={
|
||||
<>
|
||||
Enable Sliding Sync for this current login/session. Requires server support.{' '}
|
||||
<a
|
||||
href="https://github.com/SableClient/Sable/issues/39"
|
||||
target="_blank"
|
||||
rel="noreferrer"
|
||||
>
|
||||
Known issues (Sable GitHub)
|
||||
</a>
|
||||
.
|
||||
</>
|
||||
}
|
||||
after={
|
||||
<Switch variant="Primary" value={useSlidingSync} onChange={handleSetSlidingSync} />
|
||||
}
|
||||
/>
|
||||
</SequenceCard>
|
||||
<SequenceCard
|
||||
className={SequenceCardStyle}
|
||||
variant="SurfaceVariant"
|
||||
direction="Column"
|
||||
gap="400"
|
||||
>
|
||||
<SettingTile
|
||||
title="Sync settings across devices"
|
||||
focusId="sync-across-devices"
|
||||
description="Store your settings in your Matrix account so they follow you to any Sable instance. Notification and zoom preferences are kept per-device."
|
||||
after={<Switch variant="Primary" value={syncEnabled} onChange={setSyncEnabled} />}
|
||||
@@ -1669,7 +1627,7 @@ export function General({ requestBack, requestClose }: Readonly<GeneralProps>) {
|
||||
<Messages />
|
||||
<Embeds />
|
||||
<Calls />
|
||||
<SettingsSyncSection />
|
||||
<Sync />
|
||||
<DiagnosticsAndPrivacy />
|
||||
</Box>
|
||||
</PageContent>
|
||||
|
||||
@@ -28,7 +28,6 @@ export type ClientConfig = {
|
||||
};
|
||||
|
||||
slidingSync?: {
|
||||
enabled?: boolean;
|
||||
proxyBaseUrl?: string;
|
||||
bootstrapClassicOnColdCache?: boolean;
|
||||
listPageSize?: number;
|
||||
|
||||
@@ -13,6 +13,7 @@ import {
|
||||
OverlayCenter,
|
||||
PopOut,
|
||||
Spinner,
|
||||
Switch,
|
||||
Text,
|
||||
config,
|
||||
} from 'folds';
|
||||
@@ -120,7 +121,12 @@ export function PasswordLoginForm({ defaultUsername, defaultEmail }: PasswordLog
|
||||
Parameters<typeof login>
|
||||
>(useCallback(login, []));
|
||||
|
||||
useLoginComplete(loginState.status === AsyncStatus.Success ? loginState.data : undefined);
|
||||
const [useSlidingSync, setUseSlidingSync] = useState(false);
|
||||
|
||||
useLoginComplete(
|
||||
loginState.status === AsyncStatus.Success ? loginState.data : undefined,
|
||||
useSlidingSync
|
||||
);
|
||||
|
||||
const handleUsernameLogin = (username: string, password: string) => {
|
||||
startLogin(baseUrl, {
|
||||
@@ -265,6 +271,18 @@ export function PasswordLoginForm({ defaultUsername, defaultEmail }: PasswordLog
|
||||
</Box>
|
||||
</Box>
|
||||
</Box>
|
||||
<Box alignItems="Center" gap="200">
|
||||
<Switch
|
||||
variant="Primary"
|
||||
value={useSlidingSync}
|
||||
onChange={setUseSlidingSync}
|
||||
id="login-sliding-sync"
|
||||
/>
|
||||
<Text as="label" htmlFor="login-sliding-sync" size="T300" priority="300">
|
||||
Use sliding sync (faster, but buggier)
|
||||
</Text>
|
||||
</Box>
|
||||
|
||||
<Button type="submit" variant="Primary" size="500">
|
||||
<Text as="span" size="B500">
|
||||
Login
|
||||
|
||||
@@ -12,7 +12,7 @@ import {
|
||||
getAfterLoginRedirectPath,
|
||||
} from '$pages/afterLoginRedirectPath';
|
||||
import { getHomePath } from '$pages/pathUtils';
|
||||
import { activeSessionIdAtom, sessionsAtom } from '$state/sessions';
|
||||
import { activeSessionIdAtom, sessionsAtom, type Session } from '$state/sessions';
|
||||
import { createLogger } from '$utils/debug';
|
||||
import { createDebugLogger } from '$utils/debugLogger';
|
||||
import { ErrorCode } from '../../../cs-errorcode';
|
||||
@@ -145,7 +145,7 @@ export const login = async (
|
||||
);
|
||||
};
|
||||
|
||||
export const useLoginComplete = (data?: CustomLoginResponse) => {
|
||||
export const useLoginComplete = (data?: CustomLoginResponse, slidingSyncOptIn?: boolean) => {
|
||||
const navigate = useNavigate();
|
||||
const setSessions = useSetAtom(sessionsAtom);
|
||||
const setActiveSessionId = useSetAtom(activeSessionIdAtom);
|
||||
@@ -157,12 +157,15 @@ export const useLoginComplete = (data?: CustomLoginResponse) => {
|
||||
userId: loginRes.user_id,
|
||||
baseUrl: loginBaseUrl,
|
||||
});
|
||||
const newSession = {
|
||||
const newSession: Session = {
|
||||
baseUrl: loginBaseUrl,
|
||||
userId: loginRes.user_id,
|
||||
deviceId: loginRes.device_id,
|
||||
accessToken: loginRes.access_token,
|
||||
};
|
||||
if (slidingSyncOptIn !== undefined) {
|
||||
newSession.slidingSyncOptIn = slidingSyncOptIn;
|
||||
}
|
||||
setSessions({ type: 'PUT', session: newSession });
|
||||
setActiveSessionId(loginRes.user_id);
|
||||
const afterLoginRedirectUrl = getAfterLoginRedirectPath();
|
||||
@@ -171,5 +174,5 @@ export const useLoginComplete = (data?: CustomLoginResponse) => {
|
||||
log.log('useLoginComplete: navigating to', destination);
|
||||
navigate(destination, { replace: true });
|
||||
}
|
||||
}, [data, navigate, setSessions, setActiveSessionId]);
|
||||
}, [data, slidingSyncOptIn, navigate, setSessions, setActiveSessionId]);
|
||||
};
|
||||
@@ -60,11 +60,51 @@ const isClientReady = (syncState: string | null): boolean =>
|
||||
syncState === 'PREPARED' || syncState === 'SYNCING' || syncState === 'CATCHUP';
|
||||
|
||||
function ClientRootLoading() {
|
||||
const sessions = useAtomValue(sessionsAtom);
|
||||
const activeSessionId = useAtomValue(activeSessionIdAtom);
|
||||
const setSessions = useSetAtom(sessionsAtom);
|
||||
|
||||
const activeSession: Session | undefined =
|
||||
sessions.find((s) => s.userId === activeSessionId) ?? sessions[0];
|
||||
|
||||
const usingSlidingSync = activeSession?.slidingSyncOptIn === true;
|
||||
|
||||
const handleSwap = () => {
|
||||
if (!activeSession) return;
|
||||
setSessions({
|
||||
type: 'PUT',
|
||||
session: {
|
||||
...activeSession,
|
||||
slidingSyncOptIn: !usingSlidingSync,
|
||||
},
|
||||
});
|
||||
window.location.reload();
|
||||
};
|
||||
|
||||
return (
|
||||
<SplashScreen>
|
||||
<Box direction="Column" grow="Yes" alignItems="Center" justifyContent="Center" gap="400">
|
||||
<Spinner variant="Secondary" size="600" />
|
||||
<Text>Petting cats</Text>
|
||||
{activeSession && (
|
||||
<Text
|
||||
as="button"
|
||||
type="button"
|
||||
onClick={handleSwap}
|
||||
size="T200"
|
||||
style={{
|
||||
background: 'none',
|
||||
border: 'none',
|
||||
padding: 0,
|
||||
color: 'inherit',
|
||||
cursor: 'pointer',
|
||||
opacity: 0.7,
|
||||
textDecoration: 'underline',
|
||||
}}
|
||||
>
|
||||
{usingSlidingSync ? 'Swap to classic sync' : 'Swap to sliding sync'}
|
||||
</Text>
|
||||
)}
|
||||
</Box>
|
||||
</SplashScreen>
|
||||
);
|
||||
|
||||
@@ -97,17 +97,6 @@ function installStartupFetchRoomEventPatch(
|
||||
fetchRoomEventStartupCleanupByClient.set(mx, restore);
|
||||
}
|
||||
|
||||
export const resolveSlidingEnabled = (enabled: SlidingSyncConfig['enabled']): boolean => {
|
||||
if (enabled === undefined) return false;
|
||||
if (typeof enabled === 'boolean') return enabled;
|
||||
const normalized = String(enabled).trim().toLowerCase();
|
||||
if (normalized === 'false' || normalized === '0' || normalized === 'off' || normalized === 'no')
|
||||
return false;
|
||||
if (normalized === 'true' || normalized === '1' || normalized === 'on' || normalized === 'yes')
|
||||
return true;
|
||||
return false;
|
||||
};
|
||||
|
||||
const deleteDatabase = (name: string): Promise<void> =>
|
||||
new Promise((resolve) => {
|
||||
const req = window.indexedDB.deleteDatabase(name);
|
||||
@@ -405,10 +394,7 @@ export const startClient = async (mx: MatrixClient, config?: StartClientConfig):
|
||||
|
||||
const slidingConfig = config?.slidingSync;
|
||||
const proxyBaseUrl = slidingConfig?.proxyBaseUrl ?? config?.baseUrl ?? mx.baseUrl;
|
||||
const useSliding =
|
||||
config?.sessionSlidingSyncOptIn === true &&
|
||||
!!slidingConfig &&
|
||||
resolveSlidingEnabled(slidingConfig?.enabled);
|
||||
const useSliding = config?.sessionSlidingSyncOptIn === true && !!slidingConfig;
|
||||
|
||||
const presenceManager = new PresenceSyncManager(mx);
|
||||
presenceSyncByClient.set(mx, presenceManager);
|
||||
|
||||
Reference in new issue
Block a user