@@ -740,6 +740,36 @@ export default class ObsidianGit extends Plugin {
740
740
return Platform . isDesktopApp ;
741
741
}
742
742
743
+ async apiEndpointError ( ) {
744
+ try {
745
+ // none, minor, major, or critical
746
+ return await fetch ( 'https://www.githubstatus.com/api/v2/status.json' )
747
+ . then ( ( response ) => response . json ( ) )
748
+ . then ( ( { status : { indicator } } ) => indicator )
749
+ . catch ( ( error ) => {
750
+ console . warn ( 'githubStatusError' , error ) ;
751
+ return 'disconnected' ;
752
+ } ) ;
753
+ } catch ( error ) {
754
+ console . warn ( 'githubStatusError' , error ) ;
755
+ return 'disconnected' ;
756
+ } ;
757
+ }
758
+
759
+ async isConnectionEstablished ( ) {
760
+ switch ( await this . apiEndpointError ( ) ) {
761
+ case "disconnected" :
762
+ new Notice ( 'No Connectivity' )
763
+ return false ;
764
+ case "critical" :
765
+ new Notice ( 'Github API Server Outage' )
766
+ case "major" :
767
+ console . warn ( 'Github API Major Server Outage' )
768
+ default :
769
+ return true ;
770
+ }
771
+ }
772
+
743
773
async init ( ) : Promise < void > {
744
774
this . showNotices ( ) ;
745
775
@@ -926,6 +956,7 @@ export default class ObsidianGit extends Plugin {
926
956
///Used for command
927
957
async pullChangesFromRemote ( ) : Promise < void > {
928
958
if ( ! ( await this . isAllInitialized ( ) ) ) return ;
959
+ if ( ! ( await this . isConnectionEstablished ( ) ) ) return ;
929
960
930
961
const filesUpdated = await this . pull ( ) ;
931
962
this . setUpAutoBackup ( ) ;
@@ -956,10 +987,13 @@ export default class ObsidianGit extends Plugin {
956
987
) : Promise < void > {
957
988
if ( ! ( await this . isAllInitialized ( ) ) ) return ;
958
989
990
+ const isConnected = await this . isConnectionEstablished ( ) ;
991
+
959
992
if (
960
993
this . settings . syncMethod == "reset" &&
961
994
this . settings . pullBeforePush
962
995
) {
996
+ if ( ! isConnected ) return ;
963
997
await this . pull ( ) ;
964
998
}
965
999
@@ -975,6 +1009,7 @@ export default class ObsidianGit extends Plugin {
975
1009
if ( ! this . settings . disablePush ) {
976
1010
// Prevent plugin to pull/push at every call of createBackup. Only if unpushed commits are present
977
1011
if ( await this . gitManager . canPush ( ) ) {
1012
+ if ( ! isConnected ) return ;
978
1013
if (
979
1014
this . settings . syncMethod != "reset" &&
980
1015
this . settings . pullBeforePush
@@ -1166,9 +1201,9 @@ export default class ObsidianGit extends Plugin {
1166
1201
1167
1202
async push ( ) : Promise < boolean > {
1168
1203
if ( ! ( await this . isAllInitialized ( ) ) ) return false ;
1169
- if ( ! ( await this . remotesAreSet ( ) ) ) {
1170
- return false ;
1171
- }
1204
+ if ( ! ( await this . remotesAreSet ( ) ) ) return false ;
1205
+ if ( ! ( await this . isConnectionEstablished ( ) ) ) return false ;
1206
+
1172
1207
const hadConflict = this . localStorage . getConflict ( ) === "true" ;
1173
1208
if ( this . gitManager instanceof SimpleGit )
1174
1209
await this . mayDeleteConflictFile ( ) ;
0 commit comments