diff --git a/index.js b/index.js index eb58514..8c249cf 100644 --- a/index.js +++ b/index.js @@ -1,16 +1,23 @@ -const { app, BrowserWindow, globalShortcut, shell, autoUpdater } = require('electron'); -const electronLocalshortcut = require('electron-localshortcut'); -const Store = require('electron-store'); +const { + app, + BrowserWindow, + globalShortcut, + shell, + autoUpdater, +} = require("electron"); + +const electronLocalshortcut = require("electron-localshortcut"); +const Store = require("electron-store"); const store = new Store(); function initApp() { - store.set("init", true); + store.set("init", true); - store.set("minimize", true); - store.set("startup", true); + store.set("minimize", true); + store.set("startup", true); } -const AutoLaunch = require('auto-launch'); +const AutoLaunch = require("auto-launch"); // const server = 'https://cdn.g-vm.nl' // const url = `${server}/update/${process.platform}/${app.getVersion()}` @@ -19,101 +26,99 @@ const AutoLaunch = require('auto-launch'); let loadingScreen; function createLoadingScreen() { - loadingScreen = new BrowserWindow({ - width: 200, - height: 400, - frame: false, - icon: "public/icon/icon.png", - backgroundColor: '#212121' - }); - - loadingScreen.setResizable(false); - loadingScreen.on('closed', () => loadingScreen = null); - loadingScreen.loadFile('public/pages/loadscreen.html') -}; - -function createWindow() { - - let win = new BrowserWindow({ - webPreferences: { - nodeIntegration: true, - webviewTag: true, - // enableBlinkFeatures: false, - enableRemoteModule: true - }, - frame: false, - show: false, - titleBarStyle: "hidden", - backgroundColor: '#212121', - 'minWidth': 600, - 'minHeight': 600, - icon: "public/icon/icon.png" - }) - - // autoUpdater.checkForUpdates() - win.loadFile('public/index.html') - - win.webContents.on('new-window', function (e, url) { - e.preventDefault(); - shell.openExternal(url); - }); - - electronLocalshortcut.register(win, 'Ctrl+R', () => { - win.reload() - // app.relaunch() - // app.exit() - }); - - electronLocalshortcut.register(win, 'Ctrl+Shift+I', () => { - win.webContents.openDevTools() - }); - - win.on("close", e => { - if (store.get('minimize')) { - e.preventDefault(); - if (!app.isQuiting) { - win.hide(); - } - } - }) - - win.once('ready-to-show', () => { - if (loadingScreen) { - loadingScreen.close(); - } - win.show() - }) + loadingScreen = new BrowserWindow({ + width: 200, + height: 400, + frame: false, + icon: "public/icon/icon.png", + backgroundColor: "#212121", + }); + + loadingScreen.setResizable(false); + loadingScreen.on("closed", () => (loadingScreen = null)); + loadingScreen.loadFile("public/pages/loadscreen.html"); } -app.on('ready', () => { - createLoadingScreen() - createWindow() - - if (!store.get("init")) { - initApp() - } - - let autoLaunch = new AutoLaunch({ - name: 'Keyzo', - path: app.getPath('exe'), - }); - - if (store.get("startup")) { - autoLaunch.enable(); - } else { - autoLaunch.disable(); +function createWindow() { + let win = new BrowserWindow({ + webPreferences: { + nodeIntegration: true, + webviewTag: true, + // enableBlinkFeatures: false, + enableRemoteModule: true, + }, + frame: false, + show: false, + titleBarStyle: "hidden", + backgroundColor: "#212121", + minWidth: 600, + minHeight: 600, + icon: "public/icon/icon.png", + }); + + // autoUpdater.checkForUpdates() + win.loadFile("public/index.html"); + + win.webContents.on("new-window", function (e, url) { + e.preventDefault(); + shell.openExternal(url); + }); + + electronLocalshortcut.register(win, "Ctrl+R", () => { + win.reload(); + // app.relaunch() + // app.exit() + }); + + electronLocalshortcut.register(win, "Ctrl+Shift+I", () => { + win.webContents.openDevTools(); + }); + + win.on("close", (e) => { + if (store.get("minimize")) { + e.preventDefault(); + if (!app.isQuiting) { + win.hide(); + } } -}) - + }); -app.on('window-all-closed', () => { - if (process.platform !== 'darwin') { - app.quit() + win.once("ready-to-show", () => { + if (loadingScreen) { + loadingScreen.close(); } -}) + win.show(); + }); +} -app.on('activate', () => { - if (BrowserWindow.getAllWindows().length === 0) { - createWindow() - } -}) \ No newline at end of file +app.on("ready", () => { + createLoadingScreen(); + createWindow(); + + if (!store.get("init")) { + initApp(); + } + + let autoLaunch = new AutoLaunch({ + name: "Keyzo", + path: app.getPath("exe"), + }); + + if (store.get("startup")) { + autoLaunch.enable(); + } else { + autoLaunch.disable(); + } +}); + +app.on("window-all-closed", () => { + if (process.platform !== "darwin") { + app.quit(); + } +}); + +app.on("activate", () => { + if (BrowserWindow.getAllWindows().length === 0) { + createWindow(); + } +}); diff --git a/json/functions.json b/json/functions.json new file mode 100644 index 0000000..89f6cb8 --- /dev/null +++ b/json/functions.json @@ -0,0 +1,16 @@ +{ + "Applications": { + "description": "Open/Close/Modify your applications", + "openApp": {}, + "closeApp": {} + }, + "System": { + "description": "Interact with your system" + }, + "Keys": { + "description": "Output keyboard inputs" + }, + "System Functions": { + "description": "Some predefined functions" + } +} \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index aaa7b5a..58e3abd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -34,14 +34,14 @@ } }, "@types/node": { - "version": "12.12.64", - "resolved": "https://registry.npmjs.org/@types/node/-/node-12.12.64.tgz", - "integrity": "sha512-UV1/ZJMC+HcP902wWdpC43cAcGu0IQk/I5bXjP2aSuCjsk3cE74mDvFrLKga7oDC170ugOAYBwfT4DSQW3akDA==" + "version": "12.19.6", + "resolved": "https://registry.npmjs.org/@types/node/-/node-12.19.6.tgz", + "integrity": "sha512-U2VopDdmBoYBmtm8Rz340mvvSz34VgX/K9+XCuckvcLGMkt3rbMX8soqFOikIPlPBc5lmw8By9NUK7bEFSBFlQ==" }, "ajv": { - "version": "6.12.5", - "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.5.tgz", - "integrity": "sha512-lRF8RORchjpKG50/WFf8xmg7sgCLFiYNNnqdKflk63whMQcWR5ngGjiSXkL9bjxy6B2npOK2HSMN49jEBMSkag==", + "version": "6.12.6", + "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.6.tgz", + "integrity": "sha512-j3fVLgvTo527anyYyJOGTYJbG+vnnQYvE0m5mmkc1TK+nxAppkCLMIL0aZ4dblVCNoGShhm+kzE4ZUykBoMg4g==", "requires": { "fast-deep-equal": "^3.1.1", "fast-json-stable-stringify": "^2.0.0", @@ -55,9 +55,9 @@ "integrity": "sha1-u4evVoytA0pOSMS9r2Bno6JwExc=" }, "atomically": { - "version": "1.3.2", - "resolved": "https://registry.npmjs.org/atomically/-/atomically-1.3.2.tgz", - "integrity": "sha512-MAiqx5ir1nOoMeG2vLXJnj4oFROJYB1hMqa2aAo6GQVIkPdkIcrq9W9SR0OaRtvEowO7Y2bsXqKFuDMTO4iOAQ==" + "version": "1.7.0", + "resolved": "https://registry.npmjs.org/atomically/-/atomically-1.7.0.tgz", + "integrity": "sha512-Xcz9l0z7y9yQ9rdDaxlmaI4uJHf/T8g9hOEzJcsEqX2SjCj4J20uK7+ldkDHMbpJDK76wF7xEIgxc/vSlsfw5w==" }, "auto-launch": { "version": "5.0.5", @@ -71,26 +71,12 @@ "winreg": "1.2.4" } }, - "balanced-match": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", - "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=" - }, "boolean": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/boolean/-/boolean-3.0.1.tgz", - "integrity": "sha512-HRZPIjPcbwAVQvOTxR4YE3o8Xs98NqbbL1iEZDCz7CL8ql0Lt5iOyJFxfnAB0oFs8Oh02F/lLlg30Mexv46LjA==", + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/boolean/-/boolean-3.0.2.tgz", + "integrity": "sha512-RwywHlpCRc3/Wh81MiCKun4ydaIFyW5Ea6JbL6sRCVx5q5irDw7pMXBUFYF/jArQ6YrG36q0kpovc9P/Kd3I4g==", "optional": true }, - "brace-expansion": { - "version": "1.1.11", - "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", - "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", - "requires": { - "balanced-match": "^1.0.0", - "concat-map": "0.0.1" - } - }, "buffer-crc32": { "version": "0.2.13", "resolved": "https://registry.npmjs.org/buffer-crc32/-/buffer-crc32-0.2.13.tgz", @@ -138,11 +124,6 @@ "mimic-response": "^1.0.0" } }, - "concat-map": { - "version": "0.0.1", - "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", - "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=" - }, "concat-stream": { "version": "1.6.2", "resolved": "https://registry.npmjs.org/concat-stream/-/concat-stream-1.6.2.tgz", @@ -182,9 +163,9 @@ } }, "core-js": { - "version": "3.6.5", - "resolved": "https://registry.npmjs.org/core-js/-/core-js-3.6.5.tgz", - "integrity": "sha512-vZVEEwZoIsI+vPEuoF9Iqf5H7/M3eeQqWlQnYa8FSKKePuYTf5MWnxb5SDAzCa60b3JBRS5g9b+Dq7b1y/RCrA==", + "version": "3.7.0", + "resolved": "https://registry.npmjs.org/core-js/-/core-js-3.7.0.tgz", + "integrity": "sha512-NwS7fI5M5B85EwpWuIwJN4i/fbisQUwLwiSNUWeXlkAZ0sbBjLEvLvFLf1uzAUV66PcEPt4xCGCmOZSxVf3xzA==", "optional": true }, "core-util-is": { @@ -193,9 +174,9 @@ "integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=" }, "custom-electron-titlebar": { - "version": "3.2.4", - "resolved": "https://registry.npmjs.org/custom-electron-titlebar/-/custom-electron-titlebar-3.2.4.tgz", - "integrity": "sha512-zjjw8lcn2JwYaqLSLZtPWnP6IjPSix+nr3QNf5OPsNzdFDGORAUsIhU7A6vNg8aWpsjNc8rsvOW6MVcHwPrUDQ==" + "version": "3.2.5", + "resolved": "https://registry.npmjs.org/custom-electron-titlebar/-/custom-electron-titlebar-3.2.5.tgz", + "integrity": "sha512-9tzTtvrsBec9lFi9Mg8nfwARn82mVgrYiiCYmBwJFYC0YhsyUYZfPyw4fd6hq+XHQbD+f72i9uqhukl5brhZZw==" }, "debounce-fn": { "version": "4.0.0", @@ -206,9 +187,9 @@ } }, "debug": { - "version": "4.2.0", - "resolved": "https://registry.npmjs.org/debug/-/debug-4.2.0.tgz", - "integrity": "sha512-IX2ncY78vDTjZMFUdmsvIRFY2Cf4FnD0wRs+nQwJU8Lu99/tPFdb0VybiiMTPe3I6rQmwsqQqRBvxU+bZ/I8sg==", + "version": "4.3.1", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.1.tgz", + "integrity": "sha512-doEwdvm4PCeK4K3RQN2ZC2BYUBaxwLARCqZmMjtF8a51J2Rb0xpVloFRnCODwqjpwnAoao4pelN8l3RJdv3gRQ==", "requires": { "ms": "2.1.2" } @@ -255,9 +236,9 @@ "integrity": "sha1-7gHdHKwO08vH/b6jfcCo8c4ALOI=" }, "electron": { - "version": "9.3.2", - "resolved": "https://registry.npmjs.org/electron/-/electron-9.3.2.tgz", - "integrity": "sha512-0lleEf9msAXGDi2GukAuiGdw3VDgSTlONOnJgqDEz1fuSEVsXz5RX+hNPKDsVDerLTFg/C34RuJf4LwHvkKcBA==", + "version": "11.0.2", + "resolved": "https://registry.npmjs.org/electron/-/electron-11.0.2.tgz", + "integrity": "sha512-FTYtCm0oj8B8EJhp99BQSW2bd40xYEG/txMj+W3Ed0CNu5zVIIXb5WIrhXLvhcasN5LKy9nkmSZ+u220lCaARg==", "requires": { "@electron/get": "^1.0.1", "@types/node": "^12.0.12", @@ -280,15 +261,6 @@ "keyboardevents-areequal": "^0.2.1" } }, - "electron-storage": { - "version": "1.0.7", - "resolved": "https://registry.npmjs.org/electron-storage/-/electron-storage-1.0.7.tgz", - "integrity": "sha1-8Ii2idqQQU5PlVUgg4lu7VP9518=", - "requires": { - "mkdirp": "^0.5.1", - "rimraf": "^2.5.4" - } - }, "electron-store": { "version": "6.0.1", "resolved": "https://registry.npmjs.org/electron-store/-/electron-store-6.0.1.tgz", @@ -398,11 +370,6 @@ "universalify": "^0.1.0" } }, - "fs.realpath": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", - "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=" - }, "get-stream": { "version": "4.1.0", "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-4.1.0.tgz", @@ -411,19 +378,6 @@ "pump": "^3.0.0" } }, - "glob": { - "version": "7.1.6", - "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.6.tgz", - "integrity": "sha512-LwaxwyZ72Lk7vZINtNNrywX0ZuLyStrdDtabefZKAY5ZGJhVtgdznluResxNmPitE0SAO+O26sWTHeKSI2wMBA==", - "requires": { - "fs.realpath": "^1.0.0", - "inflight": "^1.0.4", - "inherits": "2", - "minimatch": "^3.0.4", - "once": "^1.3.0", - "path-is-absolute": "^1.0.0" - } - }, "global-agent": { "version": "2.1.12", "resolved": "https://registry.npmjs.org/global-agent/-/global-agent-2.1.12.tgz", @@ -488,15 +442,6 @@ "resolved": "https://registry.npmjs.org/http-cache-semantics/-/http-cache-semantics-4.1.0.tgz", "integrity": "sha512-carPklcUh7ROWRK7Cv27RPtdhYhUsela/ue5/jKzjegVvXDqM2ILE9Q2BGn9JZJh1g87cp56su/FgQSzcWS8cQ==" }, - "inflight": { - "version": "1.0.6", - "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", - "integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=", - "requires": { - "once": "^1.3.0", - "wrappy": "1" - } - }, "inherits": { "version": "2.0.4", "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", @@ -619,14 +564,6 @@ "resolved": "https://registry.npmjs.org/mimic-response/-/mimic-response-1.0.1.tgz", "integrity": "sha512-j5EctnkH7amfV/q5Hgmoal1g2QHFJRraOtmx0JpIqkxhBhI/lJSl1nMpQ45hVarwNETOoWEimndZ4QK0RHxuxQ==" }, - "minimatch": { - "version": "3.0.4", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", - "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", - "requires": { - "brace-expansion": "^1.1.7" - } - }, "minimist": { "version": "1.2.5", "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz", @@ -801,14 +738,6 @@ "lowercase-keys": "^1.0.0" } }, - "rimraf": { - "version": "2.7.1", - "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.7.1.tgz", - "integrity": "sha512-uWjbaKIK3T1OSVptzX7Nl6PvQ3qAGtKEtVRjRuazjfL3Bx5eI409VZSqgND+4UNnmzLVdPj9FqFJNPqBZFve4w==", - "requires": { - "glob": "^7.1.3" - } - }, "roarr": { "version": "2.15.4", "resolved": "https://registry.npmjs.org/roarr/-/roarr-2.15.4.tgz", diff --git a/package.json b/package.json index b01c76f..14f4a59 100644 --- a/package.json +++ b/package.json @@ -11,15 +11,9 @@ "license": "ISC", "dependencies": { "auto-launch": "^5.0.5", - "custom-electron-titlebar": "^3.2.4", - "electron": "^9.3.2", - "electron-json-storage": "^4.2.0", + "custom-electron-titlebar": "^3.2.5", + "electron": "^11.0.2", "electron-localshortcut": "^3.2.1", - "electron-storage": "^1.0.7", - "electron-store": "^6.0.1", - "electron-window-state": "^5.0.3", - "material-design-icons": "^3.0.1", - "ndb": "^1.1.5", - "update-electron-app": "^1.5.0" + "electron-store": "^6.0.1" } } diff --git a/public/javascripts/index.js b/public/javascripts/index.js index c328cdd..917777b 100644 --- a/public/javascripts/index.js +++ b/public/javascripts/index.js @@ -1,28 +1,30 @@ -const customTitlebar = require('custom-electron-titlebar'); -const $ = require("./javascripts/jquery.min.js") +const customTitlebar = require("custom-electron-titlebar"); +const { Menu } = require("electron"); +const $ = require("./javascripts/jquery.min.js"); var titleBar = new customTitlebar.Titlebar({ - backgroundColor: customTitlebar.Color.fromHex('#292929'), - icon: "icon/icon.png" + menu: null, + backgroundColor: customTitlebar.Color.fromHex("#292929"), + icon: "icon/icon.png", }); function init() { - document.querySelectorAll(".nav-item").forEach(x => { - x.addEventListener('click', () => { - if ($("#main-page").prop('src').indexOf(x.id) < 0) { - $("#main-page").prop('src', `pages/${x.id}.html`); - document.querySelectorAll(".nav-item").forEach(y => { - y.classList.remove('active') - }) - x.classList.add('active') - }; + document.querySelectorAll(".nav-item").forEach((x) => { + x.addEventListener("click", () => { + if ($("#main-page").prop("src").indexOf(x.id) < 0) { + $("#main-page").prop("src", `pages/${x.id}.html`); + document.querySelectorAll(".nav-item").forEach((y) => { + y.classList.remove("active"); }); + x.classList.add("active"); + } }); - document.querySelectorAll(".nav-item")[0].classList.add("active") -}; + }); + document.querySelectorAll(".nav-item")[0].classList.add("active"); +} document.onreadystatechange = function () { - if (document.readyState == "complete") { - init(); - } -}; \ No newline at end of file + if (document.readyState == "complete") { + init(); + } +}; diff --git a/public/javascripts/keybinds.js b/public/javascripts/keybinds.js index 2d7c4bd..c051ab5 100644 --- a/public/javascripts/keybinds.js +++ b/public/javascripts/keybinds.js @@ -1,59 +1,96 @@ -const $ = require("../javascripts/jquery.min.js"); +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; -$("input[type=text]").on("keyup", e => { - keys[e.key.toUpperCase()] = false; - setInput(); +// Detect keybinds +$(".keybind-input").on("keyup", (e) => { + keys[e.key.toUpperCase()] = false; + setInput(); }); -$("input[type=text]").on("keydown", e => { - Object.keys(keys).forEach(g => { - if (!keys[g]) - delete keys[g]; - }); - keys[e.key.toUpperCase()] = true; - 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, " + ")); + $(".keybind-input").val(Object.keys(keys).toString().replace(/,/gi, " + ")); } +// Configure buttons $(".add-keybind").click(() => { - index = 0; - resetKeyAdder(); - $(".dark-overlay").show().addClass("d-flex"); - $(".keybind-input").focus(); + index = 0; + $(".dark-overlay").show().addClass("d-flex"); + $(".keybind-input").focus(); }); $(".cancel-btn").click(() => { - $(".dark-overlay").hide().removeClass("d-flex"); - resetKeyAdder() -}) + $(".dark-overlay").hide().removeClass("d-flex"); + resetKeyAdder(); +}); $(".done-btn").click(() => { - switch (index) { - case 0: - $(".keybind-input").hide(); - $(".select-function").show(); - $(".done-btn").html("Done"); - break; - case 1: - $(".dark-overlay").hide().removeClass("d-flex"); - resetKeyAdder(); - - - break; - default: - break; - } - index++; -}) + 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().prop("value", ""); - $(".select-function").hide(); - $(".done-btn").html("Next"); -} \ No newline at end of file + $(".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/pages/keybinds.html b/public/pages/keybinds.html index 05ad9a1..6c578fa 100644 --- a/public/pages/keybinds.html +++ b/public/pages/keybinds.html @@ -17,10 +17,19 @@