diff --git a/apps/launcher/launcher.js b/apps/launcher/launcher.js index 7e21802..a0c0e13 100644 --- a/apps/launcher/launcher.js +++ b/apps/launcher/launcher.js @@ -1,19 +1,11 @@ const fs = require("fs").promises; const path = require("path"); -root.className = "d-flex" +root.className = "d-flex"; async function renderLauncher() { + root.innerHTML = ""; let items = Registry.get("launcher.items") || []; - if (!items.length) { - let elem = document.createElement('div'); - elem.className = "text-white mr-3 position-relative active fade show"; - elem.title = "Add new item"; - elem.icon = document.createElement("icon"); - elem.icon.className = "rounded-max mdi btn btn-secondary border-0 mdi-24px lh-24 d-flex text-white p-2 my-1 mdi-plus"; - elem.appendChild(elem.icon); - root.append(elem); - - } else { + if (items.length) { for (const item of items) { let json = await fs.readFile(path.join(osRoot, "apps", item, "package.json")); let pkg = JSON.parse(json.toString()); @@ -34,4 +26,5 @@ async function renderLauncher() { } } -renderLauncher(); \ No newline at end of file +renderLauncher(); +new Registry("launcher").on("changed", renderLauncher); \ No newline at end of file diff --git a/apps/settings/settings.js b/apps/settings/settings.js index 7723d79..6a9a4ff 100644 --- a/apps/settings/settings.js +++ b/apps/settings/settings.js @@ -81,5 +81,5 @@ function setActionButton(elem) { root.footer.append(root.footer.specialButton); } -if (this.sectionToOpen) openSection(sectionToOpen); else +if (sectionToOpen) openSection(sectionToOpen); else openSection("menu"); \ No newline at end of file diff --git a/apps/start/menu.js b/apps/start/menu.js index 3a41b03..1f3ee11 100644 --- a/apps/start/menu.js +++ b/apps/start/menu.js @@ -12,7 +12,7 @@ if (!Object.getOwnPropertyNames(registry.get()).length) registry.set({ firstRun: true }); const firstRun = Registry.get("start.firstRun"); -if (firstRun) Registry.set("start.firstRun", false) +if (firstRun) Registry.set("start.firstRun", false); function render() { Elements.StartMenu = document.createElement("startmenu"); @@ -20,6 +20,7 @@ function render() { Elements.StartMenu.className = "position-fixed d-flex flex-column p-2 hide fly up"; Elements.StartMenu.style.height = "400px"; Elements.StartMenu.style.width = "400px"; + Elements.StartMenu.addEventListener("contextmenu", e => e.stopPropagation()); if (isMobile) { Elements.StartMenu.classList.add("w-100"); setTimeout(function () { @@ -139,7 +140,7 @@ async function renderApps() { icon: "information-variant", click() { window.__currentApp = item; - setTimeout(() => shell.openSettings("apps-app"), 100); + shell.openSettings("apps-app"); } }]); appEntry.addEventListener("contextmenu", e => { @@ -190,9 +191,9 @@ function renderSearchSection() { } function renderSearch() { - root.Search = document.createElement("search") + root.Search = document.createElement("search"); root.Search.className = "input-group card flex-row shadow mb-2 flex-shrink-0"; - + root.Search.dataset.editMenu = "false"; let igp = document.createElement("label"); igp.className = "input-group-prepend m-0 d-flex align-items-center"; igp.htmlFor = "__searchInput" diff --git a/apps/start/start.js b/apps/start/start.js index 0862050..136d973 100644 --- a/apps/start/start.js +++ b/apps/start/start.js @@ -17,7 +17,6 @@ let menu = Menu.buildFromTemplate(null, [{ label: "Quit AtomOS", shortLabel: "Quit", click: e => { - shutdown = true; window.close(); } }]); diff --git a/apps/tray/menu.js b/apps/tray/menu.js index 96b303f..1229e60 100644 --- a/apps/tray/menu.js +++ b/apps/tray/menu.js @@ -114,21 +114,24 @@ function renderQuickSection() { //TODO: Make more customizable } shell.openSettings = function (section) { - Elements.MenuBar.open(); - Elements.MenuBar.settings = document.createElement("section"); - Elements.MenuBar.settings.className = "card shadow fade scrollable-0 position-absolute w-100"; - Elements.MenuBar.settings.style.zIndex = 100; - if(isMobile) { - Elements.MenuBar.settings.style.top = 0; - Elements.MenuBar.settings.style.left = 0; - Elements.MenuBar.settings.classList.add("flex-column-reverse") - } - setTimeout(e => Elements.MenuBar.settings.classList.add("show"), FADE_ANIMATION_DURATION); - Elements.MenuBar.settings.style.height = "450px"; - fs.readFile(path.join(osRoot, "apps", "settings", "settings.js")).then(code => { - new Function('root', 'sectionToOpen', code.toString())(Elements.MenuBar.settings, section); - }); - Elements.MenuBar.prepend(Elements.MenuBar.settings); + setTimeout(e => { + Elements.MenuBar.open(); + Elements.MenuBar.settings = document.createElement("section"); + Elements.MenuBar.settings.className = "card shadow fade scrollable-0 position-absolute w-100"; + Elements.MenuBar.settings.style.zIndex = 100; + if (isMobile) { + Elements.MenuBar.settings.style.top = 0; + Elements.MenuBar.settings.style.left = 0; + Elements.MenuBar.settings.classList.add("flex-column-reverse") + } + setTimeout(e => Elements.MenuBar.settings.classList.add("show"), FADE_ANIMATION_DURATION); + Elements.MenuBar.settings.style.height = "450px"; + fs.readFile(path.join(osRoot, "apps", "settings", "settings.js")).then(code => { + new Function('root', 'sectionToOpen', code.toString())(Elements.MenuBar.settings, section); + }); + Elements.MenuBar.prepend(Elements.MenuBar.settings); + + }, FADE_ANIMATION_DURATION); }; function renderNotifications() { diff --git a/front/api/3_menu.js b/front/api/3_menu.js index b56ad58..8c8a246 100644 --- a/front/api/3_menu.js +++ b/front/api/3_menu.js @@ -35,6 +35,7 @@ constructor(win, template = []) { super(); let _this = this; + this.activeElement = document.activeElement; template.forEach((item, i, arr) => { arr[i] = Object.assign({}, defaultOptions, item); }); @@ -67,6 +68,8 @@ if (event.returnValue) _this.closePopup(); }); this.window = win; + this.id = shell.uniqueId(); + this.menu.id = this.id; this.renderMenu(); } static getFocusedMenu() { @@ -85,7 +88,7 @@ if (_this.window && !_this.window.isFocused()) return; shortcuts.forEach(acc => { if ((e.ctrlKey ^ !acc.ctrl) && (e.shiftKey ^ !acc.shift) && (e.altKey ^ !acc.alt) && (e.key.toLowerCase() === acc.key.toLowerCase())) - acc.click.call(acc.menuItem); + acc.click.call(acc.menuItem, _this.window, _this.activeElement); }) //} } @@ -107,7 +110,7 @@ menuItem.className = "dropdown-item d-flex align-items-center"; menuItem.disabled = !item.enabled; menuItem.onclick = e => { - (item.click || (e => console.log("This menu item does not have an onclick event."))).call(null, item, _this.window, e); + (item.click || (e => console.log("This menu item does not have an onclick event."))).call(null, item, _this.window, _this.activeElement); }; menuItem.id = "dm_" + (item.id || Math.random().toString(36).substr(2, 9)); menuItem.style.order = item.position || 0; diff --git a/front/api/4_shell.js b/front/api/4_shell.js index 82afb78..93c7556 100644 --- a/front/api/4_shell.js +++ b/front/api/4_shell.js @@ -61,10 +61,6 @@ window.shell = class Shell { return Shell.uniqueId(); else return uuid; } - static async openAppInfo(app) { - Elements.MenuBar.quickItems.lastChild.click(); - Shell.openAppInfo(app) - } static async openItem(file) { let settings = registry.get(); settings.associations = settings.associations || {}; @@ -555,11 +551,11 @@ window.shell = class Shell { customCheckbox.label.className = "custom-control-label"; customCheckbox.append(customCheckbox.checkbox, customCheckbox.label); for (const i of options.buttons.keys()) { - function send() { + let send = function () { if (options.checkboxLabel) resolve([options.buttons[i], customCheckbox.checkbox.checked]); else resolve(options.buttons[i]); - } + }; let button = document.createElement("button"); button.className = "btn " + (options.defaultId === i ? "btn-primary" : "btn-secondary"); button.innerText = options.buttons[i]; diff --git a/front/api/7_contextmenu.js b/front/api/7_contextmenu.js new file mode 100644 index 0000000..dc82f56 --- /dev/null +++ b/front/api/7_contextmenu.js @@ -0,0 +1,64 @@ +const wc = require("electron").remote.getCurrentWebContents(); +let previousMenu; +wc.on("context-menu", (e, params) => { + let generate = true; + if (previousMenu) if (document.querySelector("body>menu.dropdown-menu:not(#" + previousMenu.id + ")")) generate = false; + if (!params.isEditable) generate = false; + if (e.sender.dataset && e.sender.dataset.editMenu === "false") generate = false; + if (generate) { + console.log(params); + previousMenu = new Menu(null, [{ + label: "Undo", + icon: "undo", + enabled: params.editFlags.canUndo, + click(item, win, elem) { + elem.focus(); + document.execCommand("undo"); + } + }, { + label: "Redo", + icon: "redo", + enabled: params.editFlags.canRedo, + click(item, win, elem) { + elem.focus(); + document.execCommand("redo"); + } + }, {type: "separator"}, { + label: "Cut", + icon: "content-cut", + enabled: params.editFlags.canCut, + click() { + elem.focus(); + document.execCommand('cut', false) + } + }, { + label: "Copy", + icon: "content-copy", + enabled: params.editFlags.canCopy, + click() { + elem.focus(); + document.execCommand('copy', false) + } + }, { + label: "Paste", + icon: "content-paste", + enabled: params.editFlags.canPaste, + click() { + elem.focus(); + document.execCommand('paste', false) + } + }, { + type: "separator" + }, { + label: "Select All", + icon: "select-all", + enabled: params.editFlags.canSelectAll, + click() { + elem.focus(); + document.execCommand('selectAll', false) + } + }]); + previousMenu.popup(); + } + +}); \ No newline at end of file diff --git a/index.js b/index.js index b7e7b46..b7e5d8d 100644 --- a/index.js +++ b/index.js @@ -1,7 +1,6 @@ const { BrowserWindow, - app, - session + app } = require('electron'); const fs = require("fs"); const path = require("path"); diff --git a/package-lock.json b/package-lock.json index 84746e7..f177fd3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5,9 +5,9 @@ "requires": true, "dependencies": { "@mdi/font": { - "version": "2.8.94", - "resolved": "https://registry.npmjs.org/@mdi/font/-/font-2.8.94.tgz", - "integrity": "sha512-QSmuK0BedRMDSgh7RCOc0yO+cAHAaAKfj11BPv0XDxvGKNNKGRqDJcJKdrWUpVmO1/xiFLWfPEmqMi/PKwvjcg==" + "version": "3.0.39", + "resolved": "https://registry.npmjs.org/@mdi/font/-/font-3.0.39.tgz", + "integrity": "sha512-VnPxEXsiV+YP9NO7XyQEvs1tBxkmtPzib9dRq/1CqubaZy9oeP7Jmgd/IEya8Z3bVyj+NZpwS0YGZW1kvx2eFQ==" }, "@types/commander": { "version": "2.12.2",