style: enable rxjs/finnish (#6276)

chore(infra): use finnish notation for observables

do rename
This commit is contained in:
EYHN
2024-03-24 17:04:51 +00:00
parent c6676fd074
commit 2b42a75e5a
104 changed files with 797 additions and 591 deletions

View File

@@ -38,9 +38,9 @@ export const db$Map = new Map<string, Observable<WorkspaceSQLiteDB>>();
const beforeQuit$ = defer(() => fromEvent(process, 'beforeExit'));
// return a stream that emit a single event when the subject completes
function completed<T>(subject: Subject<T>) {
function completed<T>(subject$: Subject<T>) {
return new Observable(subscriber => {
const sub = subject.subscribe({
const sub = subject$.subscribe({
complete: () => {
subscriber.next();
subscriber.complete();
@@ -50,7 +50,7 @@ function completed<T>(subject: Subject<T>) {
});
}
function getWorkspaceDB$(id: string) {
function getWorkspaceDB(id: string) {
if (!db$Map.has(id)) {
db$Map.set(
id,
@@ -103,7 +103,7 @@ function getWorkspaceDB$(id: string) {
function startPollingSecondaryDB(db: WorkspaceSQLiteDB) {
return merge(
getWorkspaceMeta(db.workspaceId),
workspaceSubjects.meta.pipe(
workspaceSubjects.meta$.pipe(
map(({ meta }) => meta),
filter(meta => meta.id === db.workspaceId)
)
@@ -141,5 +141,5 @@ function startPollingSecondaryDB(db: WorkspaceSQLiteDB) {
}
export function ensureSQLiteDB(id: string) {
return lastValueFrom(getWorkspaceDB$(id).pipe(take(1)));
return lastValueFrom(getWorkspaceDB(id).pipe(take(1)));
}

View File

@@ -48,7 +48,7 @@ export const dbEvents = {
docId?: string;
}) => void
) => {
const sub = dbSubjects.externalUpdate.subscribe(fn);
const sub = dbSubjects.externalUpdate$.subscribe(fn);
return () => {
sub.unsubscribe();
};

View File

@@ -1,7 +1,7 @@
import { Subject } from 'rxjs';
export const dbSubjects = {
externalUpdate: new Subject<{
externalUpdate$: new Subject<{
workspaceId: string;
update: Uint8Array;
docId?: string;

View File

@@ -66,7 +66,7 @@ export class WorkspaceSQLiteDB extends BaseSQLiteAdapter {
if (origin === 'renderer') {
await this.addUpdateToSQLite(insertRows);
} else if (origin === 'external') {
dbSubjects.externalUpdate.next({
dbSubjects.externalUpdate$.next({
workspaceId: this.workspaceId,
update,
docId,

View File

@@ -97,7 +97,7 @@ export async function storeWorkspaceMeta(
...meta,
};
await fs.writeJSON(metaPath, newMeta);
workspaceSubjects.meta.next({
workspaceSubjects.meta$.next({
workspaceId,
meta: newMeta,
});

View File

@@ -10,7 +10,7 @@ export const workspaceEvents = {
onMetaChange: (
fn: (meta: { workspaceId: string; meta: WorkspaceMeta }) => void
) => {
const sub = workspaceSubjects.meta.subscribe(fn);
const sub = workspaceSubjects.meta$.subscribe(fn);
return () => {
sub.unsubscribe();
};

View File

@@ -3,5 +3,5 @@ import { Subject } from 'rxjs';
import type { WorkspaceMeta } from '../type';
export const workspaceSubjects = {
meta: new Subject<{ workspaceId: string; meta: WorkspaceMeta }>(),
meta$: new Subject<{ workspaceId: string; meta: WorkspaceMeta }>(),
};

View File

@@ -26,7 +26,7 @@ export function createApplicationMenu() {
label: `About ${app.getName()}`,
click: async () => {
await showMainWindow();
applicationMenuSubjects.openAboutPageInSettingModal.next();
applicationMenuSubjects.openAboutPageInSettingModal$.next();
},
},
{ type: 'separator' },
@@ -52,7 +52,7 @@ export function createApplicationMenu() {
click: async () => {
await initAndShowMainWindow();
// fixme: if the window is just created, the new page action will not be triggered
applicationMenuSubjects.newPageAction.next();
applicationMenuSubjects.newPageAction$.next();
},
},
{ type: 'separator' },

View File

@@ -12,14 +12,14 @@ export const applicationMenuEvents = {
* File -> New Doc
*/
onNewPageAction: (fn: () => void) => {
const sub = applicationMenuSubjects.newPageAction.subscribe(fn);
const sub = applicationMenuSubjects.newPageAction$.subscribe(fn);
return () => {
sub.unsubscribe();
};
},
openAboutPageInSettingModal: (fn: () => void) => {
const sub =
applicationMenuSubjects.openAboutPageInSettingModal.subscribe(fn);
applicationMenuSubjects.openAboutPageInSettingModal$.subscribe(fn);
return () => {
sub.unsubscribe();
};

View File

@@ -1,6 +1,6 @@
import { Subject } from 'rxjs';
export const applicationMenuSubjects = {
newPageAction: new Subject<void>(),
openAboutPageInSettingModal: new Subject<void>(),
newPageAction$: new Subject<void>(),
openAboutPageInSettingModal$: new Subject<void>(),
};

View File

@@ -104,7 +104,7 @@ async function createWindow(additionalArguments: string[]) {
logger.info('main window is ready to show');
if (browserWindow.isMaximized() || browserWindow.isFullScreen()) {
uiSubjects.onMaximized.next(true);
uiSubjects.onMaximized$.next(true);
}
handleWebContentsResize().catch(logger.error);
@@ -141,20 +141,20 @@ async function createWindow(additionalArguments: string[]) {
browserWindow.setSize(size[0] + 1, size[1] + 1);
browserWindow.setSize(size[0], size[1]);
});
uiSubjects.onMaximized.next(false);
uiSubjects.onMaximized$.next(false);
});
browserWindow.on('maximize', () => {
uiSubjects.onMaximized.next(true);
uiSubjects.onMaximized$.next(true);
});
// full-screen == maximized in UI on windows
browserWindow.on('enter-full-screen', () => {
uiSubjects.onMaximized.next(true);
uiSubjects.onMaximized$.next(true);
});
browserWindow.on('unmaximize', () => {
uiSubjects.onMaximized.next(false);
uiSubjects.onMaximized$.next(false);
});
/**
@@ -172,7 +172,7 @@ async function createWindow(additionalArguments: string[]) {
}
// singleton
let browserWindow$: Promise<BrowserWindow> | undefined;
let browserWindow: Promise<BrowserWindow> | undefined;
// a hidden window that prevents the app from quitting on MacOS
let hiddenMacWindow: BrowserWindow | undefined;
@@ -181,11 +181,11 @@ let hiddenMacWindow: BrowserWindow | undefined;
* Init main BrowserWindow. Will create a new window if it's not created yet.
*/
export async function initAndShowMainWindow() {
if (!browserWindow$ || (await browserWindow$.then(w => w.isDestroyed()))) {
if (!browserWindow || (await browserWindow.then(w => w.isDestroyed()))) {
const additionalArguments = await getWindowAdditionalArguments();
browserWindow$ = createWindow(additionalArguments);
browserWindow = createWindow(additionalArguments);
}
const mainWindow = await browserWindow$;
const mainWindow = await browserWindow;
if (IS_DEV) {
// do not gain focus in dev mode
@@ -209,8 +209,8 @@ export async function initAndShowMainWindow() {
}
export async function getMainWindow() {
if (!browserWindow$) return;
const window = await browserWindow$;
if (!browserWindow) return;
const window = await browserWindow;
if (window.isDestroyed()) return;
return window;
}
@@ -251,7 +251,7 @@ export async function setCookie(
arg0: CookiesSetDetails | string,
arg1?: string
) {
const window = await browserWindow$;
const window = await browserWindow;
if (!window) {
// do nothing if window is not ready
return;
@@ -271,7 +271,7 @@ export async function setCookie(
}
export async function removeCookie(url: string, name: string): Promise<void> {
const window = await browserWindow$;
const window = await browserWindow;
if (!window) {
// do nothing if window is not ready
return;
@@ -280,7 +280,7 @@ export async function removeCookie(url: string, name: string): Promise<void> {
}
export async function getCookie(url?: string, name?: string) {
const window = await browserWindow$;
const window = await browserWindow;
if (!window) {
// do nothing if window is not ready
return;

View File

@@ -96,23 +96,23 @@ async function createOnboardingWindow(additionalArguments: string[]) {
return browserWindow;
}
let onBoardingWindow$: Promise<BrowserWindow> | undefined;
let onBoardingWindow: Promise<BrowserWindow> | undefined;
export async function getOrCreateOnboardingWindow() {
const additionalArguments = await getWindowAdditionalArguments();
if (
!onBoardingWindow$ ||
(await onBoardingWindow$.then(w => w.isDestroyed()))
!onBoardingWindow ||
(await onBoardingWindow.then(w => w.isDestroyed()))
) {
onBoardingWindow$ = createOnboardingWindow(additionalArguments);
onBoardingWindow = createOnboardingWindow(additionalArguments);
}
return onBoardingWindow$;
return onBoardingWindow;
}
export async function getOnboardingWindow() {
if (!onBoardingWindow$) return;
const window = await onBoardingWindow$;
if (!onBoardingWindow) return;
const window = await onBoardingWindow;
if (window.isDestroyed()) return;
return window;
}

View File

@@ -6,7 +6,7 @@ import { uiSubjects } from './subject';
*/
export const uiEvents = {
onMaximized: (fn: (maximized: boolean) => void) => {
const sub = uiSubjects.onMaximized.subscribe(fn);
const sub = uiSubjects.onMaximized$.subscribe(fn);
return () => {
sub.unsubscribe();
};

View File

@@ -1,5 +1,5 @@
import { Subject } from 'rxjs';
export const uiSubjects = {
onMaximized: new Subject<boolean>(),
onMaximized$: new Subject<boolean>(),
};

View File

@@ -67,7 +67,7 @@ export const downloadUpdate = async () => {
return;
}
downloading = true;
updaterSubjects.downloadProgress.next(0);
updaterSubjects.downloadProgress$.next(0);
autoUpdater.downloadUpdate().catch(e => {
downloading = false;
logger.error('Failed to download update', e);
@@ -115,7 +115,7 @@ export const registerUpdater = async () => {
console.error(err);
});
}
updaterSubjects.updateAvailable.next({
updaterSubjects.updateAvailable$.next({
version: info.version,
allowAutoUpdate,
});
@@ -125,11 +125,11 @@ export const registerUpdater = async () => {
});
autoUpdater.on('download-progress', e => {
logger.info(`Download progress: ${e.percent}`);
updaterSubjects.downloadProgress.next(e.percent);
updaterSubjects.downloadProgress$.next(e.percent);
});
autoUpdater.on('update-downloaded', e => {
downloading = false;
updaterSubjects.updateReady.next({
updaterSubjects.updateReady$.next({
version: e.version,
allowAutoUpdate,
});

View File

@@ -9,26 +9,26 @@ export interface UpdateMeta {
export const updaterSubjects = {
// means it is ready for restart and install the new version
updateAvailable: new Subject<UpdateMeta>(),
updateReady: new Subject<UpdateMeta>(),
downloadProgress: new BehaviorSubject<number>(0),
updateAvailable$: new Subject<UpdateMeta>(),
updateReady$: new Subject<UpdateMeta>(),
downloadProgress$: new BehaviorSubject<number>(0),
};
export const updaterEvents = {
onUpdateAvailable: (fn: (versionMeta: UpdateMeta) => void) => {
const sub = updaterSubjects.updateAvailable.subscribe(fn);
const sub = updaterSubjects.updateAvailable$.subscribe(fn);
return () => {
sub.unsubscribe();
};
},
onUpdateReady: (fn: (versionMeta: UpdateMeta) => void) => {
const sub = updaterSubjects.updateReady.subscribe(fn);
const sub = updaterSubjects.updateReady$.subscribe(fn);
return () => {
sub.unsubscribe();
};
},
onDownloadProgress: (fn: (progress: number) => void) => {
const sub = updaterSubjects.downloadProgress.subscribe(fn);
const sub = updaterSubjects.downloadProgress$.subscribe(fn);
return () => {
sub.unsubscribe();
};

View File

@@ -1,9 +0,0 @@
import type { BrowserWindow } from 'electron';
import type { LaunchStage } from './types';
export const windows$: Record<LaunchStage, Promise<BrowserWindow> | undefined> =
{
main: undefined,
onboarding: undefined,
};

View File

@@ -141,7 +141,7 @@ function getMainAPIs() {
return { apis, events };
}
const helperPort$ = new Promise<MessagePort>(resolve =>
const helperPort = new Promise<MessagePort>(resolve =>
ipcRenderer.on('helper-connection', e => {
console.info('[preload] helper-connection', e);
resolve(e.ports[0]);
@@ -183,7 +183,7 @@ function getHelperAPIs() {
};
const rpc = AsyncCall<HelperToRenderer>(rendererToHelperServer, {
channel: helperPort$.then(helperPort =>
channel: helperPort.then(helperPort =>
createMessagePortChannel(helperPort)
),
log: false,