Skip to content
Permalink
Browse files

Merge pull request #265 from lusbenjamin/settings-tweaks

Settings tweaks
  • Loading branch information...
Manuel-777 committed Apr 21, 2019
2 parents d72e804 + fd38185 commit 6736dedb567205127aea6142d4982be12960b8c7
Showing with 42 additions and 19 deletions.
  1. +24 −7 window_background/background.js
  2. +18 −12 window_main/renderer.js
@@ -279,16 +279,18 @@ function ipc_send(method, arg, to = windowRenderer) {

//
ipc.on("save_app_settings", function(event, arg) {
ipc_send("show_loading");
const rSettings = rstore.get("settings");
const updated = { ...rSettings, ...arg };

if (!updated.remember_me) {
rstore.set("email", "");
rstore.set("token", "");
}


loadSettings(updated);
rstore.set("settings", updated);
loadSettings();
ipc_send("hide_loading");
});

//
@@ -380,8 +382,10 @@ ipc.on("overlayBounds", function(event, obj) {

//
ipc.on("save_user_settings", function(event, settings) {
ipc_send("show_loading");
loadSettings(settings);
store.set("settings", settings);
loadSettings();
ipc_send("hide_loading");
});

//
@@ -391,17 +395,20 @@ ipc.on("delete_data", function() {

//
ipc.on("delete_course", function(event, arg) {
ipc_send("show_loading");
var i = events.courses.indexOf(arg);
if (i > -1) {
events.courses.splice(i, 1);
store.set("courses_index", events.courses);
store.delete(arg);
}
ipc_send("hide_loading");
//console.log("Delete ", arg);
});

//
ipc.on("delete_deck", function(event, arg) {
ipc_send("show_loading");
var i = decks.index.indexOf(arg);
if (i > -1) {
decks.index.splice(i, 1);
@@ -412,11 +419,13 @@ ipc.on("delete_deck", function(event, arg) {
// If we do it imediately it looks awful
setTimeout(() => {
ipc_send("set_decks", JSON.stringify(decks));
ipc_send("hide_loading");
}, 200);
});

//
ipc.on("delete_match", function(event, arg) {
ipc_send("show_loading");
var i = history.matches.indexOf(arg);
if (i > -1) {
history.matches.splice(i, 1);
@@ -429,6 +438,7 @@ ipc.on("delete_match", function(event, arg) {
store.set("draft_index", drafts.matches);
store.delete(arg);
}
ipc_send("hide_loading");
});

//
@@ -893,13 +903,20 @@ function syncUserData(data) {
}

// Loads and combines settings variables, sends result to display
function loadSettings() {
// Blends together default, user, and app config
function loadSettings(dirtySettings = {}) {
// Blends together default, user, app, and optional dirty config
// "dirty" config may be a subset, which allows early UI updates
// to make UI responsive without waiting for slow store IO
// Since settings have migrated between areas, collisions happen
// Order of precedence is: app > user > defaults
// Order of precedence is: dirty > app > user > defaults
const settings = store.get("settings");
const rSettings = rstore.get("settings");
const _settings = { ...defaultCfg.settings, ...settings, ...rSettings };
const _settings = {
...defaultCfg.settings,
...settings,
...rSettings,
...dirtySettings
};

if (_settings.decks_last_used == undefined) _settings.decks_last_used = [];

@@ -973,10 +973,16 @@ function showLoadingBars() {
$$(".main_loading")[0].style.display = "block";
}

//
ipc.on("show_loading", () => showLoadingBars());

function hideLoadingBars() {
$$(".main_loading")[0].style.display = "none";
}

//
ipc.on("hide_loading", () => hideLoadingBars());

//
ipc.on("set_draft_link", function(event, arg) {
hideLoadingBars();
@@ -2115,7 +2121,7 @@ function open_settings(openSection) {
);
add_checkbox(
section,
"Persistent overlay <i>(useful for OBS setup)</i>",
"Persistent overlay&nbsp;<i>(useful for OBS setup)</i>",
"settings_showoverlayalways",
settings.show_overlay_always
);
@@ -2230,7 +2236,7 @@ function open_settings(openSection) {

colorPick.on("move.spectrum", function(e, color) {
$(".main_wrapper").css("background-color", color.toRgbString());
updateUsersettings();
updateUserSettings();
});

label = $('<label class="but_container_label">Cards quality:</label>');
@@ -2280,13 +2286,13 @@ function open_settings(openSection) {
section.append('<div class="settings_title">Privacy</div>');
add_checkbox(
section,
"Anonymous sharing <i>(makes your username anonymous on Explore)</i>",
"Anonymous sharing&nbsp;<i>(makes your username anonymous on Explore)</i>",
"settings_anon_explore",
settings.anon_explore
);
add_checkbox(
section,
"Online sharing <i>(when disabled, blocks any connections with our servers)</i>",
"Online sharing&nbsp;<i>(when disabled, blocks any connections with our servers)</i>",
"settings_senddata",
settings.send_data
);
@@ -2440,12 +2446,12 @@ function open_settings(openSection) {

url_input.on("keyup", function(e) {
if (e.keyCode == 13) {
updateUsersettings();
updateUserSettings();
}
});

export_input.on("keyup", function() {
updateUsersettings();
updateUserSettings();
});

$(".sliderA").off();
@@ -2468,7 +2474,7 @@ function open_settings(openSection) {

$(".sliderA").on("click mouseup", function() {
cardSizePos = Math.round(parseInt(this.value));
updateUsersettings();
updateUserSettings();
});

$(".sliderB").off();
@@ -2482,7 +2488,7 @@ function open_settings(openSection) {

$(".sliderB").on("click mouseup", function() {
overlayAlpha = alphaFromTransparency(parseInt(this.value));
updateUsersettings();
updateUserSettings();
});

$(".sliderC").on("click mousemove", function() {
@@ -2496,7 +2502,7 @@ function open_settings(openSection) {

$(".sliderC").on("click mouseup", function() {
overlayAlphaBack = alphaFromTransparency(parseInt(this.value));
updateUsersettings();
updateUserSettings();
});

$(".sliderD").off();
@@ -2508,7 +2514,7 @@ function open_settings(openSection) {

$(".sliderD").on("click mouseup", function() {
overlayScale = parseInt(this.value);
updateUsersettings();
updateUserSettings();
});

$(".sliderSoundVolume").off();
@@ -2519,7 +2525,7 @@ function open_settings(openSection) {
);
let { Howl, Howler } = require("howler");
let sound = new Howl({ src: ["../sounds/blip.mp3"] });
updateUsersettings();
updateUserSettings();
Howler.volume(settings.sound_priority_volume);
sound.play();
});
@@ -2597,7 +2603,7 @@ function changeQuality(dom) {
cardQuality = "normal";
}
dom.innerHTML = cardQuality;
updateUsersettings();
updateUserSettings();
open_settings(lastSettingsSection);
}

0 comments on commit 6736ded

Please sign in to comment.
You can’t perform that action at this time.