refactor: environment setup (#2898)

Co-authored-by: Simon He <57086651+Simon-He95@users.noreply.github.com>
This commit is contained in:
Alex Yang
2023-06-28 19:19:19 +08:00
committed by GitHub
parent 80c2a78273
commit 5496969e58
72 changed files with 255 additions and 242 deletions

View File

@@ -1,4 +1,4 @@
import { env } from '@affine/env/config';
import { isBrowser } from '@affine/env/constant';
import { atomWithObservable, atomWithStorage } from 'jotai/utils';
import { Observable } from 'rxjs';
@@ -22,7 +22,7 @@ function rpcToObservable<
return new Observable<T>(subscriber => {
subscriber.next(initialValue);
onSubscribe?.();
if (typeof window === 'undefined' || !env.isDesktop || !event) {
if (!isBrowser || !environment.isDesktop || !event) {
subscriber.complete();
return;
}

View File

@@ -1,5 +1,4 @@
import { config } from '@affine/env/config';
import { Unreachable } from '@affine/env/constant';
import { isBrowser, Unreachable } from '@affine/env/constant';
import { useAFFiNEI18N } from '@affine/i18n/hooks';
import { CloseIcon, NewIcon, ResetIcon } from '@blocksuite/icons';
import clsx from 'clsx';
@@ -20,7 +19,7 @@ interface AddPageButtonProps {
}
const currentVersionAtom = atom(async () => {
if (typeof window === 'undefined') {
if (!isBrowser) {
return null;
}
const currentVersion = await window.apis?.updater.currentVersion();
@@ -28,7 +27,7 @@ const currentVersionAtom = atom(async () => {
});
const currentChangelogUnreadAtom = atom(async get => {
if (typeof window === 'undefined') {
if (!isBrowser) {
return false;
}
const mapping = get(changelogCheckedAtom);
@@ -79,7 +78,7 @@ export function AppUpdaterButton({ className, style }: AddPageButtonProps) {
);
}
} else if (currentChangelogUnread) {
window.open(config.changelogUrl, '_blank');
window.open(runtimeConfig.changelogUrl, '_blank');
onDismissCurrentChangelog();
} else {
throw new Unreachable();