Skip to content

Commit

Permalink
Fixed a bug that caused boolean preferences to be initialized incorre…
Browse files Browse the repository at this point in the history
…ctly
  • Loading branch information
fjwillemsen committed Aug 29, 2022
1 parent 4132bf7 commit 6d980b7
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 21 deletions.
5 changes: 4 additions & 1 deletion README.md
Expand Up @@ -78,7 +78,10 @@ For now, the following binaries have been precompiled and can be downloaded dire
If your platform / architecture is missing, let me know via the [discussions page](https://github.com/fjwillemsen/NativeOverleaf/discussions), or compile it yourself using the instructions below.

## How it works
Using [nativefier](https://github.com/nativefier/nativefier), the Overleaf website is wrapped as an Electron app and injected with JavaScript. While this is not optimally efficient and we may switch to a more efficient framework in the future, it does allow combining the webapp with native features for a large number of supported platforms. <!-- may switch to [Multi](https://github.com/kofigumbs/multi) in the future -->
Using [nativefier](https://github.com/nativefier/nativefier), the Overleaf website is wrapped as an Electron app and injected with JavaScript. While this is not optimally efficient and we may switch to a more efficient framework in the future, it does allow combining the webapp with native features for a large number of supported platforms.
<!-- may switch to [Multi](https://github.com/kofigumbs/multi), but macOS only -->
<!-- qbrt would have been nice had it been further developed (discontinued) -->
<!-- best option: Tauri (like [this](https://github.com/erayerdin/taurapp)) -->

## Troubleshooting
If you have any problem running the app not fixed with these instructions, please [comment on or open an issue](https://github.com/fjwillemsen/NativeOverleaf/issues)!
Expand Down
2 changes: 1 addition & 1 deletion Scripts/appversion.js
@@ -1 +1 @@
const appversion = "1.7.0";
const appversion = "1.7.1";
31 changes: 15 additions & 16 deletions Scripts/preferences.js
Expand Up @@ -19,22 +19,21 @@ const editorThemes_light = {
};

// user preferences (abbreviated UP)
let up_notifications_comments = localStorage.getObject("notifications_comment") || true;
let up_notifications_comment_threads = localStorage.getObject("notifications_comment_response") || true;
let up_notifications_chats = localStorage.getObject("notifications_chat") || true;
let up_notifications_tracked_changes_created = localStorage.getObject("notifications_tracked_changes_created") || true;
let up_notifications_tracked_changes_updated = localStorage.getObject("notifications_tracked_changes_updated") || true;
let up_notifications_tracked_changes_resolved =
localStorage.getObject("notifications_tracked_changes_resolved") || true;
let up_colormode_switching = localStorage.getObject("colormode_switching") || true;
let up_colormode_switching_pdf = localStorage.getObject("colormode_switching_pdf") || true;
let up_overalltheme_dark = localStorage.getObject("overalltheme_dark") || overallThemes_dark[0];
let up_overalltheme_light = localStorage.getObject("overalltheme_light") || overallThemes_light[0];
let up_editortheme_dark = localStorage.getObject("editortheme_dark") || editorThemes_dark[0];
let up_editortheme_light = localStorage.getObject("editortheme_light") || editorThemes_light[0];
let up_wordcount_tracking = localStorage.getObject("wordcount_tracking") || true; // whether wordcount tracking is enabled
let up_wordcount_dailytarget = localStorage.getObject("wordcount_dailytarget") || 200; // net number of words that must be produced daily
let up_wordcount_notificationhour = localStorage.getObject("wordcount_notificationhour") || 18; // hour of the day at which the user is notified whether they have achieved their goal
let up_notifications_comments = localStorage.getObject("notifications_comment", true);
let up_notifications_comment_threads = localStorage.getObject("notifications_comment_response", true);
let up_notifications_chats = localStorage.getObject("notifications_chat", true);
let up_notifications_tracked_changes_created = localStorage.getObject("notifications_tracked_changes_created", true);
let up_notifications_tracked_changes_updated = localStorage.getObject("notifications_tracked_changes_updated", true);
let up_notifications_tracked_changes_resolved = localStorage.getObject("notifications_tracked_changes_resolved", true);
let up_colormode_switching = localStorage.getObject("colormode_switching", true);
let up_colormode_switching_pdf = localStorage.getObject("colormode_switching_pdf");
let up_overalltheme_dark = localStorage.getObject("overalltheme_dark", overallThemes_dark[0]);
let up_overalltheme_light = localStorage.getObject("overalltheme_light", overallThemes_light[0]);
let up_editortheme_dark = localStorage.getObject("editortheme_dark", editorThemes_dark[0]);
let up_editortheme_light = localStorage.getObject("editortheme_light", editorThemes_light[0]);
let up_wordcount_tracking = localStorage.getObject("wordcount_tracking", true); // whether wordcount tracking is enabled
let up_wordcount_dailytarget = localStorage.getObject("wordcount_dailytarget", 200); // net number of words that must be produced daily
let up_wordcount_notificationhour = localStorage.getObject("wordcount_notificationhour", 18); // hour of the day at which the user is notified whether they have achieved their goal

// user preferences boundaries
let up_wordcount_dailytarget_min = 1;
Expand Down
7 changes: 5 additions & 2 deletions Scripts/util.js
Expand Up @@ -4,9 +4,12 @@
Storage.prototype.setObject = function (key, value) {
this.setItem(key, JSON.stringify(value));
};
Storage.prototype.getObject = function (key) {
Storage.prototype.getObject = function (key, defaultvalue = undefined) {
const value = this.getItem(key);
return value && JSON.parse(value);
if (value && value != undefined) {
return JSON.parse(value);
}
return defaultvalue;
};

// function that returns the current local date of the user as a "YYYY-MM-DD" formatted string
Expand Down
24 changes: 24 additions & 0 deletions Tests/util.spec.js
@@ -0,0 +1,24 @@
const { fetchAsync, semanticVersionCompare } = require("../Scripts/util");

describe("Local storage", () => {
test("it should return defautls for keys that do not exist", () => {
const val = localStorage.getObject("test_localstorage_key_undefined", true);
expect(val).toBe(true);
const val_2 = localStorage.getObject("test_localstorage_key_undefined");
expect(val_2).toBe(undefined);
});
test("it should set and retrieve stored values correctly", () => {
localStorage.setObject("test_localstorage_val", "hello world");
const val = localStorage.getObject("test_localstorage_val");
expect(val).toBe("hello world");
});
test("it should set and retrieve stored objects correctly", () => {
const object = {
hello: "world",
};
localStorage.setObject("test_localstorage_object", object);
const val = localStorage.getObject("test_localstorage_object");
console.log(val);
expect(val).toMatchObject(object);
});
});
2 changes: 1 addition & 1 deletion bundled_script.js

Large diffs are not rendered by default.

0 comments on commit 6d980b7

Please sign in to comment.