/*
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */

var gui = require('nw.gui');
var linewidth = 48;
var devtype = "epson";
var device = "/dev/usb/lp0";
var settingsValid = true;
var win = gui.Window.get();
var tray = new nw.Tray({
    title: 'NickelBridge',
    tooltip: 'Open NickelBridge configuration',
    icon: 'public/assets/img/logo_64.png'
});

function loadSettings() {
    if (localStorage.getItem("linewidth") !== null && Number.parseInt(localStorage.getItem("linewidth")) != Number.NaN) {
        linewidth = Number.parseInt(localStorage.getItem("linewidth"));
    } else {
        settingsValid = false;
    }
    if (localStorage.getItem("devtype") !== null) {
        devtype = localStorage.getItem("devtype");
        if (devtype != "epson" && devtype != "star") {
            devtype = "epson";
            settingsValid = false;
        }
    } else {
        settingsValid = false;
    }
    if (localStorage.getItem("device") !== null && localStorage.getItem("device") != "") {
        device = localStorage.getItem("device");
    } else {
        settingsValid = false;
    }
}

loadSettings();

win.on('minimize', function () {
    win.hide();
});
tray.on('click', function () {
    win.show();
});

if (settingsValid === true) {
    win.hide();
}