Skip to content

Commit

Permalink
fix: hide notification on mobile
Browse files Browse the repository at this point in the history
close #292
  • Loading branch information
Vinzent03 committed Nov 2, 2022
1 parent 76b894c commit 7d62527
Showing 1 changed file with 34 additions and 19 deletions.
53 changes: 34 additions & 19 deletions src/isomorphicGit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,18 +110,23 @@ export class IsomorphicGit extends GitManager {
}

async status(): Promise<Status> {
const notice = new Notice("Getting status...", this.noticeLength);
let notice: Notice | undefined;
const timeout = window.setTimeout(function () {
notice = new Notice("This takes longer: Getting status", this.noticeLength);
}, 20000);
try {
this.plugin.setState(PluginState.status);
const status = (await this.wrapFS(git.statusMatrix({ ...this.getRepo(), }))).map(row => this.getFileStatusResult(row));

const changed = status.filter(fileStatus => fileStatus.working_dir !== " ");
const staged = status.filter(fileStatus => fileStatus.index !== " " && fileStatus.index !== "U");
const conflicted: string[] = [];
notice.hide();
window.clearTimeout(timeout);
notice?.hide();
return { changed, staged, conflicted };
} catch (error) {
notice.hide();
window.clearTimeout(timeout);
notice?.hide();
this.plugin.displayError(error);
throw error;
}
Expand Down Expand Up @@ -279,7 +284,7 @@ export class IsomorphicGit extends GitManager {
}

async pull(): Promise<FileStatusResult[]> {
const progressNotice = new Notice("Initializing pull", this.noticeLength);
const progressNotice = this.showNotice("Initializing pull");
try {

this.plugin.setState(PluginState.pull);
Expand All @@ -302,7 +307,7 @@ export class IsomorphicGit extends GitManager {
},
remote: branchInfo.remote,
}));
progressNotice.hide();
progressNotice?.hide();

const upstreamCommit = await this.resolveRef("HEAD");
this.plugin.lastUpdate = Date.now();
Expand All @@ -316,7 +321,7 @@ export class IsomorphicGit extends GitManager {
vault_path: this.getVaultPath(file.path),
}));
} catch (error) {
progressNotice.hide();
progressNotice?.hide();
if (error instanceof Errors.MergeConflictError) {
this.plugin.handleConflict(error.data.filepaths.map((file) => this.getVaultPath(file)));
}
Expand All @@ -330,7 +335,7 @@ export class IsomorphicGit extends GitManager {
if (! await this.canPush()) {
return 0;
}
const progressNotice = new Notice("Initializing push", this.noticeLength);
const progressNotice = this.showNotice("Initializing push");
try {
this.plugin.setState(PluginState.status);
const status = await this.branchInfo();
Expand All @@ -346,10 +351,10 @@ export class IsomorphicGit extends GitManager {
(progressNotice as any).noticeEl.innerText = this.getProgressText("Pushing", progress);
}
}));
progressNotice.hide();
progressNotice?.hide();
return numChangedFiles;
} catch (error) {
progressNotice.hide();
progressNotice?.hide();
this.plugin.displayError(error);
throw error;
}
Expand Down Expand Up @@ -451,7 +456,7 @@ export class IsomorphicGit extends GitManager {
}

async clone(url: string, dir: string): Promise<void> {
const progressNotice = new Notice("Initializing clone", this.noticeLength);
const progressNotice = this.showNotice("Initializing clone");
try {
await this.wrapFS(git.clone({
...this.getRepo(),
Expand All @@ -461,9 +466,9 @@ export class IsomorphicGit extends GitManager {
(progressNotice as any).noticeEl.innerText = this.getProgressText("Cloning", progress);
}
}));
progressNotice.hide();
progressNotice?.hide();
} catch (error) {
progressNotice.hide();
progressNotice?.hide();
this.plugin.displayError(error);
throw error;
}
Expand Down Expand Up @@ -495,7 +500,7 @@ export class IsomorphicGit extends GitManager {
}

async fetch(remote?: string): Promise<void> {
const progressNotice = new Notice("Initializing fetch", this.noticeLength);
const progressNotice = this.showNotice("Initializing fetch");

try {
const args: any = {
Expand All @@ -507,10 +512,10 @@ export class IsomorphicGit extends GitManager {
};

await this.wrapFS(git.fetch(args));
progressNotice.hide();
progressNotice?.hide();
} catch (error) {
this.plugin.displayError(error);
progressNotice.hide();
progressNotice?.hide();
throw error;
}
}
Expand Down Expand Up @@ -631,8 +636,10 @@ export class IsomorphicGit extends GitManager {
}

async getUnstagedFiles(base = "."): Promise<UnstagedFile[]> {
const notice = new Notice("Getting status...", this.noticeLength);

let notice: Notice | undefined;
const timeout = window.setTimeout(function () {
notice = new Notice("This takes longer: Getting status", this.noticeLength);
}, 20000);
try {
const repo = this.getRepo();
const res = await this.wrapFS<Promise<UnstagedFile[]>>(
Expand Down Expand Up @@ -708,10 +715,12 @@ export class IsomorphicGit extends GitManager {
// return [filepath, ...result];
}
}));
notice.hide();
window.clearTimeout(timeout);
notice?.hide();
return res;
} catch (error) {
notice.hide();
window.clearTimeout(timeout);
notice?.hide();
this.plugin.displayError(error);
throw error;
}
Expand Down Expand Up @@ -766,6 +775,12 @@ export class IsomorphicGit extends GitManager {
};

}

private showNotice(message: string): Notice | undefined {
if (!this.plugin.settings.disablePopups) {
return new Notice(message, this.noticeLength);
}
}
}

// All because we can't use (for await)...
Expand Down

0 comments on commit 7d62527

Please sign in to comment.