diff --git a/index.js b/index.js index d335fee..1be83af 100644 --- a/index.js +++ b/index.js @@ -6,6 +6,10 @@ const { autoUpdater, } = require("electron"); +const path = app.getAppPath(); + +const info = require(path + "/json/app.json"); + const electronLocalshortcut = require("electron-localshortcut"); const Store = require("electron-store"); const store = new Store(); @@ -100,7 +104,7 @@ app.on("ready", () => { } let autoLaunch = new AutoLaunch({ - name: "Keyzo", + name: info.name, path: app.getPath("exe"), }); diff --git a/json/app.json b/json/app.json new file mode 100644 index 0000000..b5ee8c3 --- /dev/null +++ b/json/app.json @@ -0,0 +1,4 @@ +{ + "name": "Keyzo", + "version": "0.1" +} diff --git a/json/functions.json b/json/functions.json index f74abe2..25b9b34 100644 --- a/json/functions.json +++ b/json/functions.json @@ -1,20 +1,42 @@ -{ - "Applications": { +[ + { + "title": "applications", "description": "Open/Close/Modify your applications", - "open app": { - "description": "Open an application" - }, - "close app": { - "description": "Close an application" - } + "children": [ + { + "title": "open app", + "description": "Open an application", + "children": [ + { + "title": "test" + }, + { + "title": "lksfjslkd" + } + ] + } + ] }, - "System": { + { + "title": "system", + "description": "Open/Close/Modify your applications", + "children": [ + { + "title": "yeetapp", + "children": [ + { + "title": "lksfjslkd" + } + ] + } + ] + }, + { + "title": "system functions", "description": "Interact with your system" }, - "Keys": { + { + "title": "keys", "description": "Output keyboard inputs" - }, - "System Functions": { - "description": "Some predefined functions" } -} \ No newline at end of file +] \ No newline at end of file diff --git a/src/icon/icon.ico b/src/icon/icon.ico new file mode 100644 index 0000000..2dc2991 Binary files /dev/null and b/src/icon/icon.ico differ diff --git a/src/javascripts/keybinds.js b/src/javascripts/keybinds.js deleted file mode 100644 index 24a678a..0000000 --- a/src/javascripts/keybinds.js +++ /dev/null @@ -1,159 +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 + "/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/keybinds/detection.js b/src/javascripts/keybinds/detection.js new file mode 100644 index 0000000..977dbc4 --- /dev/null +++ b/src/javascripts/keybinds/detection.js @@ -0,0 +1,59 @@ +const path = require("electron").remote.app.getAppPath(); +const $ = require(path + "/src/javascripts/jquery.min.js"); + +// Predefine some vars +var keys = {}, + 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; +} diff --git a/src/javascripts/keybinds/menu.js b/src/javascripts/keybinds/menu.js new file mode 100644 index 0000000..437ee6c --- /dev/null +++ b/src/javascripts/keybinds/menu.js @@ -0,0 +1,75 @@ +const c = document.createElement.bind(document); +const q = document.querySelector.bind(document); + +const functions = require(path + "/json/functions.json"); +var showsFunctions = []; + +// Load functions from json +function init() { + cycleList(functions, "", 0); +} + +function cycleList(list, title, i) { + let div = c("div"); + + showsFunctions[i] = {}; + list.forEach((item) => { + showsFunctions[i][item.title] = false; + div.appendChild(createListItem(i, item.title, item.description)); + if (item.children) { + cycleList(item.children, item.title.replace(/ /g, ""), i + 1); + } + }); + + if (title) div.classList.add(title); + q(".select-function-" + i).appendChild(div); +} + +function createListItem(which, t, s) { + let showsFunctionsLocal = showsFunctions[which], + title = c("div"), + trailing = c("i"), + subtitle = c("div"), + noSpace = t.replace(/ /g, ""); + + title.classList.add("category-item"); + title.classList.add("bold"); + title.innerHTML = t.toUpperCase(); + + trailing.classList.add("category-arrow"); + trailing.classList.add("material-icons"); + trailing.innerHTML = "arrow_forward_ios"; + + title.addEventListener("click", () => { + showsFunctionsLocal[t] = !showsFunctionsLocal[t]; + + Object.keys(showsFunctionsLocal).forEach((i) => { + if (t !== i) { + showsFunctionsLocal[i] = false; + // console.log("Clicked: " + t, "Did not click: " + i); + $("." + i.replace(/ /g, "")).hide(); + } + }); + + // console.log(showsFunctions, which, t); + + if (showsFunctionsLocal[t]) { + $(".select-function-" + (which + 1)).show(); + $("." + noSpace).show(); + } else { + $(".select-function-" + (which + 1)).hide(); + $("." + noSpace).hide(); + } + }); + + subtitle.classList.add("text-muted"); + subtitle.innerHTML = s; + + title.appendChild(trailing); + + if (s) title.appendChild(subtitle); + + return title; +} + +init(); diff --git a/src/javascripts/settings.js b/src/javascripts/settings.js index 35f32be..b021c18 100644 --- a/src/javascripts/settings.js +++ b/src/javascripts/settings.js @@ -1,7 +1,9 @@ const Store = require("electron-store"); const store = new Store(); -const $ = require("./jquery.min.js"); +const path = require("electron").remote.app.getAppPath(); + +const $ = require(path + "/src/javascripts/jquery.min.js"); const settings = ["minimize", "startup", "startup-min"]; diff --git a/src/pages/keybinds.html b/src/pages/keybinds.html index 5b681b5..2bd9577 100644 --- a/src/pages/keybinds.html +++ b/src/pages/keybinds.html @@ -25,15 +25,15 @@
-
+

CATEGORIES

- @@ -45,6 +45,7 @@
- + + \ No newline at end of file