@synnaxlabs/drift 0.42.3 → 0.44.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/README.md +48 -56
- package/dist/electron.cjs +1 -1
- package/dist/electron.js +153 -161
- package/dist/index.cjs +1 -1
- package/dist/index.js +297 -239
- package/dist/react.cjs +1 -1
- package/dist/react.js +2 -2
- package/dist/selectors-2mPd0CjI.cjs +1 -0
- package/dist/{selectors-B00IQPYW.js → selectors-C36jHClh.js} +2 -5
- package/dist/src/external.d.ts +3 -3
- package/dist/src/external.d.ts.map +1 -1
- package/dist/src/{noop/index.d.ts → noop.d.ts} +13 -9
- package/dist/src/noop.d.ts.map +1 -0
- package/dist/src/runtime.d.ts.map +1 -1
- package/dist/src/state.d.ts.map +1 -1
- package/dist/src/sync.d.ts.map +1 -1
- package/dist/src/window.d.ts +5 -5
- package/dist/src/window.d.ts.map +1 -1
- package/dist/state-D41-Dai4.js +12075 -0
- package/dist/state-yfMrLzJG.cjs +34 -0
- package/dist/tauri.cjs +1 -1
- package/dist/tauri.js +224 -197
- package/package.json +17 -21
- package/dist/noop.cjs +0 -1
- package/dist/noop.js +0 -68
- package/dist/selectors-CGCIf0Ac.cjs +0 -1
- package/dist/src/noop/index.d.ts.map +0 -1
- package/dist/state-BX_5GHgM.js +0 -406
- package/dist/state-xseZCh_u.cjs +0 -1
- package/dist/window-Bj8OM9F9.cjs +0 -41
- package/dist/window-DwJfMpbK.js +0 -8620
package/README.md
CHANGED
|
@@ -6,20 +6,20 @@ Building multi-window applications with Tauri and Electron raises the challenge
|
|
|
6
6
|
synchronizing state between windows. Communicating over IPC is unintuitive when used in
|
|
7
7
|
combination with stateful UI frameworks like React.
|
|
8
8
|
|
|
9
|
-
Drift is a simple Redux extension that tightly synchronizes state between windows.
|
|
10
|
-
|
|
9
|
+
Drift is a simple Redux extension that tightly synchronizes state between windows. It
|
|
10
|
+
also allows you to create, delete, and alter windows by dispatching actions.
|
|
11
11
|
|
|
12
12
|
What's more, Drift can prerender windows in the background, allowing new windows to be
|
|
13
13
|
ready to display in a fraction of the typical time.
|
|
14
14
|
|
|
15
|
-
Drift was inspired by the now
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
Drift was inspired by the now unmaintained
|
|
16
|
+
[Electron Redux](https://github.com/klarna/electron-redux), and exposes a much simpler,
|
|
17
|
+
more powerful API.
|
|
18
18
|
|
|
19
19
|
# Supported Runtimes
|
|
20
20
|
|
|
21
21
|
| Runtime | Supported | Import |
|
|
22
|
-
|
|
22
|
+
| -------- | ------------------------------------------------------------------------- | -------------------------------------------------------- |
|
|
23
23
|
| Tauri | Yes | `import { TauriRuntime } from "@synnaxlabs/drift/tauri"` |
|
|
24
24
|
| Electron | No. We're looking for someone to add Electron support! Please contribute. | TBA |
|
|
25
25
|
|
|
@@ -50,31 +50,31 @@ pnpm add @synnaxlabs/drift
|
|
|
50
50
|
The first step is to reconfigure your store to support Drift. Drift exposes a custom
|
|
51
51
|
`configureStore` function returns a **promise** that resolves to a Redux store. This
|
|
52
52
|
allows Drift to asynchronously fetch the initial state from the main process. In order
|
|
53
|
-
to add declarative window management, you also need to add Drift's custom `reducer`
|
|
54
|
-
|
|
53
|
+
to add declarative window management, you also need to add Drift's custom `reducer` to
|
|
54
|
+
your store.
|
|
55
55
|
|
|
56
56
|
```ts
|
|
57
57
|
// store configuration file
|
|
58
58
|
|
|
59
59
|
import {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
} from "@synnaxlabs/drift"
|
|
60
|
+
reducer as driftReducer,
|
|
61
|
+
configureStore,
|
|
62
|
+
DRIFT_SLICE_NAME,
|
|
63
|
+
TauriRuntime,
|
|
64
|
+
} from "@synnaxlabs/drift";
|
|
65
65
|
|
|
66
|
-
import {combineReducers} from "@reduxjs/toolkit"
|
|
66
|
+
import { combineReducers } from "@reduxjs/toolkit";
|
|
67
67
|
|
|
68
68
|
const reducer = combineReducers({
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
})
|
|
69
|
+
[DRIFT_SLICE_NAME]: driftReducer,
|
|
70
|
+
// ... your other reducers
|
|
71
|
+
});
|
|
72
72
|
|
|
73
73
|
export const storePromise = configureStore({
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
})
|
|
74
|
+
runtime: new TauriRuntime(),
|
|
75
|
+
reducer,
|
|
76
|
+
enablePrerender: true,
|
|
77
|
+
});
|
|
78
78
|
```
|
|
79
79
|
|
|
80
80
|
Next, we've created a custom `Provider` that automatically resolves the store promise
|
|
@@ -83,14 +83,10 @@ and works exactly like the standard Redux `Provider`.
|
|
|
83
83
|
```tsx
|
|
84
84
|
// in your main application file
|
|
85
85
|
|
|
86
|
-
import {Provider} from "@synnaxlabs/drift/react"
|
|
87
|
-
import {storePromise} from "./store"
|
|
86
|
+
import { Provider } from "@synnaxlabs/drift/react";
|
|
87
|
+
import { storePromise } from "./store";
|
|
88
88
|
|
|
89
|
-
return
|
|
90
|
-
<Provider store={storePromise}>
|
|
91
|
-
{/* Your stateful application code*/}
|
|
92
|
-
</Provider>
|
|
93
|
-
)
|
|
89
|
+
return <Provider store={storePromise}>{/* Your stateful application code*/}</Provider>;
|
|
94
90
|
```
|
|
95
91
|
|
|
96
92
|
State should now be synchronized between all of your Windows!
|
|
@@ -100,25 +96,24 @@ State should now be synchronized between all of your Windows!
|
|
|
100
96
|
Creating a Window is as easy as dispatching a `createWindow` action.
|
|
101
97
|
|
|
102
98
|
```ts
|
|
103
|
-
import {useDispatch} from "react-redux";
|
|
104
|
-
import {createWindow} from "@synnaxlabs/drift"
|
|
105
|
-
import {useEffect} from "react";
|
|
99
|
+
import { useDispatch } from "react-redux";
|
|
100
|
+
import { createWindow } from "@synnaxlabs/drift";
|
|
101
|
+
import { useEffect } from "react";
|
|
106
102
|
|
|
107
103
|
export const MyReactComponent = () => {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
104
|
+
const dispatch = useDispatch();
|
|
105
|
+
|
|
106
|
+
useEffect(() => {
|
|
107
|
+
dispatch(
|
|
108
|
+
createWindow({
|
|
109
|
+
key: "exampleWindow",
|
|
110
|
+
title: "Example Window",
|
|
111
|
+
width: 800,
|
|
112
|
+
height: 600,
|
|
113
|
+
}),
|
|
114
|
+
);
|
|
115
|
+
}, [dispatch]);
|
|
116
|
+
};
|
|
122
117
|
```
|
|
123
118
|
|
|
124
119
|
The `key` property is used to uniquely identify the window. If a window with the same
|
|
@@ -127,19 +122,17 @@ key already exists, Drift will focus that window instead of creating a new one.
|
|
|
127
122
|
You can also dispatch a `closeWindow` action to close a window.
|
|
128
123
|
|
|
129
124
|
```tsx
|
|
130
|
-
import {useDispatch} from "react-redux";
|
|
131
|
-
import {closeWindow} from "@synnaxlabs/drift"
|
|
132
|
-
import {useEffect} from "react";
|
|
125
|
+
import { useDispatch } from "react-redux";
|
|
126
|
+
import { closeWindow } from "@synnaxlabs/drift";
|
|
127
|
+
import { useEffect } from "react";
|
|
133
128
|
|
|
134
129
|
export const MyReactComponent = () => {
|
|
135
|
-
|
|
130
|
+
const dispatch = useDispatch();
|
|
136
131
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
}
|
|
132
|
+
useEffect(() => {
|
|
133
|
+
dispatch(closeWindow({ key: "exampleWindow" }));
|
|
134
|
+
}, [dispatch]);
|
|
135
|
+
};
|
|
143
136
|
```
|
|
144
137
|
|
|
145
138
|
## Accessing Window State
|
|
@@ -159,4 +152,3 @@ export const MyReactComponent = () => {
|
|
|
159
152
|
}, [window])
|
|
160
153
|
}
|
|
161
154
|
```
|
|
162
|
-
|
package/dist/electron.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("./state-yfMrLzJG.cjs"),v=require("./debounce-BUAIXXZt.cjs"),u="drift://action",m="drift://create",_="drift://focus",S="drift://close",p="drift://set-minimized",w="drift://set-maximized",b="drift://set-visible",I="drift://set-fullscreen",N="drift://center",z="drift://set-position",y="drift://set-size",M="drift://set-min-size",O="drift://set-max-size",A="drift://set-resizable",g="drift://set-skip-taskbar",V="drift://set-always-on-top",x="drift://set-title",D="drift://set-decorations",T="drift://get-props",W="drift://get-label",R=[u,m,_,S,p,w,b,I,N,z,y,M,O,A,g,V,x,D,T],B=t=>{if(!R.includes(t))throw new Error(`Event ${t} is not on the list of allowed events`)},H=[u],Z=t=>{if(!H.includes(t))throw new Error(`Event ${t} is not on the list of allowed events`)},q=[T,W],F=t=>{if(!q.includes(t))throw new Error(`Command ${t} is not on the list of allowed commands`)},U=t=>({x:t.position?.x,y:t.position?.y,width:t.size?.width,height:t.size?.height,center:t.center,minHeight:t.minSize?.height,minWidth:t.minSize?.width,maxHeight:t.maxSize?.height,maxWidth:t.maxSize?.width,resizable:t.resizable,fullscreen:t.fullscreen,skipTaskbar:t.skipTaskbar,title:t.title,show:t.visible,transparent:t.transparent,alwaysOnTop:t.alwaysOnTop}),$=t=>{const[s,a]=t.getSize(),[o,l]=t.getPosition();return{size:{width:s,height:a},position:{x:o,y:l},minimized:t.isMinimized(),maximized:t.isMaximized(),fullscreen:t.isFullScreen(),visible:t.isVisible(),resizable:t.isResizable(),skipTaskbar:!1,title:t.getTitle(),alwaysOnTop:t.isAlwaysOnTop(),decorations:!1}},G=({mainWindow:t,createWindow:s})=>{const a=new Map,o=new Map;a.set(f.MAIN_WINDOW,t.id),o.set(t.id,f.MAIN_WINDOW);const{ipcMain:l,BrowserWindow:E}=require("electron"),d=(i,e)=>l.on(i,(n,r)=>{const c=E.fromWebContents(n.sender);c!=null&&e(c,r)});l.on(S,(i,e)=>{const n=a.get(e);if(n==null)return;const r=E.fromId(n);r!=null&&(r.close(),a.delete(e),o.delete(n))}),l.handle(T,i=>{const e=E.fromWebContents(i.sender);return e==null?void 0:{...$(e),label:o.get(e.id)}}),l.handle(W,i=>{const e=E.fromWebContents(i.sender);if(e!=null)return o.get(e.id)});const C=(i,e,n)=>{i.on(e,v.o(n,500))},P=i=>{for(const e of o.keys())E.fromId(e)?.webContents.send(u,i)},k=(i,e)=>{const n=(r,c)=>{C(e,r,()=>{P({action:f.runtimeSetWindowProps({label:i,...c(e)}),emitter:"WHITELIST"})})};n("resize",r=>{const[c,L]=r.getSize();return{size:{width:c,height:L}}}),n("move",()=>{const[r,c]=e.getPosition();return{position:{x:r,y:c}}}),n("minimize",()=>({minimized:!0})),n("restore",()=>({minimized:!1})),n("maximize",()=>({maximized:!0})),n("unmaximize",()=>({maximized:!1})),n("enter-full-screen",r=>(r.setWindowButtonVisibility(!0),{fullscreen:!0})),n("leave-full-screen",()=>(e.setWindowButtonVisibility(!1),{fullscreen:!1}))};k(f.MAIN_WINDOW,t),d(_,i=>i.focus()),d(p,i=>i.minimize()),d(w,i=>i.maximize()),d(b,(i,e)=>e?i.show():i.hide()),d(I,i=>i.setFullScreen(!0)),d(N,i=>i.center()),d(z,(i,{x:e,y:n})=>{i.setPosition(Math.round(e),Math.round(n))}),d(y,(i,{width:e,height:n})=>{i.setSize(Math.round(e),Math.round(n))}),d(M,(i,{width:e,height:n})=>i.setMinimumSize(Math.round(e),Math.round(n))),d(O,(i,{width:e,height:n})=>i.setMaximumSize(Math.round(e),Math.round(n))),d(A,(i,e)=>i.setResizable(e)),d(g,(i,e)=>i.setSkipTaskbar(e)),d(V,(i,e)=>i.setAlwaysOnTop(e)),d(x,(i,e)=>i.setTitle(e)),l.on(m,(i,e,n)=>{const r=s(U(n));a.set(e,r.id),o.set(r.id,e),k(e,r)}),l.on(u,(i,e,n)=>{if(e==null)return;if(n==null)return P(e);const r=a.get(n);if(r==null)return;const c=E.fromId(r);c?.webContents.send(u,e)})},h="driftAPI",J=()=>{const{ipcRenderer:t,contextBridge:s}=require("electron"),a={send:(o,...l)=>{B(o),t.send(o,...l)},invoke:async(o,...l)=>(F(o),await t.invoke(o,...l)),on:(o,l)=>{Z(o),t.on(o,l)}};s.exposeInMainWorld(h,a)},K=async()=>{if(!(h in window))throw new Error("Drift API not found. Make sure to call configurePreload in your preload script.");return await window[h].invoke(W)};class X{_label="";props=null;api;constructor(){if(!(h in window))throw new Error("Drift API not found. Make sure to call configurePreload in your preload script.");this.api=window[h]}async configure(){const{label:s,...a}=await this.api.invoke(T);this._label=s,this.props=a}label(){return this._label}isMain(){return this._label===f.MAIN_WINDOW}release(){}async emit(s,a){this.api.send(u,{...s,emitter:this.label()},a)}async subscribe(s){this.api.on(u,(a,o)=>s(o))}onCloseRequested(){}async create(s,a){this.api.send(m,s,JSON.parse(JSON.stringify(a)))}async close(s){this.api.send(S,s)}async listLabels(){return[]}async focus(){this.api.send(_)}async setMinimized(s){this.api.send(p,s)}async setMaximized(s){this.api.send(w,s)}async setVisible(s){this.api.send(b,s)}async setFullscreen(s){this.api.send(I,s)}async center(){this.api.send(N)}async setPosition(s){this.api.send(z,s)}async setSize(s){this.api.send(y,s)}async setMinSize(s){this.api.send(M,s)}async setMaxSize(s){this.api.send(O,s)}async setResizable(s){this.api.send(A,s)}async setSkipTaskbar(s){this.api.send(g,s)}async setAlwaysOnTop(s){this.api.send(V,s)}async setTitle(s){this.api.send(x,s)}async setDecorations(s){this.api.send(D,s)}async getProps(){if(this.props!=null)return this.props;throw new Error("Window not found")}}exports.ElectronRuntime=X;exports.exposeAPI=J;exports.getWindowLabel=K;exports.listenOnMain=G;
|
package/dist/electron.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
E,
|
|
1
|
+
import { M as h, r as v } from "./state-D41-Dai4.js";
|
|
2
|
+
import { o as R } from "./debounce-DOZKRZa9.js";
|
|
3
|
+
const u = "drift://action", m = "drift://create", _ = "drift://focus", p = "drift://close", S = "drift://set-minimized", w = "drift://set-maximized", z = "drift://set-visible", b = "drift://set-fullscreen", y = "drift://center", I = "drift://set-position", N = "drift://set-size", M = "drift://set-min-size", O = "drift://set-max-size", g = "drift://set-resizable", A = "drift://set-skip-taskbar", V = "drift://set-always-on-top", x = "drift://set-title", W = "drift://set-decorations", T = "drift://get-props", k = "drift://get-label", B = [
|
|
4
|
+
u,
|
|
5
|
+
m,
|
|
6
|
+
_,
|
|
7
|
+
p,
|
|
9
8
|
S,
|
|
10
9
|
w,
|
|
11
10
|
z,
|
|
@@ -19,45 +18,39 @@ const E = "drift://action", S = "drift://create", w = "drift://focus", z = "drif
|
|
|
19
18
|
A,
|
|
20
19
|
V,
|
|
21
20
|
x,
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
p
|
|
27
|
-
], U = (t) => {
|
|
28
|
-
if (!F.includes(t))
|
|
21
|
+
W,
|
|
22
|
+
T
|
|
23
|
+
], H = (t) => {
|
|
24
|
+
if (!B.includes(t))
|
|
29
25
|
throw new Error(`Event ${t} is not on the list of allowed events`);
|
|
30
|
-
},
|
|
31
|
-
if (!
|
|
26
|
+
}, Z = [u], F = (t) => {
|
|
27
|
+
if (!Z.includes(t))
|
|
32
28
|
throw new Error(`Event ${t} is not on the list of allowed events`);
|
|
33
|
-
},
|
|
34
|
-
if (!
|
|
29
|
+
}, U = [T, k], q = (t) => {
|
|
30
|
+
if (!U.includes(t))
|
|
35
31
|
throw new Error(`Command ${t} is not on the list of allowed commands`);
|
|
36
|
-
},
|
|
37
|
-
|
|
32
|
+
}, $ = (t) => ({
|
|
33
|
+
x: t.position?.x,
|
|
34
|
+
y: t.position?.y,
|
|
35
|
+
width: t.size?.width,
|
|
36
|
+
height: t.size?.height,
|
|
37
|
+
center: t.center,
|
|
38
|
+
minHeight: t.minSize?.height,
|
|
39
|
+
minWidth: t.minSize?.width,
|
|
40
|
+
maxHeight: t.maxSize?.height,
|
|
41
|
+
maxWidth: t.maxSize?.width,
|
|
42
|
+
resizable: t.resizable,
|
|
43
|
+
fullscreen: t.fullscreen,
|
|
44
|
+
skipTaskbar: t.skipTaskbar,
|
|
45
|
+
title: t.title,
|
|
46
|
+
show: t.visible,
|
|
47
|
+
transparent: t.transparent,
|
|
48
|
+
alwaysOnTop: t.alwaysOnTop
|
|
49
|
+
}), G = (t) => {
|
|
50
|
+
const [s, a] = t.getSize(), [o, l] = t.getPosition();
|
|
38
51
|
return {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
width: (r = t.size) == null ? void 0 : r.width,
|
|
42
|
-
height: (l = t.size) == null ? void 0 : l.height,
|
|
43
|
-
center: t.center,
|
|
44
|
-
minHeight: (u = t.minSize) == null ? void 0 : u.height,
|
|
45
|
-
minWidth: (d = t.minSize) == null ? void 0 : d.width,
|
|
46
|
-
maxHeight: (T = t.maxSize) == null ? void 0 : T.height,
|
|
47
|
-
maxWidth: (f = t.maxSize) == null ? void 0 : f.width,
|
|
48
|
-
resizable: t.resizable,
|
|
49
|
-
fullscreen: t.fullscreen,
|
|
50
|
-
skipTaskbar: t.skipTaskbar,
|
|
51
|
-
title: t.title,
|
|
52
|
-
show: t.visible,
|
|
53
|
-
transparent: t.transparent,
|
|
54
|
-
alwaysOnTop: t.alwaysOnTop
|
|
55
|
-
};
|
|
56
|
-
}, X = (t) => {
|
|
57
|
-
const [e, o] = t.getSize(), [r, l] = t.getPosition();
|
|
58
|
-
return {
|
|
59
|
-
size: { width: e, height: o },
|
|
60
|
-
position: { x: r, y: l },
|
|
52
|
+
size: { width: s, height: a },
|
|
53
|
+
position: { x: o, y: l },
|
|
61
54
|
minimized: t.isMinimized(),
|
|
62
55
|
maximized: t.isMaximized(),
|
|
63
56
|
fullscreen: t.isFullScreen(),
|
|
@@ -68,181 +61,180 @@ const E = "drift://action", S = "drift://create", w = "drift://focus", z = "drif
|
|
|
68
61
|
alwaysOnTop: t.isAlwaysOnTop(),
|
|
69
62
|
decorations: !1
|
|
70
63
|
};
|
|
71
|
-
},
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
const { ipcMain: l, BrowserWindow:
|
|
75
|
-
const c =
|
|
76
|
-
c != null &&
|
|
64
|
+
}, X = ({ mainWindow: t, createWindow: s }) => {
|
|
65
|
+
const a = /* @__PURE__ */ new Map(), o = /* @__PURE__ */ new Map();
|
|
66
|
+
a.set(h, t.id), o.set(t.id, h);
|
|
67
|
+
const { ipcMain: l, BrowserWindow: E } = require("electron"), d = (i, e) => l.on(i, (n, r) => {
|
|
68
|
+
const c = E.fromWebContents(n.sender);
|
|
69
|
+
c != null && e(c, r);
|
|
77
70
|
});
|
|
78
|
-
l.on(
|
|
79
|
-
const n =
|
|
71
|
+
l.on(p, (i, e) => {
|
|
72
|
+
const n = a.get(e);
|
|
80
73
|
if (n == null) return;
|
|
81
|
-
const
|
|
82
|
-
|
|
83
|
-
}), l.handle(
|
|
84
|
-
const
|
|
85
|
-
return
|
|
86
|
-
}), l.handle(
|
|
87
|
-
const
|
|
88
|
-
if (
|
|
89
|
-
return
|
|
74
|
+
const r = E.fromId(n);
|
|
75
|
+
r != null && (r.close(), a.delete(e), o.delete(n));
|
|
76
|
+
}), l.handle(T, (i) => {
|
|
77
|
+
const e = E.fromWebContents(i.sender);
|
|
78
|
+
return e == null ? void 0 : { ...G(e), label: o.get(e.id) };
|
|
79
|
+
}), l.handle(k, (i) => {
|
|
80
|
+
const e = E.fromWebContents(i.sender);
|
|
81
|
+
if (e != null)
|
|
82
|
+
return o.get(e.id);
|
|
90
83
|
});
|
|
91
|
-
const
|
|
92
|
-
|
|
93
|
-
},
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
action: H({ label: s, ...c(i) }),
|
|
84
|
+
const D = (i, e, n) => {
|
|
85
|
+
i.on(e, R(n, 500));
|
|
86
|
+
}, C = (i) => {
|
|
87
|
+
for (const e of o.keys())
|
|
88
|
+
E.fromId(e)?.webContents.send(u, i);
|
|
89
|
+
}, P = (i, e) => {
|
|
90
|
+
const n = (r, c) => {
|
|
91
|
+
D(e, r, () => {
|
|
92
|
+
C({
|
|
93
|
+
action: v({ label: i, ...c(e) }),
|
|
102
94
|
emitter: "WHITELIST"
|
|
103
95
|
});
|
|
104
96
|
});
|
|
105
97
|
};
|
|
106
|
-
n("resize", (
|
|
107
|
-
const [c,
|
|
108
|
-
return { size: { width: c, height:
|
|
98
|
+
n("resize", (r) => {
|
|
99
|
+
const [c, L] = r.getSize();
|
|
100
|
+
return { size: { width: c, height: L } };
|
|
109
101
|
}), n("move", () => {
|
|
110
|
-
const [
|
|
111
|
-
return { position: { x:
|
|
112
|
-
}), n("minimize", () => ({ minimized: !0 })), n("restore", () => ({ minimized: !1 })), n("maximize", () => ({ maximized: !0 })), n("unmaximize", () => ({ maximized: !1 })), n("enter-full-screen", (
|
|
102
|
+
const [r, c] = e.getPosition();
|
|
103
|
+
return { position: { x: r, y: c } };
|
|
104
|
+
}), n("minimize", () => ({ minimized: !0 })), n("restore", () => ({ minimized: !1 })), n("maximize", () => ({ maximized: !0 })), n("unmaximize", () => ({ maximized: !1 })), n("enter-full-screen", (r) => (r.setWindowButtonVisibility(!0), { fullscreen: !0 })), n("leave-full-screen", () => (e.setWindowButtonVisibility(!1), { fullscreen: !1 }));
|
|
113
105
|
};
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
}), d(
|
|
117
|
-
|
|
106
|
+
P(h, t), d(_, (i) => i.focus()), d(S, (i) => i.minimize()), d(w, (i) => i.maximize()), d(z, (i, e) => e ? i.show() : i.hide()), d(b, (i) => i.setFullScreen(!0)), d(y, (i) => i.center()), d(I, (i, { x: e, y: n }) => {
|
|
107
|
+
i.setPosition(Math.round(e), Math.round(n));
|
|
108
|
+
}), d(N, (i, { width: e, height: n }) => {
|
|
109
|
+
i.setSize(Math.round(e), Math.round(n));
|
|
118
110
|
}), d(
|
|
111
|
+
M,
|
|
112
|
+
(i, { width: e, height: n }) => i.setMinimumSize(Math.round(e), Math.round(n))
|
|
113
|
+
), d(
|
|
114
|
+
O,
|
|
115
|
+
(i, { width: e, height: n }) => i.setMaximumSize(Math.round(e), Math.round(n))
|
|
116
|
+
), d(g, (i, e) => i.setResizable(e)), d(
|
|
119
117
|
A,
|
|
120
|
-
(
|
|
118
|
+
(i, e) => i.setSkipTaskbar(e)
|
|
121
119
|
), d(
|
|
122
120
|
V,
|
|
123
|
-
(
|
|
124
|
-
), d(x, (
|
|
125
|
-
|
|
126
|
-
(
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
(s, i) => s.setAlwaysOnTop(i)
|
|
130
|
-
), d(P, (s, i) => s.setTitle(i)), l.on(
|
|
131
|
-
S,
|
|
132
|
-
(s, i, n) => {
|
|
133
|
-
const a = e(K(n));
|
|
134
|
-
o.set(i, a.id), r.set(a.id, i), D(i, a);
|
|
121
|
+
(i, e) => i.setAlwaysOnTop(e)
|
|
122
|
+
), d(x, (i, e) => i.setTitle(e)), l.on(
|
|
123
|
+
m,
|
|
124
|
+
(i, e, n) => {
|
|
125
|
+
const r = s($(n));
|
|
126
|
+
a.set(e, r.id), o.set(r.id, e), P(e, r);
|
|
135
127
|
}
|
|
136
|
-
), l.on(
|
|
137
|
-
if (
|
|
138
|
-
if (n == null) return
|
|
139
|
-
const
|
|
140
|
-
if (
|
|
141
|
-
const c =
|
|
142
|
-
c
|
|
128
|
+
), l.on(u, (i, e, n) => {
|
|
129
|
+
if (e == null) return;
|
|
130
|
+
if (n == null) return C(e);
|
|
131
|
+
const r = a.get(n);
|
|
132
|
+
if (r == null) return;
|
|
133
|
+
const c = E.fromId(r);
|
|
134
|
+
c?.webContents.send(u, e);
|
|
143
135
|
});
|
|
144
|
-
},
|
|
145
|
-
const { ipcRenderer: t, contextBridge:
|
|
146
|
-
send: (
|
|
147
|
-
|
|
136
|
+
}, f = "driftAPI", Y = () => {
|
|
137
|
+
const { ipcRenderer: t, contextBridge: s } = require("electron"), a = {
|
|
138
|
+
send: (o, ...l) => {
|
|
139
|
+
H(o), t.send(o, ...l);
|
|
148
140
|
},
|
|
149
|
-
invoke: async (
|
|
150
|
-
on: (
|
|
151
|
-
|
|
141
|
+
invoke: async (o, ...l) => (q(o), await t.invoke(o, ...l)),
|
|
142
|
+
on: (o, l) => {
|
|
143
|
+
F(o), t.on(o, l);
|
|
152
144
|
}
|
|
153
145
|
};
|
|
154
|
-
|
|
155
|
-
},
|
|
156
|
-
if (!(
|
|
146
|
+
s.exposeInMainWorld(f, a);
|
|
147
|
+
}, j = async () => {
|
|
148
|
+
if (!(f in window))
|
|
157
149
|
throw new Error(
|
|
158
150
|
"Drift API not found. Make sure to call configurePreload in your preload script."
|
|
159
151
|
);
|
|
160
|
-
return await window[
|
|
152
|
+
return await window[f].invoke(k);
|
|
161
153
|
};
|
|
162
|
-
class
|
|
154
|
+
class Q {
|
|
155
|
+
_label = "";
|
|
156
|
+
props = null;
|
|
157
|
+
api;
|
|
163
158
|
constructor() {
|
|
164
|
-
|
|
165
|
-
m(this, "props", null);
|
|
166
|
-
m(this, "api");
|
|
167
|
-
if (!(h in window))
|
|
159
|
+
if (!(f in window))
|
|
168
160
|
throw new Error(
|
|
169
161
|
"Drift API not found. Make sure to call configurePreload in your preload script."
|
|
170
162
|
);
|
|
171
|
-
this.api = window[
|
|
163
|
+
this.api = window[f];
|
|
172
164
|
}
|
|
173
165
|
async configure() {
|
|
174
|
-
const { label:
|
|
175
|
-
this._label =
|
|
166
|
+
const { label: s, ...a } = await this.api.invoke(T);
|
|
167
|
+
this._label = s, this.props = a;
|
|
176
168
|
}
|
|
177
169
|
label() {
|
|
178
170
|
return this._label;
|
|
179
171
|
}
|
|
180
172
|
isMain() {
|
|
181
|
-
return this._label ===
|
|
173
|
+
return this._label === h;
|
|
182
174
|
}
|
|
183
175
|
release() {
|
|
184
176
|
}
|
|
185
|
-
async emit(
|
|
186
|
-
this.api.send(
|
|
177
|
+
async emit(s, a) {
|
|
178
|
+
this.api.send(u, { ...s, emitter: this.label() }, a);
|
|
187
179
|
}
|
|
188
|
-
async subscribe(
|
|
189
|
-
this.api.on(
|
|
180
|
+
async subscribe(s) {
|
|
181
|
+
this.api.on(u, (a, o) => s(o));
|
|
190
182
|
}
|
|
191
183
|
onCloseRequested() {
|
|
192
184
|
}
|
|
193
|
-
async create(
|
|
194
|
-
this.api.send(
|
|
185
|
+
async create(s, a) {
|
|
186
|
+
this.api.send(m, s, JSON.parse(JSON.stringify(a)));
|
|
195
187
|
}
|
|
196
|
-
async close(
|
|
197
|
-
this.api.send(
|
|
188
|
+
async close(s) {
|
|
189
|
+
this.api.send(p, s);
|
|
198
190
|
}
|
|
199
191
|
async listLabels() {
|
|
200
192
|
return [];
|
|
201
193
|
}
|
|
202
194
|
async focus() {
|
|
203
|
-
this.api.send(
|
|
195
|
+
this.api.send(_);
|
|
204
196
|
}
|
|
205
|
-
async setMinimized(
|
|
206
|
-
this.api.send(
|
|
197
|
+
async setMinimized(s) {
|
|
198
|
+
this.api.send(S, s);
|
|
207
199
|
}
|
|
208
|
-
async setMaximized(
|
|
209
|
-
this.api.send(
|
|
200
|
+
async setMaximized(s) {
|
|
201
|
+
this.api.send(w, s);
|
|
210
202
|
}
|
|
211
|
-
async setVisible(
|
|
212
|
-
this.api.send(
|
|
203
|
+
async setVisible(s) {
|
|
204
|
+
this.api.send(z, s);
|
|
213
205
|
}
|
|
214
|
-
async setFullscreen(
|
|
215
|
-
this.api.send(
|
|
206
|
+
async setFullscreen(s) {
|
|
207
|
+
this.api.send(b, s);
|
|
216
208
|
}
|
|
217
209
|
async center() {
|
|
218
|
-
this.api.send(
|
|
210
|
+
this.api.send(y);
|
|
219
211
|
}
|
|
220
|
-
async setPosition(
|
|
221
|
-
this.api.send(
|
|
212
|
+
async setPosition(s) {
|
|
213
|
+
this.api.send(I, s);
|
|
222
214
|
}
|
|
223
|
-
async setSize(
|
|
224
|
-
this.api.send(
|
|
215
|
+
async setSize(s) {
|
|
216
|
+
this.api.send(N, s);
|
|
225
217
|
}
|
|
226
|
-
async setMinSize(
|
|
227
|
-
this.api.send(
|
|
218
|
+
async setMinSize(s) {
|
|
219
|
+
this.api.send(M, s);
|
|
228
220
|
}
|
|
229
|
-
async setMaxSize(
|
|
230
|
-
this.api.send(
|
|
221
|
+
async setMaxSize(s) {
|
|
222
|
+
this.api.send(O, s);
|
|
231
223
|
}
|
|
232
|
-
async setResizable(
|
|
233
|
-
this.api.send(
|
|
224
|
+
async setResizable(s) {
|
|
225
|
+
this.api.send(g, s);
|
|
234
226
|
}
|
|
235
|
-
async setSkipTaskbar(
|
|
236
|
-
this.api.send(
|
|
227
|
+
async setSkipTaskbar(s) {
|
|
228
|
+
this.api.send(A, s);
|
|
237
229
|
}
|
|
238
|
-
async setAlwaysOnTop(
|
|
239
|
-
this.api.send(
|
|
230
|
+
async setAlwaysOnTop(s) {
|
|
231
|
+
this.api.send(V, s);
|
|
240
232
|
}
|
|
241
|
-
async setTitle(
|
|
242
|
-
this.api.send(
|
|
233
|
+
async setTitle(s) {
|
|
234
|
+
this.api.send(x, s);
|
|
243
235
|
}
|
|
244
|
-
async setDecorations(
|
|
245
|
-
this.api.send(
|
|
236
|
+
async setDecorations(s) {
|
|
237
|
+
this.api.send(W, s);
|
|
246
238
|
}
|
|
247
239
|
async getProps() {
|
|
248
240
|
if (this.props != null) return this.props;
|
|
@@ -250,8 +242,8 @@ class ne {
|
|
|
250
242
|
}
|
|
251
243
|
}
|
|
252
244
|
export {
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
245
|
+
Q as ElectronRuntime,
|
|
246
|
+
Y as exposeAPI,
|
|
247
|
+
j as getWindowLabel,
|
|
248
|
+
X as listenOnMain
|
|
257
249
|
};
|