feat: don't sync if there is no net work, or passed in syncImmediately: false

This commit is contained in:
tiddlygit-test 2021-10-17 23:19:04 +08:00
parent 600068b422
commit 109355cb5d
2 changed files with 7 additions and 4 deletions

View file

@ -1,4 +1,4 @@
import { ipcMain, dialog } from 'electron';
import { ipcMain, dialog, net } from 'electron';
import { injectable, inject } from 'inversify';
import { debounce } from 'lodash';
import {
@ -223,8 +223,8 @@ export class Git implements IGitService {
logger.log(level, this.translateMessage(message), meta);
},
error: (error) => {
this.translateAndLogErrorMessage(error);
reject(error);
this.translateAndLogErrorMessage(error as Error);
reject(error as Error);
},
complete: () => resolve(),
});
@ -238,6 +238,9 @@ export class Git implements IGitService {
}
public async commitAndSync(wikiFolderPath: string, remoteUrl: string, userInfo: IGitUserInfos): Promise<void> {
if (!net.isOnline()) {
return;
}
return await new Promise<void>((resolve, reject) => {
this.gitWorker?.commitAndSyncWiki(wikiFolderPath, remoteUrl, userInfo).subscribe(this.getWorkerObserver(resolve, reject));
});

View file

@ -85,7 +85,7 @@ export class WorkspaceView implements IWorkspaceViewService {
// get sync process ready
try {
if (workspace.syncOnStartup && storageService !== SupportedStorageServices.local) {
if (workspace.syncOnStartup && storageService !== SupportedStorageServices.local && syncImmediately) {
// check synced wiki should have githubRepoUrl
if (typeof githubRepoUrl !== 'string') {
throw new TypeError(`githubRepoUrl is undefined in initializeAllWorkspaceView when init ${wikiFolderLocation}`);