@@ -91,6 +91,69 @@ async function backup(_ui: UI) {
9191 getBackupToken : ( service : string ) => {
9292 chrome . runtime . sendMessage ( { action : service } ) ;
9393 } ,
94+ runScheduledBackup : ( clientTime : number ) => {
95+ if ( _ui . instance . dropboxToken ) {
96+ chrome . permissions . contains (
97+ { origins : [ 'https://*.dropboxapi.com/*' ] } ,
98+ async ( hasPermission ) => {
99+ if ( hasPermission ) {
100+ try {
101+ const dropbox = new Dropbox ( ) ;
102+ const res = await dropbox . upload ( _ui . instance . encryption ) ;
103+ if ( res ) {
104+ // we have uploaded backup to Dropbox
105+ // no need to remind
106+ localStorage . lastRemindingBackupTime = clientTime ;
107+ return ;
108+ } else if ( localStorage . dropboxRevoked === 'true' ) {
109+ _ui . instance . alert (
110+ String ( _ui . instance . i18n . token_revoked )
111+ . replace ( / \$ { service} / , 'Dropbox' ) ) ;
112+ localStorage . removeItem ( 'dropboxRevoked' ) ;
113+ }
114+ } catch ( error ) {
115+ // ignore
116+ }
117+ }
118+ _ui . instance . alert ( _ui . instance . i18n . remind_backup ) ;
119+ localStorage . lastRemindingBackupTime = clientTime ;
120+ } ) ;
121+ }
122+ if ( _ui . instance . driveToken ) {
123+ chrome . permissions . contains (
124+ {
125+ origins : [
126+ 'https://www.googleapis.com/*' ,
127+ 'https://accounts.google.com/o/oauth2/revoke'
128+ ]
129+ } ,
130+ async ( hasPermission ) => {
131+ if ( hasPermission ) {
132+ try {
133+ const drive = new Drive ( ) ;
134+ const res = await drive . upload ( _ui . instance . encryption ) ;
135+ if ( res ) {
136+ localStorage . lastRemindingBackupTime = clientTime ;
137+ return ;
138+ } else if ( localStorage . driveRevoked === 'true' ) {
139+ _ui . instance . alert (
140+ String ( _ui . instance . i18n . token_revoked )
141+ . replace ( / \$ { service} / , 'Google Drive' ) ) ;
142+ localStorage . removeItem ( 'driveRevoked' ) ;
143+ }
144+ } catch ( error ) {
145+ // ignore
146+ }
147+ }
148+ _ui . instance . alert ( _ui . instance . i18n . remind_backup ) ;
149+ localStorage . lastRemindingBackupTime = clientTime ;
150+ } ) ;
151+ }
152+ if ( ! _ui . instance . driveToken && ! _ui . instance . dropboxToken ) {
153+ _ui . instance . alert ( _ui . instance . i18n . remind_backup ) ;
154+ localStorage . lastRemindingBackupTime = clientTime ;
155+ }
156+ }
94157 }
95158 } ;
96159
0 commit comments