Skip to content

Commit ef6b326

Browse files
committed
close #227
1 parent 50eae37 commit ef6b326

File tree

2 files changed

+64
-58
lines changed

2 files changed

+64
-58
lines changed

src/popup.ts

Lines changed: 1 addition & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -63,64 +63,7 @@ async function init() {
6363
clientTime - localStorage.lastRemindingBackupTime >= 30 ||
6464
clientTime - localStorage.lastRemindingBackupTime < 0) {
6565
// backup to cloud
66-
if (authenticator.dropboxToken) {
67-
chrome.permissions.contains(
68-
{origins: ['https://*.dropboxapi.com/*']},
69-
async (hasPermission) => {
70-
if (hasPermission) {
71-
try {
72-
const dropbox = new Dropbox();
73-
const res = await dropbox.upload(authenticator.encryption);
74-
if (res) {
75-
// we have uploaded backup to Dropbox
76-
// no need to remind
77-
localStorage.lastRemindingBackupTime = clientTime;
78-
return;
79-
} else if (localStorage.dropboxRevoked === 'true') {
80-
authenticator.alert(String(authenticator.i18n.token_revoked)
81-
.replace(/\${service}/, 'Dropbox'));
82-
localStorage.removeItem('dropboxRevoked');
83-
}
84-
} catch (error) {
85-
// ignore
86-
}
87-
}
88-
authenticator.alert(authenticator.i18n.remind_backup);
89-
localStorage.lastRemindingBackupTime = clientTime;
90-
});
91-
} else if (authenticator.driveToken) {
92-
chrome.permissions.contains(
93-
{
94-
origins: [
95-
'https://www.googleapis.com/*',
96-
'https://accounts.google.com/o/oauth2/revoke'
97-
]
98-
},
99-
async (hasPermission) => {
100-
if (hasPermission) {
101-
try {
102-
const drive = new Drive();
103-
const res = await drive.upload(authenticator.encryption);
104-
if (res) {
105-
localStorage.lastRemindingBackupTime = clientTime;
106-
return;
107-
} else if (localStorage.driveRevoked === 'true') {
108-
authenticator.alert(
109-
String(authenticator.i18n.token_revoked)
110-
.replace(/\${service}/, 'Google Drive'));
111-
localStorage.removeItem('driveRevoked');
112-
}
113-
} catch (error) {
114-
// ignore
115-
}
116-
}
117-
authenticator.alert(authenticator.i18n.remind_backup);
118-
localStorage.lastRemindingBackupTime = clientTime;
119-
});
120-
} else {
121-
authenticator.alert(authenticator.i18n.remind_backup);
122-
localStorage.lastRemindingBackupTime = clientTime;
123-
}
66+
authenticator.runScheduledBackup(clientTime);
12467
}
12568
return;
12669
}, 1000);

src/ui/backup.ts

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)