Skip to content
This repository was archived by the owner on May 20, 2020. It is now read-only.

Commit bbb4ce2

Browse files
committed
fix broken data storage upgrade from 3.4.3
1 parent 6e7e090 commit bbb4ce2

File tree

3 files changed

+107
-16
lines changed

3 files changed

+107
-16
lines changed

js/background.js

+43-16
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,24 @@ let removeCtxSnippetList,
265265
};
266266
}());
267267

268+
/**
269+
* when upgrading from old versions to 3.5.0, we need to set
270+
* the localStorage property which indicates what type of storage
271+
* the user is using. This fn detects correct storage
272+
* @param {Function} callback fn called after correctly setting type of
273+
* storage in localStorage
274+
*/
275+
function updateCompatForOldData(callback) {
276+
localStorage[LS_STORAGE_TYPE_PROP] = "local";
277+
chrome.storage.local.get(OLD_DATA_STORAGE_KEY, (response) => {
278+
const Data = response[OLD_DATA_STORAGE_KEY];
279+
if (Data.snippets === false) {
280+
localStorage[LS_STORAGE_TYPE_PROP] = "sync";
281+
}
282+
callback();
283+
});
284+
}
285+
268286
function afterBGPageReload({
269287
notifText, notifTitle, version, reason,
270288
}) {
@@ -282,6 +300,20 @@ function afterBGPageReload({
282300
});
283301
}
284302

303+
function handleExtUpdate(notifProps) {
304+
storage = chrome.storage[localStorage[LS_STORAGE_TYPE_PROP]];
305+
306+
window.latestRevisionLabel = "";
307+
storage.get(
308+
OLD_DATA_STORAGE_KEY,
309+
chromeAPICallWrapper((response) => {
310+
window.Data = response[OLD_DATA_STORAGE_KEY];
311+
312+
afterBGPageReload(notifProps);
313+
}),
314+
);
315+
}
316+
285317
chrome.runtime.onInstalled.addListener((details) => {
286318
runtimeOnInstalledFired = true;
287319
// unset it after five seconds, reasonable time
@@ -316,22 +348,17 @@ chrome.runtime.onInstalled.addListener((details) => {
316348
} else if (reason === "update") {
317349
notifTitle = `ProKeys updated to v${version}`;
318350
notifText = "Hooray! Please reload active tabs to use the new version.";
319-
storage = chrome.storage[localStorage[LS_STORAGE_TYPE_PROP]];
320-
321-
window.latestRevisionLabel = "";
322-
storage.get(
323-
OLD_DATA_STORAGE_KEY,
324-
chromeAPICallWrapper((response) => {
325-
window.Data = response[OLD_DATA_STORAGE_KEY];
326-
327-
afterBGPageReload({
328-
notifText,
329-
notifTitle,
330-
version,
331-
reason,
332-
});
333-
}),
334-
);
351+
const args = {
352+
notifText,
353+
notifTitle,
354+
version,
355+
reason,
356+
};
357+
if (typeof localStorage[LS_STORAGE_TYPE_PROP] === "undefined") {
358+
updateCompatForOldData(() => handleExtUpdate(args));
359+
} else {
360+
handleExtUpdate(args);
361+
}
335362
} else {
336363
// do not process anything other than install or update
337364
}
+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
{
2+
"blockedSites": [
3+
"so.com"
4+
],
5+
"charsToAutoInsertUserList": [
6+
[
7+
"(",
8+
")"
9+
],
10+
[
11+
"[",
12+
"]"
13+
]
14+
],
15+
"dataUpdateVariable": true,
16+
"dataVersion": 1,
17+
"hotKey": [
18+
32
19+
],
20+
"language": "English",
21+
"matchDelimitedWord": true,
22+
"omniboxSearchURL": "https://www.google.com/search?q=SEARCH",
23+
"snipNameDelimiterList": "@#$%&*+-=(){}[]:\"'/_<>?!., ",
24+
"snippets": [
25+
"Snippets",
26+
1560319171318,
27+
[
28+
"sampleFolder",
29+
1560319171318,
30+
{
31+
"name": "brb",
32+
"body": "be right back",
33+
"timestamp": 1560319171318
34+
},
35+
{
36+
"name": "dateArithmetic",
37+
"body": "Use this snippet in any webpage, and you'll see that the following: [[%d(Do MMMM YYYY hh:m:s)]] is replaced by the current date and time.\n\nMoreover, you can perform date/time arithmetic. The following: [[%d(D+5 MMMM+5 YYYY+5 hh-5:m-5:s-5)]] gives the date, month, year, forward by five; and hour, minutes, and seconds backward by 5.\n\nMore info on this in the Help section.",
38+
"timestamp": 1560319171318
39+
},
40+
{
41+
"name": "letter",
42+
"body": "(Sample snippet to demonstrate the power of ProKeys snippets; for more detail on Placeholders, see the Help section)\n\nHello %name%,\n\nYour complaint number %complaint% has been noted. We will work at our best pace to get this issue solved for you. If you experience any more problems, please feel free to contact at [email protected].\n\nRegards,\n%my_name%,\nDate: [[%d(D-MM-YYYY)]]",
43+
"timestamp": 1560319171318
44+
},
45+
{
46+
"name": "my_sign",
47+
"body": "<b>Aquila Softworks ©</b>\n<i>Creator Of ProKeys</i>\n<u>[email protected]</u>",
48+
"timestamp": 1560319171318
49+
}
50+
],
51+
{
52+
"name": "123",
53+
"body": "Hello new user! Thank you for using ProKeys!\n\nThis is a sample snippet. Try using it on any webpage by typing 'sampleSnippet' (snippet name; without quotes), and press the hotkey (default: Shift+Space), and this whole text would come in place of it.",
54+
"timestamp": 1560319171318
55+
}
56+
],
57+
"tabKey": false,
58+
"visited": true,
59+
"wrapSelectionAutoInsert": true
60+
}

tests/data/README.md

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Test data
2+
3+
This data can be exported into a v3.4.3+ extension to enable it for testing.
4+
It features several changes to default data, and the aim is that after upgrading from one version to another, this data must be retained as is.

0 commit comments

Comments
 (0)