Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to select backup file for import #507

Merged
merged 1 commit into from
Mar 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
<application android:usesCleartextTraffic="true" />
<application android:requestLegacyExternalStorage="true" />
<application android:extractNativeLibs="true" />
<application android:largeHeap="true" />
</edit-config>
<icon density="ldpi" background="res/icon/android/ldpi-background.png" foreground="res/icon/android/ldpi-foreground.png" src="res/android/ldpi.png" />
<icon density="mdpi" background="res/icon/android/mdpi-background.png" foreground="res/icon/android/mdpi-foreground.png" src="res/android/mdpi.png" />
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"cordova-browser": "^6.0.0",
"cordova-plugin-browsersync-gen2": "^1.1.7",
"cordova-plugin-camera": "^6.0.0",
"cordova-plugin-chooser": "^1.3.2",
"cordova-plugin-device": "^2.0.3",
"cordova-plugin-file": "^6.0.2",
"cordova-plugin-inappbrowser": "^5.0.0",
Expand All @@ -30,7 +31,8 @@
"cordova-plugin-file": {},
"cordova-plugin-device": {},
"cordova-plugin-inappbrowser": {},
"cordova-plugin-ionic-keyboard": {}
"cordova-plugin-ionic-keyboard": {},
"cordova-plugin-chooser": {}
},
"platforms": [
"browser",
Expand Down
74 changes: 40 additions & 34 deletions www/activities/settings/js/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -317,42 +317,48 @@ app.Settings = {
}
},

importDatabase: function() {
let title = app.strings.settings.integration.import || "Import";
let text = app.strings.settings.integration["confirm-import"] || "Are you sure? This will overwrite your current database.";

let div = document.createElement("div");
div.className = "dialog-text";
div.innerText = text;

let dialog = app.f7.dialog.create({
title: title,
content: div.outerHTML,
buttons: [{
text: app.strings.dialogs.cancel || "Cancel",
keyCodes: [27]
},
{
text: app.strings.dialogs.ok || "OK",
keyCodes: [13],
onClick: async () => {
let filename = "waistline_export.json";
let json = await app.Utils.readFile(filename);

if (json !== undefined) {
let data = JSON.parse(json);
await dbHandler.import(data);

if (data.settings !== undefined) {
let settings = app.Settings.migrateSettings(data.settings, false);
window.localStorage.setItem("settings", JSON.stringify(settings));
this.changeTheme(settings.appearance["dark-mode"], settings.appearance["theme"]);
importDatabase: async function() {
let file = await chooser.getFile("application/json");

if (file !== undefined && file.data !== undefined) {
let data;
try {
let content = new TextDecoder("utf-8").decode(file.data);
data = JSON.parse(content);
} catch (e) { }

if (data !== undefined) {
let title = app.strings.settings.integration.import || "Import";
let text = app.strings.settings.integration["confirm-import"] || "Are you sure? This will overwrite your current database.";

let div = document.createElement("div");
div.className = "dialog-text";
div.innerText = text;

let dialog = app.f7.dialog.create({
title: title,
content: div.outerHTML,
buttons: [{
text: app.strings.dialogs.cancel || "Cancel",
keyCodes: [27]
},
{
text: app.strings.dialogs.ok || "OK",
keyCodes: [13],
onClick: async () => {
await dbHandler.import(data);

if (data.settings !== undefined) {
let settings = app.Settings.migrateSettings(data.settings, false);
window.localStorage.setItem("settings", JSON.stringify(settings));
this.changeTheme(settings.appearance["dark-mode"], settings.appearance["theme"]);
}
}
}
}
}
]
}).open();
]
}).open();
}
}
},

firstTimeSetup: function() {
Expand Down