Skip to content
Permalink
Browse files

Merge pull request #497 from lusbenjamin/data-settings-tab

Arena Data Settings Tab
  • Loading branch information...
Manuel-777 committed Jul 24, 2019
2 parents fe5fe27 + a037491 commit d4df2574c59508cb2fa1485003a2efb7167da35b
BIN +3.13 KB images/open.png
Binary file not shown.
@@ -714,6 +714,14 @@ exports.MAIN_COLLECTION = 5;
exports.MAIN_SETTINGS = 6;
exports.MAIN_UPDATE = 9;

exports.SETTINGS_BEHAVIOUR = 1;
exports.SETTINGS_ARENA_DATA = 2;
exports.SETTINGS_OVERLAY = 3;
exports.SETTINGS_VISUAL = 4;
exports.SETTINGS_PRIVACY = 5;
exports.SETTINGS_ABOUT = 6;
exports.SETTINGS_LOGIN = 7;

// Date constants
exports.DATE_LAST_DAY = "Last 24 Hours";
exports.DATE_LAST_30 = "Last 30 Days";
@@ -26,7 +26,9 @@ const playerDataDefault = {
arenaVersion: "",
offline: false,
patreon: false,
patreon_tier: 0
patreon_tier: 0,
last_log_timestamp: null,
last_log_format: ""
};

