Skip to content

Commit ce07cf4

Browse files
author
Bardoe Besselaar
committed
feat: graceful offline support #590
+ Set offline mode when there is no network connection and an remote attempt is made. + Reset offline mode flag when connectivity re-establishes and pull changes (delayed pull/push request)
1 parent e3a0be7 commit ce07cf4

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/main.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,19 @@ export default class ObsidianGit extends Plugin {
138138
}
139139
}
140140

141+
async handleOnlineStatusChange() {
142+
if (!this.offlineMode) return;
143+
144+
if (navigator.onLine) {
145+
this.offlineMode = false;
146+
this.promiseQueue.addTask(() => this.pullChangesFromRemote());
147+
}
148+
}
149+
141150
async loadPlugin() {
142151
addEventListener("git-refresh", this.refresh.bind(this));
143152
addEventListener("git-head-update", this.refreshUpdatedHead.bind(this));
153+
addEventListener("online", this.handleOnlineStatusChange.bind(this));
144154

145155
this.registerView(SOURCE_CONTROL_VIEW_CONFIG.type, (leaf) => {
146156
return new GitView(leaf, this);
@@ -742,6 +752,7 @@ export default class ObsidianGit extends Plugin {
742752

743753
hasConnectivity() {
744754
if (navigator.onLine) return true;
755+
this.offlineMode = true;
745756
return (new Notice('No Connectivity'), false)
746757
}
747758

0 commit comments

Comments
 (0)