Skip to content

Commit 19b1e0e

Browse files
authored
Merge pull request #1302 from kando-menu/feature/custom-menus
Add IPC interface
2 parents 531a762 + 68114aa commit 19b1e0e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+1998
-265
lines changed
Lines changed: 64 additions & 0 deletions
Loading
Lines changed: 52 additions & 0 deletions
Loading

forge.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ const config: ForgeConfig = {
126126
"font-src 'self' file: data:; " +
127127
"style-src-elem 'self' 'unsafe-inline' file: data:; " +
128128
"media-src 'self' file: data:; " +
129-
"connect-src 'self' file:; ",
129+
"connect-src 'self' file: ws:; ",
130130

131131
mainConfig,
132132
renderer: {

package-lock.json

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

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@
107107
"typescript": "^5.9.3",
108108
"typescript-eslint": "^8.55.0",
109109
"typescript-plugin-css-modules": "^5.2.0",
110+
"ws": "^8.18.3",
110111
"zod": "^4.3.6",
111112
"zundo": "^2.1.0",
112113
"zustand": "^5.0.11"

src/common/index.ts

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@
99
// SPDX-License-Identifier: MIT
1010

1111
export * from './settings-schemata';
12+
export * from './typed-event-emitter';
1213

13-
import { AchievementStats } from './settings-schemata';
14+
import { AchievementStats, Menu } from './settings-schemata';
1415

1516
/** This type is used to pass command line arguments to the app. */
1617
export type CommandlineOptions = {
@@ -123,6 +124,12 @@ export type WMInfo = {
123124
export type SystemInfo = {
124125
/** Whether the system supports launching isolated processes. */
125126
readonly supportsIsolatedProcesses: boolean;
127+
128+
/** The IPC port used by Kando's own IPC show-menu interface. */
129+
readonly ipcPort: number;
130+
131+
/** The API version supported by Kando's own IPC show-menu interface. */
132+
readonly ipcApiVersion: number;
126133
};
127134

128135
/** This type describes a icon theme consisting of a collection of icon files. */
@@ -176,15 +183,24 @@ export type KeyStroke = {
176183
*/
177184
export type KeySequence = Array<KeyStroke>;
178185

186+
/** Enum for the different item categories which can be hovered or selected. */
187+
export enum InteractionTarget {
188+
eItem = 'item',
189+
eSubmenu = 'submenu',
190+
eParent = 'parent',
191+
}
192+
179193
/**
180194
* There are different reasons why a menu should be shown. This type is used to describe
181195
* the request to show a menu. A menu can be shown because a shortcut was pressed (in this
182-
* case `trigger` will be the shortcut or the shortcut ID) or because a menu was requested
183-
* by name.
196+
* case `trigger` will be the shortcut or the shortcut ID), because a menu was requested
197+
* by name, or a custom menu is requested (in this case `menu` contains the menu
198+
* structure).
184199
*/
185200
export type ShowMenuRequest = {
186-
readonly trigger: string;
187-
readonly name: string;
201+
readonly trigger?: string;
202+
readonly name?: string;
203+
readonly menu?: Menu;
188204
};
189205

190206
/**

src/common/ipc/cross-websocket.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//////////////////////////////////////////////////////////////////////////////////////////
2+
// _ _ ____ _ _ ___ ____ //
3+
// |_/ |__| |\ | | \ | | This file belongs to Kando, the cross-platform //
4+
// | \_ | | | \| |__/ |__| pie menu. Read more on github.com/kando-menu/kando //
5+
// //
6+
//////////////////////////////////////////////////////////////////////////////////////////
7+
8+
// SPDX-FileCopyrightText: Simon Schneegans <code@simonschneegans.de>
9+
// SPDX-License-Identifier: MIT
10+
11+
/**
12+
* Selects the appropriate WebSocket implementation for Node.js or browser/Electron
13+
* renderer.
14+
*/
15+
export function createCrossWebSocket(url: string): {
16+
send(data: string): void;
17+
close(): void;
18+
onopen?: () => void;
19+
onmessage?: (event: { data: string }) => void;
20+
onerror?: (event: unknown) => void;
21+
} {
22+
// eslint-disable-next-line @typescript-eslint/naming-convention
23+
const WebSocketImpl =
24+
typeof window !== 'undefined' && typeof window.WebSocket !== 'undefined'
25+
? window.WebSocket
26+
: require('ws');
27+
return new WebSocketImpl(url);
28+
}

src/common/ipc/index.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//////////////////////////////////////////////////////////////////////////////////////////
2+
// _ _ ____ _ _ ___ ____ //
3+
// |_/ |__| |\ | | \ | | This file belongs to Kando, the cross-platform //
4+
// | \_ | | | \| |__/ |__| pie menu. Read more on github.com/kando-menu/kando //
5+
// //
6+
//////////////////////////////////////////////////////////////////////////////////////////
7+
8+
// SPDX-FileCopyrightText: Simon Schneegans <code@simonschneegans.de>
9+
// SPDX-License-Identifier: MIT
10+
11+
export { IPCServer, IPCCallbacks } from './ipc-server';
12+
export { IPCShowMenuClient } from './ipc-show-menu-client';

0 commit comments

Comments
 (0)