@xwiki/cristal-electron-main 0.12.0 → 0.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xwiki/cristal-electron-main",
3
- "version": "0.12.0",
3
+ "version": "0.13.0",
4
4
  "license": "LGPL 2.1",
5
5
  "author": "XWiki Org Community <contact@xwiki.org>",
6
6
  "homepage": "https://cristal.xwiki.org/",
@@ -13,21 +13,19 @@
13
13
  "url": "https://jira.xwiki.org/projects/CRISTAL/"
14
14
  },
15
15
  "dependencies": {
16
- "electron": "33.0.2",
17
- "@xwiki/cristal-browser-electron": "0.12.0",
18
- "@xwiki/cristal-electron-authentication-xwiki-main": "0.12.0",
19
- "@xwiki/cristal-electron-storage": "0.12.0"
16
+ "electron": "33.2.1",
17
+ "@xwiki/cristal-browser-electron": "0.13.0",
18
+ "@xwiki/cristal-electron-authentication-xwiki-main": "0.13.0",
19
+ "@xwiki/cristal-electron-storage": "0.13.0"
20
20
  },
21
21
  "devDependencies": {
22
- "@types/node": "22.8.7",
23
- "cross-env": "7.0.3"
22
+ "@types/node": "22.10.2",
23
+ "typescript": "5.6.3",
24
+ "vite": "6.0.3"
24
25
  },
25
26
  "scripts": {
26
27
  "build": "tsc --project tsconfig.json && vite build",
27
28
  "clean": "rimraf dist",
28
- "electron": "echo 'no task'",
29
- "lint": "eslint \"./src/**/*.{ts,tsx}\" --max-warnings=0",
30
- "linux": "echo 'no task'",
31
- "package": "echo 'no task'"
29
+ "lint": "eslint \"./src/**/*.{ts,tsx,vue}\" --max-warnings=0"
32
30
  }
33
31
  }
package/src/mainWindow.ts CHANGED
@@ -18,6 +18,7 @@
18
18
  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19
19
  */
20
20
 
21
+ import { initializeMenu } from "./menu";
21
22
  import { loadFile } from "./reload";
22
23
  import { BrowserWindow, app, shell } from "electron";
23
24
  import { join } from "node:path";
@@ -35,6 +36,8 @@ async function createWindow() {
35
36
  },
36
37
  });
37
38
 
39
+ initializeMenu(browserWindow);
40
+
38
41
  // Uncomment to start electron debugger at startup.
39
42
  // browserWindow.webContents.openDevTools();
40
43
 
package/src/menu.ts ADDED
@@ -0,0 +1,73 @@
1
+ /*
2
+ * See the LICENSE file distributed with this work for additional
3
+ * information regarding copyright ownership.
4
+ *
5
+ * This is free software; you can redistribute it and/or modify it
6
+ * under the terms of the GNU Lesser General Public License as
7
+ * published by the Free Software Foundation; either version 2.1 of
8
+ * the License, or (at your option) any later version.
9
+ *
10
+ * This software is distributed in the hope that it will be useful,
11
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
+ * Lesser General Public License for more details.
14
+ *
15
+ * You should have received a copy of the GNU Lesser General Public
16
+ * License along with this software; if not, write to the Free
17
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19
+ */
20
+
21
+ import { BrowserWindow, Menu } from "electron";
22
+ import type { MenuItem } from "electron";
23
+
24
+ /**
25
+ * Scan recursively the menus and sub-menus to find the interesting items.
26
+ *
27
+ * @param items - the item of the current menu
28
+ * @param actions - the action we are interested to keep
29
+ * @param newMenu - the new menu built from interesting actions
30
+ * @since 0.13
31
+ */
32
+ function scan(items: MenuItem[], actions: string[], newMenu: Menu): void {
33
+ for (const item of items) {
34
+ if (actions.includes(`${item.role}`)) {
35
+ newMenu.insert(0, item);
36
+ } else {
37
+ if (item.submenu != undefined) {
38
+ scan(item.submenu.items, actions, newMenu);
39
+ }
40
+ }
41
+ }
42
+ }
43
+
44
+ /**
45
+ * Initialize the menu for the provided browser window. The menu is hidden, and we only keep entries with useful
46
+ * keyboard shortcuts.
47
+ * @param browserWindow - the provided browser window.
48
+ * @since 0.13
49
+ */
50
+ function initializeMenu(browserWindow: BrowserWindow) {
51
+ const menu = Menu.getApplicationMenu();
52
+ const newMenu = new Menu();
53
+
54
+ // The list of actions we wish to preserve from the default application menu.
55
+ const actions = [
56
+ "toggledevtools",
57
+ "resetzoom",
58
+ "zoomin",
59
+ "zoomout",
60
+ "togglefullscreen",
61
+ ];
62
+ if (menu?.items) {
63
+ scan(menu?.items, actions, newMenu);
64
+ }
65
+
66
+ // Sets the menu on windows and linux.
67
+ browserWindow.setMenu(newMenu);
68
+ // Set the menu on MacOS.
69
+ Menu.setApplicationMenu(menu);
70
+ browserWindow.setMenuBarVisibility(false);
71
+ }
72
+
73
+ export { initializeMenu };
package/tsdoc.json ADDED
@@ -0,0 +1,4 @@
1
+ {
2
+ "$schema": "https://developer.microsoft.com/json-schemas/tsdoc/v0/tsdoc.schema.json",
3
+ "extends": ["../../tsdoc.json"]
4
+ }