Skip to content

Commit aba699f

Browse files
author
Ruslan Garifullin ruslan.g2002@gmail.com
committed
Fixed app info opening, experimental text input context menus
1 parent 8a952ff commit aba699f

10 files changed

Lines changed: 104 additions & 46 deletions

File tree

apps/launcher/launcher.js

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,11 @@
11
const fs = require("fs").promises;
22
const path = require("path");
3-
root.className = "d-flex"
3+
root.className = "d-flex";
44

55
async function renderLauncher() {
6+
root.innerHTML = "";
67
let items = Registry.get("launcher.items") || [];
7-
if (!items.length) {
8-
let elem = document.createElement('div');
9-
elem.className = "text-white mr-3 position-relative active fade show";
10-
elem.title = "Add new item";
11-
elem.icon = document.createElement("icon");
12-
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";
13-
elem.appendChild(elem.icon);
14-
root.append(elem);
15-
16-
} else {
8+
if (items.length) {
179
for (const item of items) {
1810
let json = await fs.readFile(path.join(osRoot, "apps", item, "package.json"));
1911
let pkg = JSON.parse(json.toString());
@@ -34,4 +26,5 @@ async function renderLauncher() {
3426
}
3527
}
3628

37-
renderLauncher();
29+
renderLauncher();
30+
new Registry("launcher").on("changed", renderLauncher);

apps/settings/settings.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,5 +81,5 @@ function setActionButton(elem) {
8181
root.footer.append(root.footer.specialButton);
8282
}
8383

84-
if (this.sectionToOpen) openSection(sectionToOpen); else
84+
if (sectionToOpen) openSection(sectionToOpen); else
8585
openSection("menu");

apps/start/menu.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,15 @@ if (!Object.getOwnPropertyNames(registry.get()).length) registry.set({
1212
firstRun: true
1313
});
1414
const firstRun = Registry.get("start.firstRun");
15-
if (firstRun) Registry.set("start.firstRun", false)
15+
if (firstRun) Registry.set("start.firstRun", false);
1616

1717
function render() {
1818
Elements.StartMenu = document.createElement("startmenu");
1919
root = Elements.StartMenu;
2020
Elements.StartMenu.className = "position-fixed d-flex flex-column p-2 hide fly up";
2121
Elements.StartMenu.style.height = "400px";
2222
Elements.StartMenu.style.width = "400px";
23+
Elements.StartMenu.addEventListener("contextmenu", e => e.stopPropagation());
2324
if (isMobile) {
2425
Elements.StartMenu.classList.add("w-100");
2526
setTimeout(function () {
@@ -139,7 +140,7 @@ async function renderApps() {
139140
icon: "information-variant",
140141
click() {
141142
window.__currentApp = item;
142-
setTimeout(() => shell.openSettings("apps-app"), 100);
143+
shell.openSettings("apps-app");
143144
}
144145
}]);
145146
appEntry.addEventListener("contextmenu", e => {
@@ -190,9 +191,9 @@ function renderSearchSection() {
190191
}
191192

192193
function renderSearch() {
193-
root.Search = document.createElement("search")
194+
root.Search = document.createElement("search");
194195
root.Search.className = "input-group card flex-row shadow mb-2 flex-shrink-0";
195-
196+
root.Search.dataset.editMenu = "false";
196197
let igp = document.createElement("label");
197198
igp.className = "input-group-prepend m-0 d-flex align-items-center";
198199
igp.htmlFor = "__searchInput"

apps/start/start.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ let menu = Menu.buildFromTemplate(null, [{
1717
label: "Quit AtomOS",
1818
shortLabel: "Quit",
1919
click: e => {
20-
shutdown = true;
2120
window.close();
2221
}
2322
}]);

apps/tray/menu.js

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -114,21 +114,24 @@ function renderQuickSection() { //TODO: Make more customizable
114114
}
115115

116116
shell.openSettings = function (section) {
117-
Elements.MenuBar.open();
118-
Elements.MenuBar.settings = document.createElement("section");
119-
Elements.MenuBar.settings.className = "card shadow fade scrollable-0 position-absolute w-100";
120-
Elements.MenuBar.settings.style.zIndex = 100;
121-
if(isMobile) {
122-
Elements.MenuBar.settings.style.top = 0;
123-
Elements.MenuBar.settings.style.left = 0;
124-
Elements.MenuBar.settings.classList.add("flex-column-reverse")
125-
}
126-
setTimeout(e => Elements.MenuBar.settings.classList.add("show"), FADE_ANIMATION_DURATION);
127-
Elements.MenuBar.settings.style.height = "450px";
128-
fs.readFile(path.join(osRoot, "apps", "settings", "settings.js")).then(code => {
129-
new Function('root', 'sectionToOpen', code.toString())(Elements.MenuBar.settings, section);
130-
});
131-
Elements.MenuBar.prepend(Elements.MenuBar.settings);
117+
setTimeout(e => {
118+
Elements.MenuBar.open();
119+
Elements.MenuBar.settings = document.createElement("section");
120+
Elements.MenuBar.settings.className = "card shadow fade scrollable-0 position-absolute w-100";
121+
Elements.MenuBar.settings.style.zIndex = 100;
122+
if (isMobile) {
123+
Elements.MenuBar.settings.style.top = 0;
124+
Elements.MenuBar.settings.style.left = 0;
125+
Elements.MenuBar.settings.classList.add("flex-column-reverse")
126+
}
127+
setTimeout(e => Elements.MenuBar.settings.classList.add("show"), FADE_ANIMATION_DURATION);
128+
Elements.MenuBar.settings.style.height = "450px";
129+
fs.readFile(path.join(osRoot, "apps", "settings", "settings.js")).then(code => {
130+
new Function('root', 'sectionToOpen', code.toString())(Elements.MenuBar.settings, section);
131+
});
132+
Elements.MenuBar.prepend(Elements.MenuBar.settings);
133+
134+
}, FADE_ANIMATION_DURATION);
132135
};
133136

134137
function renderNotifications() {

front/api/3_menu.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
constructor(win, template = []) {
3636
super();
3737
let _this = this;
38+
this.activeElement = document.activeElement;
3839
template.forEach((item, i, arr) => {
3940
arr[i] = Object.assign({}, defaultOptions, item);
4041
});
@@ -67,6 +68,8 @@
6768
if (event.returnValue) _this.closePopup();
6869
});
6970
this.window = win;
71+
this.id = shell.uniqueId();
72+
this.menu.id = this.id;
7073
this.renderMenu();
7174
}
7275
static getFocusedMenu() {
@@ -85,7 +88,7 @@
8588
if (_this.window && !_this.window.isFocused()) return;
8689
shortcuts.forEach(acc => {
8790
if ((e.ctrlKey ^ !acc.ctrl) && (e.shiftKey ^ !acc.shift) && (e.altKey ^ !acc.alt) && (e.key.toLowerCase() === acc.key.toLowerCase()))
88-
acc.click.call(acc.menuItem);
91+
acc.click.call(acc.menuItem, _this.window, _this.activeElement);
8992
})
9093
//}
9194
}
@@ -107,7 +110,7 @@
107110
menuItem.className = "dropdown-item d-flex align-items-center";
108111
menuItem.disabled = !item.enabled;
109112
menuItem.onclick = e => {
110-
(item.click || (e => console.log("This menu item does not have an onclick event."))).call(null, item, _this.window, e);
113+
(item.click || (e => console.log("This menu item does not have an onclick event."))).call(null, item, _this.window, _this.activeElement);
111114
};
112115
menuItem.id = "dm_" + (item.id || Math.random().toString(36).substr(2, 9));
113116
menuItem.style.order = item.position || 0;

front/api/4_shell.js

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,6 @@ window.shell = class Shell {
6161
return Shell.uniqueId();
6262
else return uuid;
6363
}
64-
static async openAppInfo(app) {
65-
Elements.MenuBar.quickItems.lastChild.click();
66-
Shell.openAppInfo(app)
67-
}
6864
static async openItem(file) {
6965
let settings = registry.get();
7066
settings.associations = settings.associations || {};
@@ -555,11 +551,11 @@ window.shell = class Shell {
555551
customCheckbox.label.className = "custom-control-label";
556552
customCheckbox.append(customCheckbox.checkbox, customCheckbox.label);
557553
for (const i of options.buttons.keys()) {
558-
function send() {
554+
let send = function () {
559555
if (options.checkboxLabel)
560556
resolve([options.buttons[i], customCheckbox.checkbox.checked]);
561557
else resolve(options.buttons[i]);
562-
}
558+
};
563559
let button = document.createElement("button");
564560
button.className = "btn " + (options.defaultId === i ? "btn-primary" : "btn-secondary");
565561
button.innerText = options.buttons[i];

front/api/7_contextmenu.js

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
const wc = require("electron").remote.getCurrentWebContents();
2+
let previousMenu;
3+
wc.on("context-menu", (e, params) => {
4+
let generate = true;
5+
if (previousMenu) if (document.querySelector("body>menu.dropdown-menu:not(#" + previousMenu.id + ")")) generate = false;
6+
if (!params.isEditable) generate = false;
7+
if (e.sender.dataset && e.sender.dataset.editMenu === "false") generate = false;
8+
if (generate) {
9+
console.log(params);
10+
previousMenu = new Menu(null, [{
11+
label: "Undo",
12+
icon: "undo",
13+
enabled: params.editFlags.canUndo,
14+
click(item, win, elem) {
15+
elem.focus();
16+
document.execCommand("undo");
17+
}
18+
}, {
19+
label: "Redo",
20+
icon: "redo",
21+
enabled: params.editFlags.canRedo,
22+
click(item, win, elem) {
23+
elem.focus();
24+
document.execCommand("redo");
25+
}
26+
}, {type: "separator"}, {
27+
label: "Cut",
28+
icon: "content-cut",
29+
enabled: params.editFlags.canCut,
30+
click() {
31+
elem.focus();
32+
document.execCommand('cut', false)
33+
}
34+
}, {
35+
label: "Copy",
36+
icon: "content-copy",
37+
enabled: params.editFlags.canCopy,
38+
click() {
39+
elem.focus();
40+
document.execCommand('copy', false)
41+
}
42+
}, {
43+
label: "Paste",
44+
icon: "content-paste",
45+
enabled: params.editFlags.canPaste,
46+
click() {
47+
elem.focus();
48+
document.execCommand('paste', false)
49+
}
50+
}, {
51+
type: "separator"
52+
}, {
53+
label: "Select All",
54+
icon: "select-all",
55+
enabled: params.editFlags.canSelectAll,
56+
click() {
57+
elem.focus();
58+
document.execCommand('selectAll', false)
59+
}
60+
}]);
61+
previousMenu.popup();
62+
}
63+
64+
});

index.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
const {
22
BrowserWindow,
3-
app,
4-
session
3+
app
54
} = require('electron');
65
const fs = require("fs");
76
const path = require("path");

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)