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