Files
AFFiNE-Mirror/packages/component/src/components/app-sidebar/index.jotai.ts
2023-05-14 21:58:13 -07:00

35 lines
1014 B
TypeScript

import { atom } from 'jotai';
import { atomWithObservable } from 'jotai/utils';
import { atomWithStorage } from 'jotai/utils';
import { Observable } from 'rxjs';
export const APP_SIDEBAR_OPEN = 'app-sidebar-open';
export const appSidebarOpenAtom = atomWithStorage(
APP_SIDEBAR_OPEN,
undefined as boolean | undefined
);
export const appSidebarFloatingAtom = atom(false);
export const appSidebarResizingAtom = atom(false);
export const appSidebarWidthAtom = atomWithStorage(
'app-sidebar-width',
256 /* px */
);
export const updateAvailableAtom = atomWithObservable<boolean>(() => {
return new Observable<boolean>(subscriber => {
subscriber.next(false);
if (typeof window !== 'undefined') {
const isMacosDesktop = environment.isDesktop && environment.isMacOs;
if (isMacosDesktop) {
const dispose = window.events?.updater.onClientUpdateReady(() => {
subscriber.next(true);
});
return () => {
dispose?.();
};
}
}
});
});