From 2186a7afc41f0b30e54876ed045b056ed6e42afd Mon Sep 17 00:00:00 2001 From: Jason Stallings Date: Sat, 28 May 2016 18:57:01 -0500 Subject: [PATCH] New settings dialog and other changes. --- app.js | 99 ++++++++++++++++++++++---------- g.png => assets/img/g.png | Bin load.gif => assets/img/load.gif | Bin tray.png => assets/img/tray.png | Bin assets/view/settings.html | 28 +++++++++ index.html | 14 ++--- package.json | 1 + 7 files changed, 104 insertions(+), 38 deletions(-) rename g.png => assets/img/g.png (100%) rename load.gif => assets/img/load.gif (100%) rename tray.png => assets/img/tray.png (100%) create mode 100644 assets/view/settings.html diff --git a/app.js b/app.js index bfc41d2..e416b2d 100644 --- a/app.js +++ b/app.js @@ -9,12 +9,16 @@ var AutoLaunch = require("auto-launch"); var runatstartup = new AutoLaunch( { - name: "Hot Gifs", + name: "Hot Gifs", isHidden: "false" }); -var fs = require("fs"); -var config = JSON.parse(fs.readFileSync("config.json", "utf8")); +var config = require("./config.json"); + +//Load user settings. +var Configstore = require("configstore"); +var pkg = require("./package.json"); +var settings = new Configstore(pkg.name, {"opt-out": false, "check-for-updates": true}); var keydown = 0; var showing = 0; @@ -37,7 +41,7 @@ if (process.platform === "darwin") //Create tray icon. var tray = new gui.Tray( { - icon: "tray.png", + icon: "assets/img/tray.png", iconsAreTemplates: false }); @@ -68,6 +72,12 @@ if (process.platform === "darwin") menu.append(startup); } +menu.append(new gui.MenuItem( +{ + label: "Settings", + click: settingsClicked +})); + menu.append(new gui.MenuItem( { type: "separator" @@ -91,9 +101,6 @@ var clipboard = gui.Clipboard.get(); var translate_endpoint = "http://api.giphy.com"; var api_version = "v1"; -//Settings -var shouldcheckforupdate = 1; - //Hotkey Stuff var option = { key: "Ctrl+Alt+G", @@ -109,7 +116,7 @@ var option = { $("#s").focus(); }, 0); - visitor.event("User interaction", "Window Open").send(); + if (!settings.get('opt-out')) visitor.event("User interaction", "Window Open").send(); }, failed: function(msg) { @@ -132,7 +139,7 @@ runatstartup.isEnabled(function(found) $(document).on("ready", function() { - if (shouldcheckforupdate) + if (settings.get('check-for-updates')) { checkforupdate(); } @@ -147,24 +154,24 @@ $(document).on("ready", function() //If the instruction text isn't showing, and it's the preview instructions, show it. if (!instructionsshowing() && $("#instructions").text() == previewtext) $("#instructions").fadeIn(); - + //Tab to skip gif. if (e.keyCode == 9 && keydown) { //Hide skip instructions if they're currently showing. if (instructionsshowing()) $("#instructions").fadeOut(); - + e.preventDefault(); search(); - - visitor.event("User interaction", "Skip").send(); + + if (!settings.get('opt-out')) visitor.event("User interaction", "Skip").send(); return; } - + //Enter is currently held down. if (keydown) return; - + //Search if enter is pressed down. if (e.keyCode == 13) { @@ -174,12 +181,12 @@ $(document).on("ready", function() $("#instructions").text(skiptext); $("#instructions").fadeIn(); }); - + keydown = 1; search(); } }); - + $("#s").keyup(function(e) { //Hide window if enter is released. @@ -199,7 +206,7 @@ $(document).on("ready", function() { //Close the dialog if esc is pressed. if (e.keyCode == 27) - { + { closeGUI(); } }); @@ -208,11 +215,11 @@ $(document).on("ready", function() function search() { var keyword = $("#s").val(); - - //Time Giphy response. - var start = new Date().getTime(); - - $("#i").attr("src", "load.gif"); + + //Time Giphy response. + var start = new Date().getTime(); + + $("#i").attr("src", "assets/img/load.gif"); $("#scene").show(); url = translate_endpoint + "/" + api_version + "/gifs/translate?s=" + encodeURIComponent(keyword) + "&api_key=" + config.key; $.ajax( @@ -221,11 +228,11 @@ function search() url: url }).done(function(res) { - var end = new Date().getTime(); - var time = end - start; - visitor.timing("User interaction", "Time to return Giphy results", time).send(); - - //If results are found. + var end = new Date().getTime(); + var time = end - start; + if (!settings.get('opt-out')) visitor.timing("User interaction", "Time to return Giphy results", time).send(); + + //If results are found. if (typeof res.data.images != "undefined") { clipboard.set(res.data.images.original.url, "text"); @@ -233,7 +240,7 @@ function search() { win.height = 270; $("#i").attr("src", res.data.images.downsized_medium.url); - visitor.event("User interaction", "Preview").send(); + if (!settings.get('opt-out')) visitor.event("User interaction", "Preview").send(); } } else @@ -247,10 +254,10 @@ function search() $("#instructions").fadeIn(); }); } - visitor.event("User interaction", "No Results", keyword).send(); + if (!settings.get('opt-out')) visitor.event("User interaction", "No Results", keyword).send(); } }); - visitor.event("User interaction", "Search", keyword).send(); + if (!settings.get('opt-out')) visitor.event("User interaction", "Search", keyword).send(); } function closeGUI() @@ -298,3 +305,33 @@ function startupClicked() runatstartup.disable(); } } + +function settingsClicked() +{ + var dialog = gui.Window.open('assets/view/settings.html', + { + width: 300, + height: 100, + toolbar: false + }); + + dialog.on("loaded", function() + { + // Load settings. + for (var x in settings.all) + { + dialog.window.$('input[name="' + x +'"]').prop('checked', settings.all[x]); + } + + // On submit, save the settings. + dialog.window.$("form").on("submit", function(event) + { + event.preventDefault(); + dialog.window.$('input:checkbox').map(function() + { + settings.set(this.name, this.checked ? true : false); + }); + dialog.close(); + }); + }); +} diff --git a/g.png b/assets/img/g.png similarity index 100% rename from g.png rename to assets/img/g.png diff --git a/load.gif b/assets/img/load.gif similarity index 100% rename from load.gif rename to assets/img/load.gif diff --git a/tray.png b/assets/img/tray.png similarity index 100% rename from tray.png rename to assets/img/tray.png diff --git a/assets/view/settings.html b/assets/view/settings.html new file mode 100644 index 0000000..3cb9af6 --- /dev/null +++ b/assets/view/settings.html @@ -0,0 +1,28 @@ + + + + + + + + Settings + + + + + + + + +
+ Automatically check for updates.
+ Opt-out of anonymous usage logging.
+ +
+ + \ No newline at end of file diff --git a/index.html b/index.html index 6d4ace1..01c9749 100644 --- a/index.html +++ b/index.html @@ -30,13 +30,13 @@ width: 498px; text-align:center; outline: none; - background:url(g.png) no-repeat right bottom; + background:url(assets/img/g.png) no-repeat right bottom; background-size: 75px; } - + img { - display:block; + display:block; margin: 0 auto; max-height: 200px; max-width: 100%; @@ -45,18 +45,18 @@ top: 50%; -webkit-transform: translateY(-50%); } - + #scene { height: 200px; width: 100%; display: none; } - + #instructions { display: none; - position: fixed; + position: fixed; left: 0px; top: 45px; font-size: 12px; @@ -69,7 +69,7 @@
- +
Hold enter to preview.
diff --git a/package.json b/package.json index d37a016..7381484 100644 --- a/package.json +++ b/package.json @@ -17,6 +17,7 @@ "license": "GPL-3.0", "dependencies": { "auto-launch": "^0.1.18", + "configstore": "^2.0.0", "universal-analytics": "^0.3.9" }, "devDependencies": {