@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 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
- It also allows you to create, delete, and alter windows by dispatching actions.
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
- unmaintained [Electron Redux](https://github.com/klarna/electron-redux),
17
- and exposes a much simpler, more powerful API.
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
- to your store.
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
- reducer as driftReducer,
61
- configureStore,
62
- DRIFT_SLICE_NAME,
63
- TauriRuntime,
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
- [DRIFT_SLICE_NAME]: driftReducer,
70
- // ... your other reducers
71
- })
69
+ [DRIFT_SLICE_NAME]: driftReducer,
70
+ // ... your other reducers
71
+ });
72
72
 
73
73
  export const storePromise = configureStore({
74
- runtime: new TauriRuntime(),
75
- reducer,
76
- enablePrerender: true,
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
- const dispatch = useDispatch()
109
-
110
- useEffect(() => {
111
- dispatch(createWindow({
112
- key: "exampleWindow",
113
- title: "Example Window",
114
- width: 800,
115
- height: 600,
116
- }))
117
- }, [dispatch])
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
- const dispatch = useDispatch()
130
+ const dispatch = useDispatch();
136
131
 
137
- useEffect(() => {
138
- dispatch(closeWindow({key: "exampleWindow"}))
139
- }, [dispatch])
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";var R=Object.defineProperty;var B=(t,e,o)=>e in t?R(t,e,{enumerable:!0,configurable:!0,writable:!0,value:o}):t[e]=o;var m=(t,e,o)=>B(t,typeof e!="symbol"?e+"":e,o);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const _=require("./window-Bj8OM9F9.cjs"),q=require("./state-xseZCh_u.cjs"),H=require("./debounce-BUAIXXZt.cjs"),E="drift://action",p="drift://create",w="drift://focus",b="drift://close",I="drift://set-minimized",N="drift://set-maximized",z="drift://set-visible",y="drift://set-fullscreen",M="drift://center",O="drift://set-position",A="drift://set-size",g="drift://set-min-size",V="drift://set-max-size",x="drift://set-resizable",W="drift://set-skip-taskbar",P="drift://set-always-on-top",k="drift://set-title",L="drift://set-decorations",S="drift://get-props",D="drift://get-label",Z=[E,p,w,b,I,N,z,y,M,O,A,g,V,x,W,P,k,L,S],F=t=>{if(!Z.includes(t))throw new Error(`Event ${t} is not on the list of allowed events`)},U=[E],$=t=>{if(!U.includes(t))throw new Error(`Event ${t} is not on the list of allowed events`)},G=[S,D],J=t=>{if(!G.includes(t))throw new Error(`Command ${t} is not on the list of allowed commands`)},K=t=>{var e,o,r,l,u,d,T,f;return{x:(e=t.position)==null?void 0:e.x,y:(o=t.position)==null?void 0:o.y,width:(r=t.size)==null?void 0:r.width,height:(l=t.size)==null?void 0:l.height,center:t.center,minHeight:(u=t.minSize)==null?void 0:u.height,minWidth:(d=t.minSize)==null?void 0:d.width,maxHeight:(T=t.maxSize)==null?void 0:T.height,maxWidth:(f=t.maxSize)==null?void 0:f.width,resizable:t.resizable,fullscreen:t.fullscreen,skipTaskbar:t.skipTaskbar,title:t.title,show:t.visible,transparent:t.transparent,alwaysOnTop:t.alwaysOnTop}},X=t=>{const[e,o]=t.getSize(),[r,l]=t.getPosition();return{size:{width:e,height:o},position:{x:r,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}},j=({mainWindow:t,createWindow:e})=>{const o=new Map,r=new Map;o.set(_.MAIN_WINDOW,t.id),r.set(t.id,_.MAIN_WINDOW);const{ipcMain:l,BrowserWindow:u}=require("electron"),d=(s,i)=>l.on(s,(n,a)=>{const c=u.fromWebContents(n.sender);c!=null&&i(c,a)});l.on(b,(s,i)=>{const n=o.get(i);if(n==null)return;const a=u.fromId(n);a!=null&&(a.close(),o.delete(i),r.delete(n))}),l.handle(S,s=>{const i=u.fromWebContents(s.sender);return i==null?void 0:{...X(i),label:r.get(i.id)}}),l.handle(D,s=>{const i=u.fromWebContents(s.sender);if(i!=null)return r.get(i.id)});const T=(s,i,n)=>{s.on(i,H.o(n,500))},f=s=>{var i;for(const n of r.keys())(i=u.fromId(n))==null||i.webContents.send(E,s)},C=(s,i)=>{const n=(a,c)=>{T(i,a,()=>{f({action:q.runtimeSetWindowProps({label:s,...c(i)}),emitter:"WHITELIST"})})};n("resize",a=>{const[c,v]=a.getSize();return{size:{width:c,height:v}}}),n("move",()=>{const[a,c]=i.getPosition();return{position:{x:a,y:c}}}),n("minimize",()=>({minimized:!0})),n("restore",()=>({minimized:!1})),n("maximize",()=>({maximized:!0})),n("unmaximize",()=>({maximized:!1})),n("enter-full-screen",a=>(a.setWindowButtonVisibility(!0),{fullscreen:!0})),n("leave-full-screen",()=>(i.setWindowButtonVisibility(!1),{fullscreen:!1}))};C(_.MAIN_WINDOW,t),d(w,s=>s.focus()),d(I,s=>s.minimize()),d(N,s=>s.maximize()),d(z,(s,i)=>i?s.show():s.hide()),d(y,s=>s.setFullScreen(!0)),d(M,s=>s.center()),d(O,(s,{x:i,y:n})=>{s.setPosition(Math.round(i),Math.round(n))}),d(A,(s,{width:i,height:n})=>{s.setSize(Math.round(i),Math.round(n))}),d(g,(s,{width:i,height:n})=>s.setMinimumSize(Math.round(i),Math.round(n))),d(V,(s,{width:i,height:n})=>s.setMaximumSize(Math.round(i),Math.round(n))),d(x,(s,i)=>s.setResizable(i)),d(W,(s,i)=>s.setSkipTaskbar(i)),d(P,(s,i)=>s.setAlwaysOnTop(i)),d(k,(s,i)=>s.setTitle(i)),l.on(p,(s,i,n)=>{const a=e(K(n));o.set(i,a.id),r.set(a.id,i),C(i,a)}),l.on(E,(s,i,n)=>{if(i==null)return;if(n==null)return f(i);const a=o.get(n);if(a==null)return;const c=u.fromId(a);c!=null&&c.webContents.send(E,i)})},h="driftAPI",Y=()=>{const{ipcRenderer:t,contextBridge:e}=require("electron"),o={send:(r,...l)=>{F(r),t.send(r,...l)},invoke:async(r,...l)=>(J(r),await t.invoke(r,...l)),on:(r,l)=>{$(r),t.on(r,l)}};e.exposeInMainWorld(h,o)},Q=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(D)};class ee{constructor(){m(this,"_label","");m(this,"props",null);m(this,"api");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:e,...o}=await this.api.invoke(S);this._label=e,this.props=o}label(){return this._label}isMain(){return this._label===_.MAIN_WINDOW}release(){}async emit(e,o){this.api.send(E,{...e,emitter:this.label()},o)}async subscribe(e){this.api.on(E,(o,r)=>e(r))}onCloseRequested(){}async create(e,o){this.api.send(p,e,JSON.parse(JSON.stringify(o)))}async close(e){this.api.send(b,e)}async listLabels(){return[]}async focus(){this.api.send(w)}async setMinimized(e){this.api.send(I,e)}async setMaximized(e){this.api.send(N,e)}async setVisible(e){this.api.send(z,e)}async setFullscreen(e){this.api.send(y,e)}async center(){this.api.send(M)}async setPosition(e){this.api.send(O,e)}async setSize(e){this.api.send(A,e)}async setMinSize(e){this.api.send(g,e)}async setMaxSize(e){this.api.send(V,e)}async setResizable(e){this.api.send(x,e)}async setSkipTaskbar(e){this.api.send(W,e)}async setAlwaysOnTop(e){this.api.send(P,e)}async setTitle(e){this.api.send(k,e)}async setDecorations(e){this.api.send(L,e)}async getProps(){if(this.props!=null)return this.props;throw new Error("Window not found")}}exports.ElectronRuntime=ee;exports.exposeAPI=Y;exports.getWindowLabel=Q;exports.listenOnMain=j;
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
- var R = Object.defineProperty;
2
- var B = (t, e, o) => e in t ? R(t, e, { enumerable: !0, configurable: !0, writable: !0, value: o }) : t[e] = o;
3
- var m = (t, e, o) => B(t, typeof e != "symbol" ? e + "" : e, o);
4
- import { M as _ } from "./window-DwJfMpbK.js";
5
- import { r as H } from "./state-BX_5GHgM.js";
6
- import { o as Z } from "./debounce-DOZKRZa9.js";
7
- const E = "drift://action", S = "drift://create", w = "drift://focus", z = "drift://close", b = "drift://set-minimized", y = "drift://set-maximized", I = "drift://set-visible", N = "drift://set-fullscreen", M = "drift://center", O = "drift://set-position", g = "drift://set-size", A = "drift://set-min-size", V = "drift://set-max-size", x = "drift://set-resizable", k = "drift://set-skip-taskbar", C = "drift://set-always-on-top", P = "drift://set-title", L = "drift://set-decorations", p = "drift://get-props", W = "drift://get-label", F = [
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
- k,
23
- C,
24
- P,
25
- L,
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
- }, q = [E], $ = (t) => {
31
- if (!q.includes(t))
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
- }, G = [p, W], J = (t) => {
34
- if (!G.includes(t))
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
- }, K = (t) => {
37
- var e, o, r, l, u, d, T, f;
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
- x: (e = t.position) == null ? void 0 : e.x,
40
- y: (o = t.position) == null ? void 0 : o.y,
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
- }, te = ({ mainWindow: t, createWindow: e }) => {
72
- const o = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Map();
73
- o.set(_, t.id), r.set(t.id, _);
74
- const { ipcMain: l, BrowserWindow: u } = require("electron"), d = (s, i) => l.on(s, (n, a) => {
75
- const c = u.fromWebContents(n.sender);
76
- c != null && i(c, a);
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(z, (s, i) => {
79
- const n = o.get(i);
71
+ l.on(p, (i, e) => {
72
+ const n = a.get(e);
80
73
  if (n == null) return;
81
- const a = u.fromId(n);
82
- a != null && (a.close(), o.delete(i), r.delete(n));
83
- }), l.handle(p, (s) => {
84
- const i = u.fromWebContents(s.sender);
85
- return i == null ? void 0 : { ...X(i), label: r.get(i.id) };
86
- }), l.handle(W, (s) => {
87
- const i = u.fromWebContents(s.sender);
88
- if (i != null)
89
- return r.get(i.id);
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 T = (s, i, n) => {
92
- s.on(i, Z(n, 500));
93
- }, f = (s) => {
94
- var i;
95
- for (const n of r.keys())
96
- (i = u.fromId(n)) == null || i.webContents.send(E, s);
97
- }, D = (s, i) => {
98
- const n = (a, c) => {
99
- T(i, a, () => {
100
- f({
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", (a) => {
107
- const [c, v] = a.getSize();
108
- return { size: { width: c, height: v } };
98
+ n("resize", (r) => {
99
+ const [c, L] = r.getSize();
100
+ return { size: { width: c, height: L } };
109
101
  }), n("move", () => {
110
- const [a, c] = i.getPosition();
111
- return { position: { x: a, y: c } };
112
- }), n("minimize", () => ({ minimized: !0 })), n("restore", () => ({ minimized: !1 })), n("maximize", () => ({ maximized: !0 })), n("unmaximize", () => ({ maximized: !1 })), n("enter-full-screen", (a) => (a.setWindowButtonVisibility(!0), { fullscreen: !0 })), n("leave-full-screen", () => (i.setWindowButtonVisibility(!1), { fullscreen: !1 }));
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
- D(_, t), d(w, (s) => s.focus()), d(b, (s) => s.minimize()), d(y, (s) => s.maximize()), d(I, (s, i) => i ? s.show() : s.hide()), d(N, (s) => s.setFullScreen(!0)), d(M, (s) => s.center()), d(O, (s, { x: i, y: n }) => {
115
- s.setPosition(Math.round(i), Math.round(n));
116
- }), d(g, (s, { width: i, height: n }) => {
117
- s.setSize(Math.round(i), Math.round(n));
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
- (s, { width: i, height: n }) => s.setMinimumSize(Math.round(i), Math.round(n))
118
+ (i, e) => i.setSkipTaskbar(e)
121
119
  ), d(
122
120
  V,
123
- (s, { width: i, height: n }) => s.setMaximumSize(Math.round(i), Math.round(n))
124
- ), d(x, (s, i) => s.setResizable(i)), d(
125
- k,
126
- (s, i) => s.setSkipTaskbar(i)
127
- ), d(
128
- C,
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(E, (s, i, n) => {
137
- if (i == null) return;
138
- if (n == null) return f(i);
139
- const a = o.get(n);
140
- if (a == null) return;
141
- const c = u.fromId(a);
142
- c != null && c.webContents.send(E, i);
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
- }, h = "driftAPI", ie = () => {
145
- const { ipcRenderer: t, contextBridge: e } = require("electron"), o = {
146
- send: (r, ...l) => {
147
- U(r), t.send(r, ...l);
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 (r, ...l) => (J(r), await t.invoke(r, ...l)),
150
- on: (r, l) => {
151
- $(r), t.on(r, l);
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
- e.exposeInMainWorld(h, o);
155
- }, se = async () => {
156
- if (!(h in window))
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[h].invoke(W);
152
+ return await window[f].invoke(k);
161
153
  };
162
- class ne {
154
+ class Q {
155
+ _label = "";
156
+ props = null;
157
+ api;
163
158
  constructor() {
164
- m(this, "_label", "");
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[h];
163
+ this.api = window[f];
172
164
  }
173
165
  async configure() {
174
- const { label: e, ...o } = await this.api.invoke(p);
175
- this._label = e, this.props = o;
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(e, o) {
186
- this.api.send(E, { ...e, emitter: this.label() }, o);
177
+ async emit(s, a) {
178
+ this.api.send(u, { ...s, emitter: this.label() }, a);
187
179
  }
188
- async subscribe(e) {
189
- this.api.on(E, (o, r) => e(r));
180
+ async subscribe(s) {
181
+ this.api.on(u, (a, o) => s(o));
190
182
  }
191
183
  onCloseRequested() {
192
184
  }
193
- async create(e, o) {
194
- this.api.send(S, e, JSON.parse(JSON.stringify(o)));
185
+ async create(s, a) {
186
+ this.api.send(m, s, JSON.parse(JSON.stringify(a)));
195
187
  }
196
- async close(e) {
197
- this.api.send(z, e);
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(w);
195
+ this.api.send(_);
204
196
  }
205
- async setMinimized(e) {
206
- this.api.send(b, e);
197
+ async setMinimized(s) {
198
+ this.api.send(S, s);
207
199
  }
208
- async setMaximized(e) {
209
- this.api.send(y, e);
200
+ async setMaximized(s) {
201
+ this.api.send(w, s);
210
202
  }
211
- async setVisible(e) {
212
- this.api.send(I, e);
203
+ async setVisible(s) {
204
+ this.api.send(z, s);
213
205
  }
214
- async setFullscreen(e) {
215
- this.api.send(N, e);
206
+ async setFullscreen(s) {
207
+ this.api.send(b, s);
216
208
  }
217
209
  async center() {
218
- this.api.send(M);
210
+ this.api.send(y);
219
211
  }
220
- async setPosition(e) {
221
- this.api.send(O, e);
212
+ async setPosition(s) {
213
+ this.api.send(I, s);
222
214
  }
223
- async setSize(e) {
224
- this.api.send(g, e);
215
+ async setSize(s) {
216
+ this.api.send(N, s);
225
217
  }
226
- async setMinSize(e) {
227
- this.api.send(A, e);
218
+ async setMinSize(s) {
219
+ this.api.send(M, s);
228
220
  }
229
- async setMaxSize(e) {
230
- this.api.send(V, e);
221
+ async setMaxSize(s) {
222
+ this.api.send(O, s);
231
223
  }
232
- async setResizable(e) {
233
- this.api.send(x, e);
224
+ async setResizable(s) {
225
+ this.api.send(g, s);
234
226
  }
235
- async setSkipTaskbar(e) {
236
- this.api.send(k, e);
227
+ async setSkipTaskbar(s) {
228
+ this.api.send(A, s);
237
229
  }
238
- async setAlwaysOnTop(e) {
239
- this.api.send(C, e);
230
+ async setAlwaysOnTop(s) {
231
+ this.api.send(V, s);
240
232
  }
241
- async setTitle(e) {
242
- this.api.send(P, e);
233
+ async setTitle(s) {
234
+ this.api.send(x, s);
243
235
  }
244
- async setDecorations(e) {
245
- this.api.send(L, e);
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
- ne as ElectronRuntime,
254
- ie as exposeAPI,
255
- se as getWindowLabel,
256
- te as listenOnMain
245
+ Q as ElectronRuntime,
246
+ Y as exposeAPI,
247
+ j as getWindowLabel,
248
+ X as listenOnMain
257
249
  };