mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-21 16:26:58 +08:00
feat: add new rule for floating promise (#2726)
Co-authored-by: Himself65 <himself65@outlook.com>
(cherry picked from commit bedf838fe5)
This commit is contained in:
@@ -119,7 +119,7 @@ export function createApplicationMenu() {
|
||||
{
|
||||
label: 'Open log file',
|
||||
click: async () => {
|
||||
revealLogFile();
|
||||
await revealLogFile();
|
||||
},
|
||||
},
|
||||
{
|
||||
|
||||
@@ -62,7 +62,7 @@ test('on applyUpdate (from renderer), will trigger update', async () => {
|
||||
db.update$.subscribe(onUpdate);
|
||||
const sub = dbSubjects.externalUpdate.subscribe(onExternalUpdate);
|
||||
db.applyUpdate(getTestUpdates(), 'renderer');
|
||||
expect(onUpdate).toHaveBeenCalled(); // not yet updated
|
||||
expect(onUpdate).toHaveBeenCalled();
|
||||
sub.unsubscribe();
|
||||
await db.destroy();
|
||||
});
|
||||
|
||||
@@ -11,6 +11,7 @@ import {
|
||||
merge,
|
||||
} from 'rxjs';
|
||||
import {
|
||||
concatMap,
|
||||
distinctUntilChanged,
|
||||
filter,
|
||||
ignoreElements,
|
||||
@@ -126,10 +127,8 @@ function startPollingSecondaryDB(db: WorkspaceSQLiteDB) {
|
||||
switchMap(secondaryDB => {
|
||||
return interval(300000).pipe(
|
||||
startWith(0),
|
||||
concatMap(() => secondaryDB.pull()),
|
||||
tap({
|
||||
next: () => {
|
||||
secondaryDB.pull();
|
||||
},
|
||||
error: err => {
|
||||
logger.error(`[ensureSQLiteDB] polling secondary db error`, err);
|
||||
},
|
||||
|
||||
@@ -93,6 +93,7 @@ export class SecondaryWorkspaceSQLiteDB extends BaseSQLiteAdapter {
|
||||
return await fn();
|
||||
} catch (err) {
|
||||
logger.error(err);
|
||||
throw err;
|
||||
} finally {
|
||||
this.runCounter--;
|
||||
if (this.runCounter === 0) {
|
||||
@@ -115,10 +116,10 @@ export class SecondaryWorkspaceSQLiteDB extends BaseSQLiteAdapter {
|
||||
}
|
||||
};
|
||||
|
||||
const onSelfUpdate = (update: Uint8Array, origin: YOrigin) => {
|
||||
const onSelfUpdate = async (update: Uint8Array, origin: YOrigin) => {
|
||||
// for self update from upstream, we need to push it to external DB
|
||||
if (origin === 'upstream' && this.db) {
|
||||
this.addUpdateToUpdateQueue(this.db, update);
|
||||
await this.addUpdateToUpdateQueue(this.db, update);
|
||||
}
|
||||
|
||||
if (origin === 'self') {
|
||||
@@ -135,12 +136,18 @@ export class SecondaryWorkspaceSQLiteDB extends BaseSQLiteAdapter {
|
||||
this.yDoc.off('update', onSelfUpdate);
|
||||
});
|
||||
|
||||
this.run(async () => {
|
||||
this.run(() => {
|
||||
// apply all updates from upstream
|
||||
const upstreamUpdate = this.upstream.getDocAsUpdates();
|
||||
// to initialize the yDoc, we need to apply all updates from the db
|
||||
this.applyUpdate(upstreamUpdate, 'upstream');
|
||||
});
|
||||
})
|
||||
.then(() => {
|
||||
logger.debug('run success');
|
||||
})
|
||||
.catch(err => {
|
||||
logger.error('run error', err);
|
||||
});
|
||||
}
|
||||
|
||||
applyUpdate = (data: Uint8Array, origin: YOrigin = 'upstream') => {
|
||||
|
||||
@@ -79,19 +79,19 @@ export class WorkspaceSQLiteDB extends BaseSQLiteAdapter {
|
||||
};
|
||||
|
||||
override async addBlob(key: string, value: Uint8Array) {
|
||||
const res = await super.addBlob(key, value);
|
||||
this.update$.next();
|
||||
const res = await super.addBlob(key, value);
|
||||
return res;
|
||||
}
|
||||
|
||||
override async deleteBlob(key: string) {
|
||||
super.deleteBlob(key);
|
||||
this.update$.next();
|
||||
await super.deleteBlob(key);
|
||||
}
|
||||
|
||||
override async addUpdateToSQLite(db: SqliteConnection, data: Uint8Array[]) {
|
||||
super.addUpdateToSQLite(db, data);
|
||||
this.update$.next();
|
||||
await super.addUpdateToSQLite(db, data);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -320,7 +320,7 @@ export async function moveDBFile(
|
||||
filePath: newFilePath,
|
||||
};
|
||||
} catch (err) {
|
||||
db?.destroy();
|
||||
await db?.destroy();
|
||||
logger.error('[moveDBFile]', err);
|
||||
return {
|
||||
error: 'UNKNOWN_ERROR',
|
||||
|
||||
@@ -50,7 +50,7 @@ export async function savePDFFileAs(
|
||||
});
|
||||
});
|
||||
|
||||
shell.openPath(filePath);
|
||||
await shell.openPath(filePath);
|
||||
return { filePath };
|
||||
} catch (err) {
|
||||
logger.error('savePDFFileAs', err);
|
||||
|
||||
@@ -29,7 +29,9 @@ if (!isSingleInstance) {
|
||||
}
|
||||
|
||||
app.on('second-instance', () => {
|
||||
restoreOrCreateWindow();
|
||||
restoreOrCreateWindow().catch(e =>
|
||||
console.error('Failed to restore or create window:', e)
|
||||
);
|
||||
});
|
||||
|
||||
app.on('open-url', async (_, _url) => {
|
||||
|
||||
@@ -28,10 +28,12 @@ export const getExchangeTokenParams = (code: string) => {
|
||||
};
|
||||
|
||||
export function getGoogleOauthCode() {
|
||||
shell.openExternal(oauthEndpoint);
|
||||
|
||||
return new Promise<ReturnType<typeof getExchangeTokenParams>>(
|
||||
(resolve, reject) => {
|
||||
shell.openExternal(oauthEndpoint).catch(e => {
|
||||
logger.error('Failed to open external url', e);
|
||||
reject(e);
|
||||
});
|
||||
const handleOpenUrl = async (_: any, url: string) => {
|
||||
const mainWindow = BrowserWindow.getAllWindows().find(
|
||||
w => !w.isDestroyed()
|
||||
|
||||
@@ -67,7 +67,9 @@ export const registerUpdater = async () => {
|
||||
// register events for checkForUpdatesAndNotify
|
||||
_autoUpdater.on('update-available', info => {
|
||||
if (allowAutoUpdate) {
|
||||
_autoUpdater?.downloadUpdate();
|
||||
_autoUpdater?.downloadUpdate().catch(e => {
|
||||
logger.error('Failed to download update', e);
|
||||
});
|
||||
logger.info('Update available, downloading...', info);
|
||||
}
|
||||
updaterSubjects.updateAvailable.next({
|
||||
|
||||
@@ -46,7 +46,9 @@ export const LocalAdapter: WorkspaceAdapter<WorkspaceFlavour.LOCAL> = {
|
||||
});
|
||||
setEditorFlags(blockSuiteWorkspace);
|
||||
if (config.enablePreloading) {
|
||||
initPageWithPreloading(page);
|
||||
initPageWithPreloading(page).catch(err => {
|
||||
logger.error('init page with preloading failed', err);
|
||||
});
|
||||
} else {
|
||||
initEmptyPage(page);
|
||||
}
|
||||
|
||||
@@ -67,7 +67,7 @@ export class AffineErrorBoundary extends Component<
|
||||
pageId: error.workspace.meta.pageMetas[0].id,
|
||||
},
|
||||
})
|
||||
.then(() => {
|
||||
.finally(() => {
|
||||
this.setState({ error: null });
|
||||
});
|
||||
}}
|
||||
|
||||
@@ -95,7 +95,7 @@ export const WorkspaceSettingDetail: React.FC<
|
||||
const workspaceId = workspace.id;
|
||||
useEffect(() => {
|
||||
if (isAffine && isOwner) {
|
||||
preload([QueryKey.getMembers, workspaceId], fetcher);
|
||||
preload([QueryKey.getMembers, workspaceId], fetcher).catch(console.error);
|
||||
}
|
||||
}, [isAffine, isOwner, workspaceId]);
|
||||
const containerRef = useRef<HTMLDivElement | null>(null);
|
||||
|
||||
@@ -46,8 +46,8 @@ const PublishPanelAffine: React.FC<PublishPanelAffineProps> = ({
|
||||
const shareUrl = origin + '/public-workspace/' + workspace.id;
|
||||
const t = useAFFiNEI18N();
|
||||
const publishWorkspace = useToggleWorkspacePublish(workspace);
|
||||
const copyUrl = useCallback(() => {
|
||||
navigator.clipboard.writeText(shareUrl);
|
||||
const copyUrl = useCallback(async () => {
|
||||
await navigator.clipboard.writeText(shareUrl);
|
||||
toast(t['Copied link to clipboard']());
|
||||
}, [shareUrl, t]);
|
||||
|
||||
|
||||
@@ -16,12 +16,12 @@ export const usePageHelper = (blockSuiteWorkspace: BlockSuiteWorkspace) => {
|
||||
|
||||
const createPageAndOpen = () => {
|
||||
const page = createPage();
|
||||
openPage(blockSuiteWorkspace.id, page.id);
|
||||
return openPage(blockSuiteWorkspace.id, page.id);
|
||||
};
|
||||
const createEdgelessAndOpen = () => {
|
||||
const page = createPage();
|
||||
setPreferredMode(page.id, 'edgeless');
|
||||
openPage(blockSuiteWorkspace.id, page.id);
|
||||
return openPage(blockSuiteWorkspace.id, page.id);
|
||||
};
|
||||
const importFileAndOpen = async () => {
|
||||
const { showImportModal } = await import('@blocksuite/blocks');
|
||||
|
||||
@@ -10,7 +10,9 @@ export const EditPage = () => {
|
||||
const { jumpToPage } = useRouterHelper(router);
|
||||
const onClickPage = useCallback(() => {
|
||||
if (workspaceId && pageId) {
|
||||
jumpToPage(workspaceId, pageId);
|
||||
jumpToPage(workspaceId, pageId).catch(error => {
|
||||
console.error(error);
|
||||
});
|
||||
}
|
||||
}, [jumpToPage, pageId, workspaceId]);
|
||||
return (
|
||||
|
||||
@@ -9,7 +9,7 @@ const LanguageMenuContent: FC = () => {
|
||||
const i18n = useI18N();
|
||||
const changeLanguage = useCallback(
|
||||
(event: string) => {
|
||||
i18n.changeLanguage(event);
|
||||
void i18n.changeLanguage(event);
|
||||
},
|
||||
[i18n]
|
||||
);
|
||||
|
||||
@@ -96,8 +96,8 @@ const LocalHeaderShareMenu: React.FC<BaseHeaderProps> = props => {
|
||||
onClose={() => {
|
||||
setOpen(false);
|
||||
}}
|
||||
onConform={() => {
|
||||
onTransformWorkspace(
|
||||
onConform={async () => {
|
||||
await onTransformWorkspace(
|
||||
WorkspaceFlavour.LOCAL,
|
||||
WorkspaceFlavour.AFFINE,
|
||||
props.workspace as LocalWorkspace
|
||||
|
||||
@@ -138,17 +138,14 @@ export const SyncUser = () => {
|
||||
workspace as LocalWorkspace
|
||||
);
|
||||
// fixme(himself65): refactor this
|
||||
router
|
||||
.replace({
|
||||
pathname: `/workspace/[workspaceId]/all`,
|
||||
query: {
|
||||
workspaceId: id,
|
||||
},
|
||||
})
|
||||
.then(() => {
|
||||
router.reload();
|
||||
});
|
||||
await router.replace({
|
||||
pathname: `/workspace/[workspaceId]/all`,
|
||||
query: {
|
||||
workspaceId: id,
|
||||
},
|
||||
});
|
||||
setOpen(false);
|
||||
router.reload();
|
||||
}}
|
||||
/>
|
||||
</>
|
||||
|
||||
@@ -63,9 +63,10 @@ export const TrashButtonGroup = () => {
|
||||
workspaceId: workspace.id,
|
||||
},
|
||||
})
|
||||
.then(() => {
|
||||
blockSuiteWorkspace.removePage(pageId);
|
||||
.catch(error => {
|
||||
console.error(error);
|
||||
});
|
||||
blockSuiteWorkspace.removePage(pageId);
|
||||
}}
|
||||
onCancel={() => {
|
||||
setOpen(false);
|
||||
|
||||
@@ -43,7 +43,7 @@ export const MessageCenter: FC = memo(function MessageCenter() {
|
||||
})
|
||||
.catch(() => {
|
||||
setPopup(false);
|
||||
onLogout();
|
||||
return onLogout();
|
||||
});
|
||||
} else {
|
||||
toast(Messages[event.detail.code].message);
|
||||
|
||||
@@ -64,9 +64,11 @@ export const PublishedResults: FC<PublishedResultsProps> = ({
|
||||
<Command.Item
|
||||
key={result.id}
|
||||
onSelect={() => {
|
||||
router.push(
|
||||
`/public-workspace/${router.query.workspaceId}/${result.id}`
|
||||
);
|
||||
router
|
||||
.push(
|
||||
`/public-workspace/${router.query.workspaceId}/${result.id}`
|
||||
)
|
||||
.catch(err => console.error(err));
|
||||
onClose();
|
||||
}}
|
||||
value={result.id}
|
||||
|
||||
@@ -71,7 +71,9 @@ export const Results: FC<ResultsProps> = ({
|
||||
value={page.id}
|
||||
onSelect={() => {
|
||||
onClose();
|
||||
jumpToPage(blockSuiteWorkspace.id, page.id);
|
||||
jumpToPage(blockSuiteWorkspace.id, page.id).catch(
|
||||
console.error
|
||||
);
|
||||
}}
|
||||
>
|
||||
<StyledListItem>
|
||||
@@ -95,7 +97,7 @@ export const Results: FC<ResultsProps> = ({
|
||||
value={link.title}
|
||||
onSelect={() => {
|
||||
onClose();
|
||||
router.push(link.href);
|
||||
router.push(link.href).catch(console.error);
|
||||
}}
|
||||
>
|
||||
<StyledListItem>
|
||||
@@ -133,7 +135,9 @@ export const Results: FC<ResultsProps> = ({
|
||||
onSelect={() => {
|
||||
onClose();
|
||||
assertExists(blockSuiteWorkspace.id);
|
||||
jumpToPage(blockSuiteWorkspace.id, result.id);
|
||||
jumpToPage(blockSuiteWorkspace.id, result.id).catch(error =>
|
||||
console.error(error)
|
||||
);
|
||||
}}
|
||||
value={result.id}
|
||||
>
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
import { DebugLogger } from '@affine/debug';
|
||||
import type { BlobManager } from '@blocksuite/store';
|
||||
import { useEffect, useMemo, useRef, useState } from 'react';
|
||||
|
||||
import type { BlockSuiteWorkspace } from '../shared';
|
||||
|
||||
const logger = new DebugLogger('useWorkspaceBlob');
|
||||
|
||||
export function useWorkspaceBlob(
|
||||
blockSuiteWorkspace: BlockSuiteWorkspace
|
||||
): BlobManager {
|
||||
@@ -21,14 +24,19 @@ export function useWorkspaceBlobImage(
|
||||
setBlob(null);
|
||||
return;
|
||||
}
|
||||
blobManager?.get(key).then(blob => {
|
||||
if (controller.signal.aborted) {
|
||||
return;
|
||||
}
|
||||
if (blob) {
|
||||
setBlob(blob);
|
||||
}
|
||||
});
|
||||
blobManager
|
||||
?.get(key)
|
||||
.then(blob => {
|
||||
if (controller.signal.aborted) {
|
||||
return;
|
||||
}
|
||||
if (blob) {
|
||||
setBlob(blob);
|
||||
}
|
||||
})
|
||||
.catch(err => {
|
||||
logger.error('Failed to get blob', err);
|
||||
});
|
||||
return () => {
|
||||
controller.abort();
|
||||
};
|
||||
|
||||
@@ -204,7 +204,9 @@ export const WorkspaceLayout: FC<PropsWithChildren> =
|
||||
useEffect(() => {
|
||||
document.documentElement.lang = i18n.language;
|
||||
// todo(himself65): this is a hack, we should use a better way to set the language
|
||||
setUpLanguage(i18n);
|
||||
setUpLanguage(i18n)?.catch(error => {
|
||||
console.error(error);
|
||||
});
|
||||
}, [i18n]);
|
||||
useTrackRouterHistoryEffect();
|
||||
const currentWorkspaceId = useAtomValue(rootCurrentWorkspaceIdAtom);
|
||||
@@ -247,7 +249,9 @@ export const WorkspaceLayout: FC<PropsWithChildren> =
|
||||
logger.info('mount first data:', items);
|
||||
}
|
||||
|
||||
fetch();
|
||||
fetch().catch(e => {
|
||||
logger.error('fetch error:', e);
|
||||
});
|
||||
return () => {
|
||||
controller.abort();
|
||||
logger.info('unmount');
|
||||
|
||||
@@ -34,7 +34,7 @@ export const NotfoundPage = () => {
|
||||
<Button
|
||||
shape="round"
|
||||
onClick={() => {
|
||||
router.push('/');
|
||||
router.push('/').catch(err => console.error(err));
|
||||
}}
|
||||
>
|
||||
{t['Back Home']()}
|
||||
|
||||
@@ -44,7 +44,7 @@ const InvitePage: NextPageWithLayout = () => {
|
||||
inviteData.workspace_id,
|
||||
WorkspaceSubPath.ALL,
|
||||
RouteLogic.REPLACE
|
||||
);
|
||||
).catch(err => console.error(err));
|
||||
}}
|
||||
>
|
||||
Go to Workspace
|
||||
@@ -64,7 +64,7 @@ const InvitePage: NextPageWithLayout = () => {
|
||||
<Button
|
||||
shape="round"
|
||||
onClick={() => {
|
||||
router.replace(`/`);
|
||||
router.replace(`/`).catch(err => console.error(err));
|
||||
}}
|
||||
>
|
||||
Back to Home
|
||||
|
||||
@@ -26,7 +26,7 @@ const AllPage: NextPageWithLayout = () => {
|
||||
if (newTab) {
|
||||
window.open(`/workspace/${currentWorkspace?.id}/${pageId}`, '_blank');
|
||||
} else {
|
||||
jumpToPage(currentWorkspace.id, pageId);
|
||||
jumpToPage(currentWorkspace.id, pageId).catch(console.error);
|
||||
}
|
||||
},
|
||||
[currentWorkspace, jumpToPage]
|
||||
|
||||
@@ -23,7 +23,7 @@ const SharedPages: NextPageWithLayout = () => {
|
||||
if (newTab) {
|
||||
window.open(`/workspace/${currentWorkspace?.id}/${pageId}`, '_blank');
|
||||
} else {
|
||||
jumpToPage(currentWorkspace.id, pageId);
|
||||
jumpToPage(currentWorkspace.id, pageId).catch(console.error);
|
||||
}
|
||||
},
|
||||
[currentWorkspace, jumpToPage]
|
||||
|
||||
@@ -24,7 +24,9 @@ const TrashPage: NextPageWithLayout = () => {
|
||||
if (newTab) {
|
||||
window.open(`/workspace/${currentWorkspace?.id}/${pageId}`, '_blank');
|
||||
} else {
|
||||
jumpToPage(currentWorkspace.id, pageId);
|
||||
jumpToPage(currentWorkspace.id, pageId).catch(error => {
|
||||
console.error(error);
|
||||
});
|
||||
}
|
||||
},
|
||||
[currentWorkspace, jumpToPage]
|
||||
|
||||
@@ -129,7 +129,9 @@ export const AllWorkspaceModals = (): ReactElement => {
|
||||
workspace => {
|
||||
setOpenWorkspacesModal(false);
|
||||
setCurrentWorkspaceId(workspace.id);
|
||||
jumpToSubPath(workspace.id, WorkspaceSubPath.ALL);
|
||||
jumpToSubPath(workspace.id, WorkspaceSubPath.ALL).catch(error => {
|
||||
console.error(error);
|
||||
});
|
||||
},
|
||||
[jumpToSubPath, setCurrentWorkspaceId, setOpenWorkspacesModal]
|
||||
)}
|
||||
@@ -137,7 +139,11 @@ export const AllWorkspaceModals = (): ReactElement => {
|
||||
workspace => {
|
||||
setOpenWorkspacesModal(false);
|
||||
setCurrentWorkspaceId(workspace.id);
|
||||
jumpToSubPath(workspace.id, WorkspaceSubPath.SETTING);
|
||||
jumpToSubPath(workspace.id, WorkspaceSubPath.SETTING).catch(
|
||||
error => {
|
||||
console.error(error);
|
||||
}
|
||||
);
|
||||
},
|
||||
[jumpToSubPath, setCurrentWorkspaceId, setOpenWorkspacesModal]
|
||||
)}
|
||||
|
||||
Reference in New Issue
Block a user