From e63af2581cf6b5ed35c95f871c05951cc0155ed3 Mon Sep 17 00:00:00 2001 From: Guus van Meerveld <57101832+Guusvanmeerveld@users.noreply.github.com> Date: Mon, 23 Nov 2020 16:30:11 +0100 Subject: [PATCH] Moved to src folder, more progress on keybinds --- index.js | 18 +- json/functions.json | 8 +- package-lock.json | 5 + package.json | 3 +- public/javascripts/keybinds.js | 96 ----------- public/javascripts/settings.js | 36 ---- {public => src}/fonts/Roboto-Bold.ttf | Bin {public => src}/fonts/Roboto-Light.ttf | Bin {public => src}/icon/icon.png | Bin {public => src}/index.html | 0 {public => src}/javascripts/account.js | 0 {public => src}/javascripts/index.js | 0 {public => src}/javascripts/jquery.min.js | 0 src/javascripts/keybinds.js | 159 ++++++++++++++++++ src/javascripts/settings.js | 31 ++++ {public => src}/pages/account.html | 0 {public => src}/pages/devices.html | 0 {public => src}/pages/keybinds.html | 14 +- {public => src}/pages/loadscreen.html | 2 +- {public => src}/pages/macros.html | 0 {public => src}/pages/settings.html | 0 {public => src}/stylesheets/bootstrap.min.css | 0 .../stylesheets/bootstrap.min.css.map | 0 .../icons/iconfont/MaterialIcons-Regular.eot | Bin .../iconfont/MaterialIcons-Regular.ijmap | 0 .../icons/iconfont/MaterialIcons-Regular.svg | 0 .../icons/iconfont/MaterialIcons-Regular.ttf | Bin .../icons/iconfont/MaterialIcons-Regular.woff | Bin .../iconfont/MaterialIcons-Regular.woff2 | Bin .../stylesheets/icons/iconfont/README.md | 0 .../stylesheets/icons/iconfont/codepoints | 0 .../icons/iconfont/material-icons.css | 0 {public => src}/stylesheets/index.css | 0 {public => src}/stylesheets/keybinds.css | 14 ++ {public => src}/stylesheets/main.css | 0 .../stylesheets/material-switches.css | 0 {public => src}/stylesheets/settings.css | 0 37 files changed, 237 insertions(+), 149 deletions(-) delete mode 100644 public/javascripts/keybinds.js delete mode 100644 public/javascripts/settings.js rename {public => src}/fonts/Roboto-Bold.ttf (100%) rename {public => src}/fonts/Roboto-Light.ttf (100%) rename {public => src}/icon/icon.png (100%) rename {public => src}/index.html (100%) rename {public => src}/javascripts/account.js (100%) rename {public => src}/javascripts/index.js (100%) rename {public => src}/javascripts/jquery.min.js (100%) create mode 100644 src/javascripts/keybinds.js create mode 100644 src/javascripts/settings.js rename {public => src}/pages/account.html (100%) rename {public => src}/pages/devices.html (100%) rename {public => src}/pages/keybinds.html (73%) rename {public => src}/pages/loadscreen.html (93%) rename {public => src}/pages/macros.html (100%) rename {public => src}/pages/settings.html (100%) rename {public => src}/stylesheets/bootstrap.min.css (100%) rename {public => src}/stylesheets/bootstrap.min.css.map (100%) rename {public => src}/stylesheets/icons/iconfont/MaterialIcons-Regular.eot (100%) rename {public => src}/stylesheets/icons/iconfont/MaterialIcons-Regular.ijmap (100%) rename {public => src}/stylesheets/icons/iconfont/MaterialIcons-Regular.svg (100%) rename {public => src}/stylesheets/icons/iconfont/MaterialIcons-Regular.ttf (100%) rename {public => src}/stylesheets/icons/iconfont/MaterialIcons-Regular.woff (100%) rename {public => src}/stylesheets/icons/iconfont/MaterialIcons-Regular.woff2 (100%) rename {public => src}/stylesheets/icons/iconfont/README.md (100%) rename {public => src}/stylesheets/icons/iconfont/codepoints (100%) rename {public => src}/stylesheets/icons/iconfont/material-icons.css (100%) rename {public => src}/stylesheets/index.css (100%) rename {public => src}/stylesheets/keybinds.css (84%) rename {public => src}/stylesheets/main.css (100%) rename {public => src}/stylesheets/material-switches.css (100%) rename {public => src}/stylesheets/settings.css (100%) diff --git a/index.js b/index.js index 8c249cf..d335fee 100644 --- a/index.js +++ b/index.js @@ -30,21 +30,20 @@ function createLoadingScreen() { width: 200, height: 400, frame: false, - icon: "public/icon/icon.png", + icon: "src/icon/icon.png", backgroundColor: "#212121", }); loadingScreen.setResizable(false); loadingScreen.on("closed", () => (loadingScreen = null)); - loadingScreen.loadFile("public/pages/loadscreen.html"); + loadingScreen.loadFile("src/pages/loadscreen.html"); } -function createWindow() { +async function createWindow() { let win = new BrowserWindow({ webPreferences: { nodeIntegration: true, webviewTag: true, - // enableBlinkFeatures: false, enableRemoteModule: true, }, frame: false, @@ -53,11 +52,11 @@ function createWindow() { backgroundColor: "#212121", minWidth: 600, minHeight: 600, - icon: "public/icon/icon.png", + icon: "src/icon/icon.png", }); // autoUpdater.checkForUpdates() - win.loadFile("public/index.html"); + win.loadFile("src/index.html"); win.webContents.on("new-window", function (e, url) { e.preventDefault(); @@ -66,8 +65,8 @@ function createWindow() { electronLocalshortcut.register(win, "Ctrl+R", () => { win.reload(); - // app.relaunch() - // app.exit() + // app.relaunch(); + // app.exit(); }); electronLocalshortcut.register(win, "Ctrl+Shift+I", () => { @@ -83,10 +82,11 @@ function createWindow() { } }); - win.once("ready-to-show", () => { + win.webContents.on("dom-ready", () => { if (loadingScreen) { loadingScreen.close(); } + win.maximize(); win.show(); }); } diff --git a/json/functions.json b/json/functions.json index 89f6cb8..f74abe2 100644 --- a/json/functions.json +++ b/json/functions.json @@ -1,8 +1,12 @@ { "Applications": { "description": "Open/Close/Modify your applications", - "openApp": {}, - "closeApp": {} + "open app": { + "description": "Open an application" + }, + "close app": { + "description": "Close an application" + } }, "System": { "description": "Interact with your system" diff --git a/package-lock.json b/package-lock.json index 58e3abd..4d4c649 100644 --- a/package-lock.json +++ b/package-lock.json @@ -582,6 +582,11 @@ "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==" }, + "node-fetch": { + "version": "2.6.1", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.1.tgz", + "integrity": "sha512-V4aYg89jEoVRxRb2fJdAg8FHvI7cEyYdVAh94HH0UIK8oJxUfkjlDQN9RbMx+bEjP7+ggMiFRprSti032Oipxw==" + }, "normalize-url": { "version": "4.5.0", "resolved": "https://registry.npmjs.org/normalize-url/-/normalize-url-4.5.0.tgz", diff --git a/package.json b/package.json index 14f4a59..1d4f045 100644 --- a/package.json +++ b/package.json @@ -14,6 +14,7 @@ "custom-electron-titlebar": "^3.2.5", "electron": "^11.0.2", "electron-localshortcut": "^3.2.1", - "electron-store": "^6.0.1" + "electron-store": "^6.0.1", + "node-fetch": "^2.6.1" } } diff --git a/public/javascripts/keybinds.js b/public/javascripts/keybinds.js deleted file mode 100644 index c051ab5..0000000 --- a/public/javascripts/keybinds.js +++ /dev/null @@ -1,96 +0,0 @@ -const app = require("electron").remote.app; -const path = app.getAppPath(); - -const q = document.querySelector.bind(document); -const c = document.createElement.bind(document); - -const $ = require(path + "/public/javascripts/jquery.min.js"); -const functions = require(path + "/json/functions.json"); - -// Predefine some vars -var keys = {}; -var index; - -// Detect keybinds -$(".keybind-input").on("keyup", (e) => { - keys[e.key.toUpperCase()] = false; - setInput(); -}); - -$(".keybind-input").on("keydown", (e) => { - e.preventDefault(); - - Object.keys(keys).forEach((g) => { - if (!keys[g]) delete keys[g]; - }); - - keys[e.key.toUpperCase()] = true; - setInput(); -}); - -function setInput() { - $(".keybind-input").val(Object.keys(keys).toString().replace(/,/gi, " + ")); -} - -// Configure buttons -$(".add-keybind").click(() => { - index = 0; - $(".dark-overlay").show().addClass("d-flex"); - $(".keybind-input").focus(); -}); - -$(".cancel-btn").click(() => { - $(".dark-overlay").hide().removeClass("d-flex"); - resetKeyAdder(); -}); - -$(".done-btn").click(() => { - switch (index) { - case 0: - $(".keybind-input").hide(); - $(".customize").show().addClass("container-fluid"); - $(".done-btn").html("Done"); - break; - case 1: - $(".dark-overlay").hide().removeClass("d-flex"); - resetKeyAdder(); - - break; - default: - break; - } - index++; -}); - -function resetKeyAdder() { - $(".keybind-input").show().val(""); - $(".customize").hide(); - $(".done-btn").html("Next"); -} - -// Load functions from json -Object.keys(functions).forEach((func) => { - let title = c("div"); - - title.classList.add("category-item"); - title.classList.add("bold"); - title.innerHTML = func.toUpperCase(); - - title.addEventListener("click", () => { - $(".select-function").toggle(); - }); - - let trailing = c("i"); - - trailing.classList.add("category-arrow"); - trailing.classList.add("material-icons"); - trailing.innerHTML = "arrow_forward_ios"; - - let subtitle = c("div"); - subtitle.classList.add("text-muted"); - subtitle.innerHTML = functions[func].description; - - title.appendChild(subtitle); - title.appendChild(trailing); - q(".select-category").appendChild(title); -}); diff --git a/public/javascripts/settings.js b/public/javascripts/settings.js deleted file mode 100644 index f22fde9..0000000 --- a/public/javascripts/settings.js +++ /dev/null @@ -1,36 +0,0 @@ -const Store = require('electron-store'); -const store = new Store(); - -const $ = require("../javascripts/jquery.min.js"); - -const settings = [ - "minimize", - "startup", - "startup-min" -] - -settings.forEach(setting => { - $(`#${setting}-label`).click(() => { - let checked = $(`#${setting}`).prop("checked"); - store.set(setting, checked); - - if (setting == "startup") { - disabledArea(); - } - }); - - $(`#${setting}`).prop("checked", store.get(setting)); -}); - -function disabledArea() { - if (store.get('startup')) { - $(".startup-min").removeClass("disabled-item"); - } - else { - $(".startup-min").addClass("disabled-item"); - $("#startup-min").prop("checked", false); - store.set("startup-min", false); - } -} - -disabledArea(); \ No newline at end of file diff --git a/public/fonts/Roboto-Bold.ttf b/src/fonts/Roboto-Bold.ttf similarity index 100% rename from public/fonts/Roboto-Bold.ttf rename to src/fonts/Roboto-Bold.ttf diff --git a/public/fonts/Roboto-Light.ttf b/src/fonts/Roboto-Light.ttf similarity index 100% rename from public/fonts/Roboto-Light.ttf rename to src/fonts/Roboto-Light.ttf diff --git a/public/icon/icon.png b/src/icon/icon.png similarity index 100% rename from public/icon/icon.png rename to src/icon/icon.png diff --git a/public/index.html b/src/index.html similarity index 100% rename from public/index.html rename to src/index.html diff --git a/public/javascripts/account.js b/src/javascripts/account.js similarity index 100% rename from public/javascripts/account.js rename to src/javascripts/account.js diff --git a/public/javascripts/index.js b/src/javascripts/index.js similarity index 100% rename from public/javascripts/index.js rename to src/javascripts/index.js diff --git a/public/javascripts/jquery.min.js b/src/javascripts/jquery.min.js similarity index 100% rename from public/javascripts/jquery.min.js rename to src/javascripts/jquery.min.js diff --git a/src/javascripts/keybinds.js b/src/javascripts/keybinds.js new file mode 100644 index 0000000..24a678a --- /dev/null +++ b/src/javascripts/keybinds.js @@ -0,0 +1,159 @@ +const app = require("electron").remote.app; +const path = app.getAppPath(); + +const q = document.querySelector.bind(document); +const c = document.createElement.bind(document); + +const $ = require(path + "/src/javascripts/jquery.min.js"); +const functions = require(path + "/json/functions.json"); + +// Predefine some vars +var keys = {}, + showsFunctions = {}, + keybind; + +// Detect keybinds +$(".keybind-input").on("keyup", (e) => { + keys[e.key.toUpperCase()] = false; + setInput(); +}); + +$(".keybind-input").on("keydown", (e) => { + e.preventDefault(); + + Object.keys(keys).forEach((g) => { + if (!keys[g]) delete keys[g]; + }); + + keys[e.key.toUpperCase()] = true; + setInput(); +}); + +function setInput() { + keybind = Object.keys(keys).join(" + "); + + if (Object.values(keys).filter((k) => k).length == 0) { + $(".keybind-input").hide(); + $(".customize").show(); + } + + $(".show-keybind").html(keybind); + $(".keybind-input").val(keybind); +} + +// Configure buttons +$(".add-keybind").click(() => { + $(".dark-overlay").show().addClass("d-flex"); + $(".keybind-input").show().focus(); +}); + +$(".cancel-btn").click(resetKeyAdder); +$(".done-btn").click(resetKeyAdder); + +$(".change-btn").click(() => { + $(".keybind-input").show().focus().val(""); + $(".customize").hide(); +}); + +function resetKeyAdder() { + $(".dark-overlay").hide().removeClass("d-flex"); + + $(".keybind-input").val(""); + $(".customize").hide(); + $(".done-btn").hide(); + + keybind = null; +} + +// Load functions from json +Object.keys(functions).forEach((cat) => { + let catNoSpace = cat.replace(/ /g, ""); + // Select category + let catagoryItem = createCatagoryItem(cat, catNoSpace), + catagoryFunctions = c("div"), + functionItems = createFunctionItem(functions[cat]); + + q(".select-category").appendChild(catagoryItem); + + catagoryFunctions.classList.add(catNoSpace); + catagoryFunctions.style.display = "none"; + + functionItems.forEach((item) => { + catagoryFunctions.appendChild(item); + }); + + q(".select-function").appendChild(catagoryFunctions); +}); + +function createCatagoryItem(f, noSpace) { + let title = c("div"), + trailing = c("i"), + subtitle = c("div"); + + title.classList.add("category-item"); + title.classList.add("bold"); + title.innerHTML = f.toUpperCase(); + + title.addEventListener("click", () => { + showsFunctions[f] = !showsFunctions[f] ?? true; + + Object.keys(showsFunctions).forEach((i) => { + if (f !== i) { + showsFunctions[i] = false; + $("." + i.replace(/ /g, "")).hide(); + } + }); + + if (showsFunctions[f]) { + $(".select-function").show(); + $("." + noSpace).show(); + } else { + $(".select-function").hide(); + $("." + noSpace).hide(); + } + }); + + trailing.classList.add("category-arrow"); + trailing.classList.add("material-icons"); + trailing.innerHTML = "arrow_forward_ios"; + + subtitle.classList.add("text-muted"); + subtitle.innerHTML = functions[f].description; + + title.appendChild(subtitle); + title.appendChild(trailing); + + return title; +} + +function createFunctionItem(f) { + delete f.description; + var result = []; + + Object.keys(f).forEach((func) => { + result.push(createFunctionItem(func, f[func].description)); + }); + + return result; +} + +function createListItem(title, subtitle) { + let titleEl = c("div"), + trailing = c("i"), + subtitleEl = c("div"); + + titleEl.classList.add("category-item"); + titleEl.classList.add("bold"); + titleEl.innerHTML = title.toUpperCase(); + + trailing.classList.add("category-arrow"); + trailing.classList.add("material-icons"); + trailing.innerHTML = "arrow_forward_ios"; + + subtitleEl.classList.add("text-muted"); + subtitleEl.innerHTML = subtitle; + + titleEl.appendChild(trailing); + titleEl.appendChild(subtitleEl); + return titleEl; +} diff --git a/src/javascripts/settings.js b/src/javascripts/settings.js new file mode 100644 index 0000000..35f32be --- /dev/null +++ b/src/javascripts/settings.js @@ -0,0 +1,31 @@ +const Store = require("electron-store"); +const store = new Store(); + +const $ = require("./jquery.min.js"); + +const settings = ["minimize", "startup", "startup-min"]; + +settings.forEach((setting) => { + $(`#${setting}-label`).click(() => { + let checked = $(`#${setting}`).prop("checked"); + store.set(setting, checked); + + if (setting == "startup") { + disabledArea(); + } + }); + + $(`#${setting}`).prop("checked", store.get(setting)); +}); + +function disabledArea() { + if (store.get("startup")) { + $(".startup-min").removeClass("disabled-item"); + } else { + $(".startup-min").addClass("disabled-item"); + $("#startup-min").prop("checked", false); + store.set("startup-min", false); + } +} + +disabledArea(); diff --git a/public/pages/account.html b/src/pages/account.html similarity index 100% rename from public/pages/account.html rename to src/pages/account.html diff --git a/public/pages/devices.html b/src/pages/devices.html similarity index 100% rename from public/pages/devices.html rename to src/pages/devices.html diff --git a/public/pages/keybinds.html b/src/pages/keybinds.html similarity index 73% rename from public/pages/keybinds.html rename to src/pages/keybinds.html index 6c578fa..5b681b5 100644 --- a/public/pages/keybinds.html +++ b/src/pages/keybinds.html @@ -17,13 +17,19 @@