const overlayCfg = {
@@ -296,6 +298,8 @@ class PlayerData {
"toolVersion",
"auto_login",
"launch_to_tray",
"logUri",
"log_locale_format",
"remember_me",
"beta_channel"
];
@@ -2,12 +2,12 @@
global
debugLog
firstPass
logLanguage
*/
// Utility functions that belong only to background
const { ipcRenderer: ipc } = require("electron");
const _ = require("lodash");
const parse = require("date-fns").parse;
const parse = require("date-fns/parse");
const isValid = require("date-fns/isValid");

const {
IPC_BACKGROUND,
@@ -18,7 +18,7 @@ const pd = require("../shared/player-data.js");

// These were tested briefly , but hey are all taken from actual logs
// At most some format from date-fns could be wrong;
// https://date-fns.org/v2.0.0-alpha.7/docs/parse
// https://date-fns.org/v2.0.0-alpha.27/docs/parse
let dateLangs = [
"dd.MM.yyyy HH:mm:ss",
"dd/MM/yyyy HH:mm:ss",
@@ -30,26 +30,31 @@ let dateLangs = [

// throws an error if it fails
function parseWotcTime(dateStr) {
let date = parse(dateStr, dateLangs[0], new Date());

// This is to detect language when the one read does not match or logLanguage is not yet set
// Defaults to current time if none matches
if (!date || isNaN(date.getTime())) {
dateLangs.forEach(lang => {
let test = parse(dateStr, lang, new Date());
if (test && !isNaN(test.getTime())) {
//logLanguage = lang;
//console.log(`Log datetime language detected: ${lang}`, dateStr, test);
date = test;
}
});
// Attempt parsing with custom app-level setting first
if (pd.settings.log_locale_format) {
const lang = pd.settings.log_locale_format;
// console.log(`Log datetime custom language attempt: ${lang}`);
const test = parse(dateStr, lang, new Date());
if (isValid(test) && !isNaN(test.getTime())) {
//console.log(`Log datetime language detected: ${lang}`, dateStr, test);
setData({ last_log_format: lang });
return test;
}
}

if (!date || isNaN(date.getTime())) {
// console.log(`Invalid date ('${dateStr}') - using current date as backup.`);
date = new Date();
}
return date;
// Try parsing input with each format (in order) and return first valid result
dateLangs.forEach(lang => {
const test = parse(dateStr, lang, new Date());
if (isValid(test) && !isNaN(test.getTime())) {
//console.log(`Log datetime language detected: ${lang}`, dateStr, test);
setData({ last_log_format: lang });
return test;
}
});

// Defaults to current time if none matches
// console.log(`Invalid date ('${dateStr}') - using current date as backup.`);
return new Date();
}

function normaliseFields(iterator) {
@@ -94,7 +94,8 @@ const rememberCfg = {
auto_login: false,
launch_to_tray: false,
remember_me: true,
beta_channel: false
beta_channel: false,
log_locale_format: ""
}
};

@@ -248,7 +249,7 @@ ipc.on("start_background", function() {
// first time during bootstrapping that we load
// app-level settings into singletons
const appSettings = rstore.get("settings");
const settings = { ...pd.settings, ...appSettings };
const settings = { ...pd.settings, ...appSettings, logUri };
setData({ settings }, false);
ipc_send("initial_settings", settings);

@@ -921,6 +922,7 @@ function onLogEntryFound(entry) {
default:
break;
}
setData({ last_log_timestamp: entry.timestamp });
} catch (err) {
console.log(entry.label, entry.position, entry.json());
console.error(err);
@@ -76,7 +76,7 @@ relative-time, local-time {
background-image: url(../images/logo_big.png);
}

.release_notes_link {
.release_notes_link, .link {
cursor: pointer;
text-decoration: underline;
}
@@ -2803,7 +2803,17 @@ a:hover {
-webkit-transition: all .2s ease-in-out;
}

.copy_button:hover {
.open_button {
margin: auto 0 auto 16px;
cursor: pointer;
width: 28px;
height: 28px;
opacity: 0.5;
background: url(../images/open.png) no-repeat center;
-webkit-transition: all .2s ease-in-out;
}

.copy_button:hover, .open_button:hover {
opacity: 1;
}

@@ -1,6 +1,7 @@
const fs = require("fs");
const path = require("path");
const { app, ipcRenderer: ipc, remote } = require("electron");
const { dialog } = remote;
const _ = require("lodash");
const anime = require("animejs");
const striptags = require("striptags");
@@ -811,6 +812,77 @@ function showDatepicker(defaultDate, onChange = () => {}, pickerOptions = {}) {
openDialog(cont);
}

//
exports.renderLogInput = renderLogInput;
function renderLogInput(section) {
const logUriLabel = createLabel(["but_container_label"], "Arena Log:", {
for: "settings_log_uri"
});
logUriLabel.style.width = "100%";
logUriLabel.appendChild(createDiv(["open_button"]));
const logUriCont = createDiv(["input_container"]);
logUriCont.style.margin = "3px";
logUriCont.style.width = "70%";
const logUriInput = createInput([], "", {
type: "text",
id: "settings_log_uri",
autocomplete: "off",
placeholder: pd.settings.logUri,
value: pd.settings.logUri
});
let canShowFileDialog = true;
logUriLabel.addEventListener("click", () => {
if (!canShowFileDialog) return;
// ignore clicks inside actual input field
if (document.activeElement === logUriInput) return;
canShowFileDialog = false;
const paths = dialog.showOpenDialog(remote.getCurrentWindow(), {
title: "Arena Log Location",
defaultPath: pd.settings.logUri,
buttonLabel: "Select",
filters: [
{ name: "Text", extensions: ["txt", "text"] },
{ name: "All Files", extensions: ["*"] }
],
properties: ["openFile"]
});
if (paths && paths.length && paths[0]) {
logUriInput.focus();
logUriInput.value = paths[0];
logUriInput.blur();
}
canShowFileDialog = true;
});
logUriInput.addEventListener("keyup", e => {
if (e.keyCode === 13) logUriInput.blur();
});
logUriInput.addEventListener("focusout", () => {
if (logUriInput.value === pd.settings.logUri) return;
if (
confirm(
"Changing the Arena log location requires a restart, are you sure?"
)
) {
ipcSend("set_log", byId("settings_log_uri").value);
remote.app.relaunch();
remote.app.exit(0);
} else {
logUriInput.value = pd.settings.logUri;
}
});
logUriCont.appendChild(logUriInput);
logUriLabel.appendChild(logUriCont);
section.appendChild(logUriLabel);
section.appendChild(
createDiv(
["settings_note"],
`<p><i>This temporary text file generated by WotC contains the raw
output from your most recent (or current) Arena session. This is the
primary source of user data.</i></p>`
)
);
}

//
exports.formatPercent = formatPercent;
function formatPercent(value, config = { maximumSignificantDigits: 2 }) {
@@ -19,7 +19,6 @@ const anime = require("animejs");
require("time-elements");

const {
DATE_LAST_30,
DATE_SEASON,
EASING_DEFAULT,
HIDDEN_PW,
@@ -32,14 +31,11 @@ const {
MAIN_ECONOMY,
MAIN_COLLECTION,
MAIN_SETTINGS,
MAIN_UPDATE
MAIN_UPDATE,
SETTINGS_ABOUT
} = require("../shared/constants");
const pd = require("../shared/player-data");
const {
createDiv,
createInput,
queryElements: $$
} = require("../shared/dom-fns");
const { createDiv, queryElements: $$ } = require("../shared/dom-fns");
const {
compare_cards,
get_deck_colors,
@@ -49,12 +45,12 @@ const {

const {
changeBackground,
closeDialog,
getLocalState,
hideLoadingBars,
ipcSend,
openDialog,
pop,
renderLogInput,
resetMainContainer,
setLocalState,
showLoadingBars
@@ -283,7 +279,7 @@ ipc.on("player_data_refresh", () => {
//
ipc.on("set_update_state", function(event, arg) {
if (sidebarActive === MAIN_UPDATE) {
openSettingsTab(5);
openSettingsTab(SETTINGS_ABOUT);
}
});

@@ -451,39 +447,9 @@ ipc.on("no_log", function(event, arg) {
'</div><div class="message_sub_16 white">if it does, try closing MTG Arena and deleting it.</div>';
} else if (!logDialogOpen) {
logDialogOpen = true;

const cont = createDiv(["dialog_content"]);
cont.style.width = "600px";

const title = createDiv(["share_title"], "Enter output_log.txt location:");
title.style.margin = "12px auto";
cont.appendChild(title);
const icd = createDiv(["share_input_container"]);
const sin = createInput([], "", {
id: "log_input",
autofocus: true,
autocomplete: "off",
value: arg
});
sin.style.borderRadius = "3px";
sin.style.height = "28px";
sin.style.fontSize = "14px";
sin.style.margin = 0;
icd.appendChild(sin);
cont.appendChild(icd);

const but = createDiv(["button_simple"], "Save");
but.style.marginLeft = "auto";
but.style.marginRight = "auto";
but.addEventListener("click", function() {
ipcSend("set_log", byId("log_input").value);
closeDialog();
setTimeout(() => {
logDialogOpen = false;
}, 300);
});
cont.appendChild(but);

cont.style.width = "650px";
renderLogInput(cont);
openDialog(cont, () => (logDialogOpen = false));
}
});
@@ -559,7 +525,7 @@ function force_open_about() {
duration: 350
});
$$(".top_nav_item").forEach(el => el.classList.remove("item_selected"));
openSettingsTab(5, 0);
openSettingsTab(SETTINGS_ABOUT, 0);
}

//

0 comments on commit d4df257

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