fix: initializeAllWorkspaceView await in loop

This commit is contained in:
tiddlygit-test 2021-03-19 23:31:22 +08:00
parent c787a273d9
commit ab63d043d4
4 changed files with 11 additions and 7 deletions

View file

@ -84,7 +84,6 @@ module.exports = {
'plugin:react/recommended',
'plugin:unicorn/recommended',
'plugin:prettier/recommended',
'prettier',
'standard-with-typescript',
'plugin:@typescript-eslint/eslint-recommended',
'plugin:@typescript-eslint/recommended',
@ -93,6 +92,7 @@ module.exports = {
'plugin:import/warnings',
'plugin:import/typescript',
'plugin:react-hooks/recommended',
'prettier',
],
plugins: ['@typescript-eslint/eslint-plugin', 'prettier', 'react', 'html', 'react', 'unicorn', 'import', 'react-hooks'],
env: {

View file

@ -102,6 +102,7 @@ if (!gotTheLock) {
// eslint-disable-next-line promise/catch-or-return
await app.whenReady();
if (isDev) {
// eslint-disable-next-line @typescript-eslint/no-misused-promises
protocol.registerFileProtocol('file', async (request, callback) => {
const pathname = decodeURIComponent(request.url.replace('file:///', ''));
if (path.isAbsolute(pathname) ? await fs.pathExists(pathname) : await fs.pathExists(`/${pathname}`)) {
@ -114,7 +115,6 @@ if (!gotTheLock) {
}
await windowService.open(WindowNames.main);
buildLanguageMenu();
// FIXME: this await is never ended
await workspaceViewService.initializeAllWorkspaceView();
ipcMain.emit('request-update-pause-notifications-info');

View file

@ -105,7 +105,6 @@ export default function setupViewEventHandlers(
if (workspaceObject === undefined) {
return;
}
// FIXME: seems isLoading is now controlled by wiki-worker-manager.js , and should not update here
workspaceService.updateMetaData(workspace.id, {
isLoading: false,
});

View file

@ -53,21 +53,26 @@ export class WorkspaceView implements IWorkspaceViewService {
}
try {
const userInfo = this.authService.getStorageServiceUserInfo(workspace.storageService);
const { name: wikiPath, gitUrl: githubRepoUrl, isSubWiki } = workspace;
// TODO: rename name to wikiPath
const { name: wikiPath, gitUrl: githubRepoUrl } = workspace;
// wait for main wiki's watch-fs plugin to be fully initialized
// and also wait for wiki BrowserView to be able to receive command
// eslint-disable-next-line global-require
let workspaceMetadata = this.workspaceService.getMetaData(workspaceID);
if (!isSubWiki) {
// wait for main wiki webview loaded
if (!workspace.isSubWiki) {
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
while (!workspaceMetadata.didFailLoadErrorMessage && !workspaceMetadata.isLoading) {
while (workspaceMetadata.isLoading !== false) {
// eslint-disable-next-line no-await-in-loop
await delay(500);
workspaceMetadata = this.workspaceService.getMetaData(workspaceID);
}
if (workspaceMetadata.didFailLoadErrorMessage) {
throw new Error(workspaceMetadata.didFailLoadErrorMessage);
}
}
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
if (!isSubWiki && !workspaceMetadata.didFailLoadErrorMessage?.length && userInfo?.accessToken) {
if (!workspace.isSubWiki && !workspaceMetadata.didFailLoadErrorMessage?.length && userInfo?.accessToken) {
await this.gitService.commitAndSync(wikiPath, githubRepoUrl, userInfo);
}
} catch {