feat: ask user to use github desktop to debug themselves if git sync error

This commit is contained in:
林一二 2021-12-28 13:59:16 +08:00
parent 54b4011c07
commit f7df1ca5df
4 changed files with 48 additions and 9 deletions

View file

@ -3,3 +3,4 @@
*/
export const defaultServerIP = '0.0.0.0';
export const latestUpdateUrl = 'https://github.com/tiddly-gittly/TidGi-Desktop/releases/latest';
export const githubDesktopUrl = 'https://desktop.github.com/';

View file

@ -1,4 +1,4 @@
import { ipcMain, dialog, net } from 'electron';
import { ipcMain, dialog, net, shell } from 'electron';
import { injectable, inject } from 'inversify';
import { compact, debounce } from 'lodash';
import {
@ -17,6 +17,8 @@ import { spawn, Worker, ModuleThread } from 'threads';
import serviceIdentifier from '@services/serviceIdentifier';
import type { IViewService } from '@services/view/interface';
import type { IPreferenceService } from '@services/preferences/interface';
import type { IWindowService } from '@services/windows/interface';
import type { INativeService } from '@services/native/interface';
import { logger } from '@services/libs/log';
import i18n from '@services/libs/i18n';
import { IGitLogMessage, IGitService, IGitUserInfos } from './interface';
@ -30,12 +32,13 @@ import workerURL from 'threads-plugin/dist/loader?name=gitWorker!./gitWorker.ts'
import { LOCAL_GIT_DIRECTORY } from '@/constants/appPaths';
import { WindowNames } from '@services/windows/WindowProperties';
import { lazyInject } from '@services/container';
import type { IWindowService } from '@services/windows/interface';
import { githubDesktopUrl } from '@/constants/urls';
@injectable()
export class Git implements IGitService {
@lazyInject(serviceIdentifier.Window) private readonly windowService!: IWindowService;
@lazyInject(serviceIdentifier.View) private readonly viewService!: IViewService;
@lazyInject(serviceIdentifier.NativeService) private readonly nativeService!: INativeService;
private gitWorker?: ModuleThread<GitWorker>;
@ -236,6 +239,33 @@ export class Git implements IGitService {
complete: () => resolve(),
});
private createFailedDialog(message: string, wikiFolderPath: string): void {
const mainWindow = this.windowService.get(WindowNames.main);
if (mainWindow !== undefined) {
void dialog
.showMessageBox(mainWindow, {
title: i18n.t('Log.SynchronizationFailed'),
message,
buttons: ['OK', 'Github Desktop'],
cancelId: 0,
defaultId: 1,
})
.then(async ({ response }) => {
if (response === 1) {
try {
const result = await this.nativeService.openInGitGuiApp(wikiFolderPath);
if (!result) {
throw new Error('open download site');
}
} catch {
await shell.openExternal(githubDesktopUrl);
}
}
})
.catch((error) => logger.error('createFailedDialog failed', error));
}
}
public async initWikiGit(wikiFolderPath: string, isSyncedWiki?: boolean, isMainWiki?: boolean, remoteUrl?: string, userInfo?: IGitUserInfos): Promise<void> {
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
const syncImmediately = !!isSyncedWiki && !!isMainWiki;
@ -248,9 +278,13 @@ export class Git implements IGitService {
if (!net.isOnline()) {
return;
}
return await new Promise<void>((resolve, reject) => {
this.gitWorker?.commitAndSyncWiki(wikiFolderPath, remoteUrl, userInfo).subscribe(this.getWorkerObserver(resolve, reject));
});
try {
return await new Promise<void>((resolve, reject) => {
this.gitWorker?.commitAndSyncWiki(wikiFolderPath, remoteUrl, userInfo).subscribe(this.getWorkerObserver(resolve, reject));
});
} catch (error) {
this.createFailedDialog((error as Error).message, wikiFolderPath);
}
}
public async clone(remoteUrl: string, repoFolderPath: string, userInfo: IGitUserInfos): Promise<void> {

View file

@ -25,7 +25,7 @@ export class NativeService implements INativeService {
constructor(@inject(serviceIdentifier.Window) private readonly windowService: IWindowService) {}
public async openInEditor(filePath: string, editorName?: string): Promise<void> {
public async openInEditor(filePath: string, editorName?: string): Promise<boolean> {
// TODO: open vscode by default to speed up, support choose favorite editor later
let defaultEditor = await findEditorOrDefault('Visual Studio Code').catch(() => {});
if (defaultEditor === undefined) {
@ -33,14 +33,18 @@ export class NativeService implements INativeService {
}
if (defaultEditor !== undefined) {
await launchExternalEditor(filePath, defaultEditor);
return true;
}
return false;
}
public async openInGitGuiApp(filePath: string, editorName?: string): Promise<void> {
public async openInGitGuiApp(filePath: string, editorName?: string): Promise<boolean> {
const defaultEditor = await findGitGUIAppOrDefault(editorName);
if (defaultEditor !== undefined) {
await launchExternalEditor(filePath, defaultEditor);
return true;
}
return false;
}
public executeZxScript$(zxWorkerArguments: IZxFileInput, wikiFolderLocation?: string): Observable<string> {

View file

@ -18,8 +18,8 @@ export interface INativeService {
executeZxScript$(zxWorkerArguments: IZxFileInput, wikiFolderLocation?: string): Observable<string>;
log(level: string, message: string, meta?: Record<string, unknown>): Promise<void>;
open(uri: string, isDirectory?: boolean): Promise<void>;
openInEditor(filePath: string, editorName?: string | undefined): Promise<void>;
openInGitGuiApp(filePath: string, editorName?: string | undefined): Promise<void>;
openInEditor(filePath: string, editorName?: string | undefined): Promise<boolean>;
openInGitGuiApp(filePath: string, editorName?: string | undefined): Promise<boolean>;
openNewGitHubIssue(error: Error): Promise<void>;
pickDirectory(defaultPath?: string): Promise<string[]>;
pickFile(filters?: Electron.OpenDialogOptions['filters']): Promise<string[]>;