Skip to content

Commit

Permalink
Fixed app info opening, experimental text input context menus
Browse files Browse the repository at this point in the history
  • Loading branch information
Ruslan Garifullin ruslan.g2002@gmail.com committed Nov 11, 2018
1 parent 8a952ff commit aba699f
Show file tree
Hide file tree
Showing 10 changed files with 104 additions and 46 deletions.
17 changes: 5 additions & 12 deletions apps/launcher/launcher.js
Original file line number Diff line number Diff line change
@@ -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());
Expand All @@ -34,4 +26,5 @@ async function renderLauncher() {
}
}

renderLauncher();
renderLauncher();
new Registry("launcher").on("changed", renderLauncher);
2 changes: 1 addition & 1 deletion apps/settings/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
9 changes: 5 additions & 4 deletions apps/start/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@ 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");
root = Elements.StartMenu;
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 () {
Expand Down Expand Up @@ -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 => {
Expand Down Expand Up @@ -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"
Expand Down
1 change: 0 additions & 1 deletion apps/start/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ let menu = Menu.buildFromTemplate(null, [{
label: "Quit AtomOS",
shortLabel: "Quit",
click: e => {
shutdown = true;
window.close();
}
}]);
Expand Down
33 changes: 18 additions & 15 deletions apps/tray/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
7 changes: 5 additions & 2 deletions front/api/3_menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down Expand Up @@ -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() {
Expand All @@ -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);
})
//}
}
Expand All @@ -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;
Expand Down
8 changes: 2 additions & 6 deletions front/api/4_shell.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 || {};
Expand Down Expand Up @@ -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];
Expand Down
64 changes: 64 additions & 0 deletions front/api/7_contextmenu.js
Original file line number Diff line number Diff line change
@@ -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();
}

});
3 changes: 1 addition & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const {
BrowserWindow,
app,
session
app
} = require('electron');
const fs = require("fs");
const path = require("path");
Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit aba699f

Please sign in to comment.