@synnaxlabs/drift 0.42.1 → 0.43.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-DLsE0-fP.cjs"),q=require("./state-Cl8us-b9.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";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 _=(t,e,o)=>B(t,typeof e!="symbol"?e+"":e,o);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const h=require("./state-BGByXBtX.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],q=t=>{if(!Z.includes(t))throw new Error(`Event ${t} is not on the list of allowed events`)},F=[E],U=t=>{if(!F.includes(t))throw new Error(`Event ${t} is not on the list of allowed events`)},$=[S,D],G=t=>{if(!$.includes(t))throw new Error(`Command ${t} is not on the list of allowed commands`)},J=t=>{var e,o,r,l,u,d,m,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:(m=t.maxSize)==null?void 0:m.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}},K=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}},X=({mainWindow:t,createWindow:e})=>{const o=new Map,r=new Map;o.set(h.MAIN_WINDOW,t.id),r.set(t.id,h.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:{...K(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 m=(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)=>{m(i,a,()=>{f({action:h.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(h.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(J(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)})},T="driftAPI",j=()=>{const{ipcRenderer:t,contextBridge:e}=require("electron"),o={send:(r,...l)=>{q(r),t.send(r,...l)},invoke:async(r,...l)=>(G(r),await t.invoke(r,...l)),on:(r,l)=>{U(r),t.on(r,l)}};e.exposeInMainWorld(T,o)},Y=async()=>{if(!(T in window))throw new Error("Drift API not found. Make sure to call configurePreload in your preload script.");return await window[T].invoke(D)};class Q{constructor(){_(this,"_label","");_(this,"props",null);_(this,"api");if(!(T in window))throw new Error("Drift API not found. Make sure to call configurePreload in your preload script.");this.api=window[T]}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===h.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=Q;exports.exposeAPI=j;exports.getWindowLabel=Y;exports.listenOnMain=X;
package/dist/electron.js CHANGED
@@ -1,8 +1,7 @@
1
1
  var R = Object.defineProperty;
2
2
  var B = (t, e, o) => e in t ? R(t, e, { enumerable: !0, configurable: !0, writable: !0, value: o }) : t[e] = o;
3
3
  var m = (t, e, o) => B(t, typeof e != "symbol" ? e + "" : e, o);
4
- import { M as _ } from "./window-BIbHrbtA.js";
5
- import { r as H } from "./state-BOplmOQD.js";
4
+ import { M as _, r as H } from "./state-C1PObbun.js";
6
5
  import { o as Z } from "./debounce-DOZKRZa9.js";
7
6
  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
7
  E,
@@ -68,7 +67,7 @@ const E = "drift://action", S = "drift://create", w = "drift://focus", z = "drif
68
67
  alwaysOnTop: t.isAlwaysOnTop(),
69
68
  decorations: !1
70
69
  };
71
- }, te = ({ mainWindow: t, createWindow: e }) => {
70
+ }, ee = ({ mainWindow: t, createWindow: e }) => {
72
71
  const o = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Map();
73
72
  o.set(_, t.id), r.set(t.id, _);
74
73
  const { ipcMain: l, BrowserWindow: u } = require("electron"), d = (s, i) => l.on(s, (n, a) => {
@@ -141,7 +140,7 @@ const E = "drift://action", S = "drift://create", w = "drift://focus", z = "drif
141
140
  const c = u.fromId(a);
142
141
  c != null && c.webContents.send(E, i);
143
142
  });
144
- }, h = "driftAPI", ie = () => {
143
+ }, h = "driftAPI", te = () => {
145
144
  const { ipcRenderer: t, contextBridge: e } = require("electron"), o = {
146
145
  send: (r, ...l) => {
147
146
  U(r), t.send(r, ...l);
@@ -152,14 +151,14 @@ const E = "drift://action", S = "drift://create", w = "drift://focus", z = "drif
152
151
  }
153
152
  };
154
153
  e.exposeInMainWorld(h, o);
155
- }, se = async () => {
154
+ }, ie = async () => {
156
155
  if (!(h in window))
157
156
  throw new Error(
158
157
  "Drift API not found. Make sure to call configurePreload in your preload script."
159
158
  );
160
159
  return await window[h].invoke(W);
161
160
  };
162
- class ne {
161
+ class se {
163
162
  constructor() {
164
163
  m(this, "_label", "");
165
164
  m(this, "props", null);
@@ -250,8 +249,8 @@ class ne {
250
249
  }
251
250
  }
252
251
  export {
253
- ne as ElectronRuntime,
254
- ie as exposeAPI,
255
- se as getWindowLabel,
256
- te as listenOnMain
252
+ se as ElectronRuntime,
253
+ te as exposeAPI,
254
+ ie as getWindowLabel,
255
+ ee as listenOnMain
257
256
  };
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const A=require("@reduxjs/toolkit"),o=require("./state-Cl8us-b9.cjs"),f=require("./window-DLsE0-fP.cjs"),h=require("./selectors-jksTA_U1.cjs"),C=new Error("request for lock canceled");var L=function(i,e,s,t){function n(a){return a instanceof s?a:new s(function(r){r(a)})}return new(s||(s=Promise))(function(a,r){function l(c){try{u(t.next(c))}catch(w){r(w)}}function d(c){try{u(t.throw(c))}catch(w){r(w)}}function u(c){c.done?a(c.value):n(c.value).then(l,d)}u((t=t.apply(i,e||[])).next())})};class N{constructor(e,s=C){this._value=e,this._cancelError=s,this._queue=[],this._weightedWaiters=[]}acquire(e=1,s=0){if(e<=0)throw new Error(`invalid weight ${e}: must be positive`);return new Promise((t,n)=>{const a={resolve:t,reject:n,weight:e,priority:s},r=T(this._queue,l=>s<=l.priority);r===-1&&e<=this._value?this._dispatchItem(a):this._queue.splice(r+1,0,a)})}runExclusive(e){return L(this,arguments,void 0,function*(s,t=1,n=0){const[a,r]=yield this.acquire(t,n);try{return yield s(a)}finally{r()}})}waitForUnlock(e=1,s=0){if(e<=0)throw new Error(`invalid weight ${e}: must be positive`);return this._couldLockImmediately(e,s)?Promise.resolve():new Promise(t=>{this._weightedWaiters[e-1]||(this._weightedWaiters[e-1]=[]),P(this._weightedWaiters[e-1],{resolve:t,priority:s})})}isLocked(){return this._value<=0}getValue(){return this._value}setValue(e){this._value=e,this._dispatchQueue()}release(e=1){if(e<=0)throw new Error(`invalid weight ${e}: must be positive`);this._value+=e,this._dispatchQueue()}cancel(){this._queue.forEach(e=>e.reject(this._cancelError)),this._queue=[]}_dispatchQueue(){for(this._drainUnlockWaiters();this._queue.length>0&&this._queue[0].weight<=this._value;)this._dispatchItem(this._queue.shift()),this._drainUnlockWaiters()}_dispatchItem(e){const s=this._value;this._value-=e.weight,e.resolve([s,this._newReleaser(e.weight)])}_newReleaser(e){let s=!1;return()=>{s||(s=!0,this.release(e))}}_drainUnlockWaiters(){if(this._queue.length===0)for(let e=this._value;e>0;e--){const s=this._weightedWaiters[e-1];s&&(s.forEach(t=>t.resolve()),this._weightedWaiters[e-1]=[])}else{const e=this._queue[0].priority;for(let s=this._value;s>0;s--){const t=this._weightedWaiters[s-1];if(!t)continue;const n=t.findIndex(a=>a.priority<=e);(n===-1?t:t.splice(0,n)).forEach(a=>a.resolve())}}}_couldLockImmediately(e,s){return(this._queue.length===0||this._queue[0].priority<s)&&e<=this._value}}function P(i,e){const s=T(i,t=>e.priority<=t.priority);i.splice(s+1,0,e)}function T(i,e){for(let s=i.length-1;s>=0;s--)if(e(i[s]))return s;return-1}var q=function(i,e,s,t){function n(a){return a instanceof s?a:new s(function(r){r(a)})}return new(s||(s=Promise))(function(a,r){function l(c){try{u(t.next(c))}catch(w){r(w)}}function d(c){try{u(t.throw(c))}catch(w){r(w)}}function u(c){c.done?a(c.value):n(c.value).then(l,d)}u((t=t.apply(i,e||[])).next())})};class D{constructor(e){this._semaphore=new N(1,e)}acquire(){return q(this,arguments,void 0,function*(e=0){const[,s]=yield this._semaphore.acquire(1,e);return s})}runExclusive(e,s=0){return this._semaphore.runExclusive(()=>e(),1,s)}isLocked(){return this._semaphore.isLocked()}waitForUnlock(e=0){return this._semaphore.waitForUnlock(1,e)}release(){this._semaphore.isLocked()&&this._semaphore.release()}cancel(){return this._semaphore.cancel()}}const R=i=>[...new Set(i)],F=(i,e,s=!0)=>{const t=new Map;return i.forEach(n=>{const a=e(n);if(t.has(a)){if(s)return;t.delete(a)}t.set(a,n)}),Array.from(t.values())},V=Object.freeze(Object.defineProperty({__proto__:null,by:F,unique:R},Symbol.toStringTag,{value:"Module"})),I="DA@",M="://",j=(i,e)=>I.concat(e,M,i),Z=i=>{const[e,s]=i.split(M);if(s==null)return[i,""];const[,t]=e.split(I);return[s,t]},z=(i,e)=>({...i,type:j(i.type,e)}),U=i=>{const[e,s]=Z(i.type);return{emitted:s!=null&&s.length>0,emitter:s,action:{...i,type:e}}},K=i=>{const{centerCount:e,processCount:s,focusCount:t,stage:n,key:a,prerenderLabel:r,reserved:l,minimized:d,...u}=i;return u},Q=async(i,e,s,t)=>{const n=(await s.listLabels()).filter(c=>c!==f.MAIN_WINDOW),a=Object.keys(i.windows).filter(c=>c!==f.MAIN_WINDOW);o.group(t,"syncInitial"),o.log(t,"existing windows in runtime",n.sort()),o.log(t,"non-main windows in state",a.sort()),o.groupEnd(t);const r=V.unique([...n,...a]);for(const c of r)!n.includes(c)&&s.isMain()?(o.log(t,"state window not in runtime, creating",c),await v(s,c,i.windows[c],t)):a.includes(c)||(o.log(t,"runtime window not in state, closing",c),await y(s,c,t));const l=s.label(),d=i.windows[l];if(d==null)return;const u={...f.INITIAL_WINDOW_STATE};await k(u,d,s,t),e(o.runtimeSetWindowProps({label:s.label(),...await s.getProps()}))},X=async(i,e,s,t)=>{o.log(t,"sync",i,e),s.isMain()&&await $(i,e,s,t);const n=i.windows[s.label()],a=e.windows[s.label()];n==null||a==null||await k(n,a,s,t)},k=async(i,e,s,t)=>{const n=[];e.title!=null&&e.title!==i.title&&n.push(["title",{prev:i.title,next:e.title},async()=>s.setTitle(e.title)]);const a=e.visible!=null&&e.visible!==i.visible,r=e.visible===!1,l=()=>n.push(["visible",{prev:i.visible,next:e.visible},async()=>{if(await s.setVisible(e.visible),e.visible===!1)return;let d=e.position;d??(d=(await s.getProps()).position),await s.setPosition(f.J.translate(d,{x:1,y:1})),await s.setPosition(d)}]);if(a&&r&&l(),e.skipTaskbar!=null&&e.skipTaskbar!==i.skipTaskbar&&n.push(["skipTaskbar",{prev:i.skipTaskbar,next:e.skipTaskbar},async()=>await s.setSkipTaskbar(e.skipTaskbar)]),e.maximized!=null&&e.maximized!==i.maximized&&n.push(["maximized",{prev:i.maximized,next:e.maximized},async()=>await s.setMaximized(e.maximized)]),e.fullscreen!=null&&e.fullscreen!==i.fullscreen&&n.push(["fullscreen",{prev:i.fullscreen,next:e.fullscreen},async()=>await s.setFullscreen(e.fullscreen)]),e.centerCount!==i.centerCount&&n.push(["center",{prev:i.centerCount,next:e.centerCount},async()=>s.center()]),e.minimized!=null&&e.minimized!==i.minimized&&n.push(["minimized",{prev:i.minimized,next:e.minimized},async()=>await s.setMinimized(e.minimized)]),e.resizable!=null&&e.resizable!==i.resizable&&n.push(["resizable",{prev:i.resizable,next:e.resizable},async()=>await s.setResizable(e.resizable)]),e.minSize!=null&&!f._.equals(e.minSize,i.minSize)&&n.push(["minSize",{prev:i.minSize,next:e.minSize},async()=>await s.setMinSize(e.minSize)]),e.maxSize!=null&&!f._.equals(e.maxSize,i.maxSize)&&n.push(["maxSize",{prev:i.maxSize,next:e.maxSize},async()=>await s.setMaxSize(e.maxSize)]),e.size!=null&&!f._.equals(e.size,i.size)&&n.push(["size",{prev:i.size,next:e.size},async()=>await s.setSize(e.size)]),e.position!=null&&!f._.equals(e.position,i.position)&&n.push(["position",{prev:i.position,next:e.position},async()=>await s.setPosition(e.position)]),e.focusCount!==i.focusCount&&n.push(["setVisible",{prev:i.visible,next:e.visible},async()=>await s.setVisible(!0)],["focus",{prev:i.focusCount,next:e.focusCount},async()=>await s.focus()]),e.decorations!=null&&e.decorations!==i.decorations&&n.push(["decorations",{prev:i.decorations,next:e.decorations},async()=>await s.setDecorations(e.decorations)]),e.alwaysOnTop!=null&&e.alwaysOnTop!==i.alwaysOnTop&&n.push(["alwaysOnTop",{prev:i.alwaysOnTop,next:e.alwaysOnTop},async()=>await s.setAlwaysOnTop(e.alwaysOnTop)]),a&&!r&&l(),n.length!==0){o.group(t,`syncCurrent, label: ${s.label()}, key: ${e.key}`);for(const[d,{prev:u,next:c}]of n)o.log(t,d,u,"->",c);o.groupEnd(t);for(const[,,d]of n)await d()}},$=async(i,e,s,t)=>{const n=Object.keys(i.windows).filter(l=>!(l in e.windows)),a=Object.keys(e.windows).filter(l=>!(l in i.windows)),r=s.isMain();if(r&&n.length>0)for(const l of n)o.log(t,"syncMain","closing",l),l===f.MAIN_WINDOW&&await Promise.all(Object.keys(e.windows).filter(d=>d!==f.MAIN_WINDOW).map(async d=>await y(s,d,t))),await y(s,l,t);if(r&&a.length>0)for(const l of a)await v(s,l,e.windows[l],t)},v=async(i,e,s,t)=>(o.log(t,"createWindow",s),await i.create(e,K(s))),y=async(i,e,s)=>(o.log(s,"closeWindow",e),await i.close(e)),m="[drift] - unexpected undefined action",g="[drift] - unexpected undefined action type",_=i=>{if(i.emitted??(i.emitted=!1),i.action==null)throw console.warn(m,i),new Error(m);if(i.action.type==null||i.action.type.length===0)throw console.warn(g,i),new Error(g)},J=new D,Y=[o.runtimeSetWindowProps.type,o.reloadWindow.type],B=(i,e=!1)=>s=>t=>n=>{let{action:a,emitted:r,emitter:l}=U(n);const d=i.label();_({action:n,emitted:r,emitter:l});const u=o.isDriftAction(a.type);if(u&&o.log(e,"[drift] - middleware",{action:a,emitted:r,emitter:l,host:d}),l===i.label())return;const c=u&&!Y.includes(a.type);let w=null;u&&(w=s.getState().drift,a=o.assignLabel(a,w));const p=t(a),S=c?s.getState().drift:null,O=o.shouldEmit(r,a.type);return J.runExclusive(async()=>{try{w!==null&&S!==null&&await X(w,S,i,e),O&&await i.emit({action:a})}catch(b){o.log(e,"[drift] - ERROR",{error:b.message,action:a,emitted:r,emitter:l,host:d}),s.dispatch(o.setWindowError({key:d,message:b.message}))}}),p},G=(i,e,s=!1)=>t=>{const n=i!=null?typeof i=="function"?i(t):i:t();return[B(e,s),...n]},H=async({runtime:i,preloadedState:e,middleware:s,debug:t=!1,enablePrerender:n=!0,defaultWindowProps:a,...r})=>{await i.configure();let l;l=A.configureStore({...r,preloadedState:await x(t,i,()=>l,a,e),middleware:G(s,i,t)}),await Q(l.getState().drift,l.dispatch,i,t);const d=i.label();return l.dispatch(o.internalSetInitial({enablePrerender:n,defaultWindowProps:a,debug:t,label:d})),l.dispatch(o.setWindowStage({stage:"created"})),i.onCloseRequested(()=>l==null?void 0:l.dispatch(o.closeWindow({}))),l},x=async(i,e,s,t,n)=>e.isMain()?(await e.subscribe(({action:r,emitter:l,sendState:d})=>{const u=s();if(u==null)return;if(r!=null){_({action:r,emitter:l}),u.dispatch(z(r,l));return}const c=u.getState();d===!0&&e.emit({state:c},l)}),typeof n=="function"?E(t,i,await n()):E(t,i,n)):await new Promise((r,l)=>{(async()=>{try{await e.subscribe(({action:u,emitter:c,state:w})=>{const p=s();if(p==null)return w!=null?r(w):void 0;u!=null&&(_({action:u,emitter:c}),p.dispatch(z(u,c)))}),await e.emit({sendState:!0},f.MAIN_WINDOW)}catch(u){l(u)}})()}),W=H,E=(i,e,s)=>{if(s==null)return s;const t=s[o.SLICE_NAME];return t.config.debug=e??t.config.debug,t.windows=Object.fromEntries(Object.entries(t.windows).filter(([,n])=>n.reserved).map(([n,a])=>((i==null?void 0:i.visible)!=null&&(a.visible=i.visible),a.focusCount=0,a.centerCount=0,a.processCount=0,[n,a]))),s},ee=Object.freeze(Object.defineProperty({__proto__:null,MAIN_WINDOW:f.MAIN_WINDOW,SLICE_NAME:o.SLICE_NAME,ZERO_SLICE_STATE:o.ZERO_SLICE_STATE,closeWindow:o.closeWindow,completeProcess:o.completeProcess,configureStore:W,createWindow:o.createWindow,focusWindow:o.focusWindow,reducer:o.reducer,registerProcess:o.registerProcess,reloadWindow:o.reloadWindow,selectSliceState:h.selectSliceState,selectWindow:h.selectWindow,selectWindowAttribute:h.selectWindowAttribute,selectWindowKey:h.selectWindowKey,selectWindowLabel:h.selectWindowLabel,selectWindows:h.selectWindows,setWindowAlwaysOnTop:o.setWindowAlwaysOnTop,setWindowDecorations:o.setWindowDecorations,setWindowFullscreen:o.setWindowFullscreen,setWindowMaxSize:o.setWindowMaxSize,setWindowMaximized:o.setWindowMaximized,setWindowMinSize:o.setWindowMinSize,setWindowMinimized:o.setWindowMinimized,setWindowPosition:o.setWindowPosition,setWindowProps:o.setWindowProps,setWindowResizable:o.setWindowResizable,setWindowSize:o.setWindowSize,setWindowSkipTaskbar:o.setWindowSkipTaskbar,setWindowStage:o.setWindowStage,setWindowTitle:o.setWindowTitle,setWindowVisible:o.setWindowVisible,windowPropsZ:f.windowPropsZ},Symbol.toStringTag,{value:"Module"}));exports.SLICE_NAME=o.SLICE_NAME;exports.ZERO_SLICE_STATE=o.ZERO_SLICE_STATE;exports.closeWindow=o.closeWindow;exports.completeProcess=o.completeProcess;exports.createWindow=o.createWindow;exports.focusWindow=o.focusWindow;exports.reducer=o.reducer;exports.registerProcess=o.registerProcess;exports.reloadWindow=o.reloadWindow;exports.setWindowAlwaysOnTop=o.setWindowAlwaysOnTop;exports.setWindowDecorations=o.setWindowDecorations;exports.setWindowFullscreen=o.setWindowFullscreen;exports.setWindowMaxSize=o.setWindowMaxSize;exports.setWindowMaximized=o.setWindowMaximized;exports.setWindowMinSize=o.setWindowMinSize;exports.setWindowMinimized=o.setWindowMinimized;exports.setWindowPosition=o.setWindowPosition;exports.setWindowProps=o.setWindowProps;exports.setWindowResizable=o.setWindowResizable;exports.setWindowSize=o.setWindowSize;exports.setWindowSkipTaskbar=o.setWindowSkipTaskbar;exports.setWindowStage=o.setWindowStage;exports.setWindowTitle=o.setWindowTitle;exports.setWindowVisible=o.setWindowVisible;exports.MAIN_WINDOW=f.MAIN_WINDOW;exports.windowPropsZ=f.windowPropsZ;exports.selectSliceState=h.selectSliceState;exports.selectWindow=h.selectWindow;exports.selectWindowAttribute=h.selectWindowAttribute;exports.selectWindowKey=h.selectWindowKey;exports.selectWindowLabel=h.selectWindowLabel;exports.selectWindows=h.selectWindows;exports.Drift=ee;exports.configureStore=W;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const O=require("@reduxjs/toolkit"),t=require("./state-BGByXBtX.cjs"),f=require("./selectors-DrXQNVVN.cjs"),N=new Error("request for lock canceled");var C=function(i,e,s,o){function n(a){return a instanceof s?a:new s(function(c){c(a)})}return new(s||(s=Promise))(function(a,c){function l(r){try{u(o.next(r))}catch(w){c(w)}}function d(r){try{u(o.throw(r))}catch(w){c(w)}}function u(r){r.done?a(r.value):n(r.value).then(l,d)}u((o=o.apply(i,e||[])).next())})};class P{constructor(e,s=N){this._value=e,this._cancelError=s,this._queue=[],this._weightedWaiters=[]}acquire(e=1,s=0){if(e<=0)throw new Error(`invalid weight ${e}: must be positive`);return new Promise((o,n)=>{const a={resolve:o,reject:n,weight:e,priority:s},c=T(this._queue,l=>s<=l.priority);c===-1&&e<=this._value?this._dispatchItem(a):this._queue.splice(c+1,0,a)})}runExclusive(e){return C(this,arguments,void 0,function*(s,o=1,n=0){const[a,c]=yield this.acquire(o,n);try{return yield s(a)}finally{c()}})}waitForUnlock(e=1,s=0){if(e<=0)throw new Error(`invalid weight ${e}: must be positive`);return this._couldLockImmediately(e,s)?Promise.resolve():new Promise(o=>{this._weightedWaiters[e-1]||(this._weightedWaiters[e-1]=[]),L(this._weightedWaiters[e-1],{resolve:o,priority:s})})}isLocked(){return this._value<=0}getValue(){return this._value}setValue(e){this._value=e,this._dispatchQueue()}release(e=1){if(e<=0)throw new Error(`invalid weight ${e}: must be positive`);this._value+=e,this._dispatchQueue()}cancel(){this._queue.forEach(e=>e.reject(this._cancelError)),this._queue=[]}_dispatchQueue(){for(this._drainUnlockWaiters();this._queue.length>0&&this._queue[0].weight<=this._value;)this._dispatchItem(this._queue.shift()),this._drainUnlockWaiters()}_dispatchItem(e){const s=this._value;this._value-=e.weight,e.resolve([s,this._newReleaser(e.weight)])}_newReleaser(e){let s=!1;return()=>{s||(s=!0,this.release(e))}}_drainUnlockWaiters(){if(this._queue.length===0)for(let e=this._value;e>0;e--){const s=this._weightedWaiters[e-1];s&&(s.forEach(o=>o.resolve()),this._weightedWaiters[e-1]=[])}else{const e=this._queue[0].priority;for(let s=this._value;s>0;s--){const o=this._weightedWaiters[s-1];if(!o)continue;const n=o.findIndex(a=>a.priority<=e);(n===-1?o:o.splice(0,n)).forEach(a=>a.resolve())}}}_couldLockImmediately(e,s){return(this._queue.length===0||this._queue[0].priority<s)&&e<=this._value}}function L(i,e){const s=T(i,o=>e.priority<=o.priority);i.splice(s+1,0,e)}function T(i,e){for(let s=i.length-1;s>=0;s--)if(e(i[s]))return s;return-1}var q=function(i,e,s,o){function n(a){return a instanceof s?a:new s(function(c){c(a)})}return new(s||(s=Promise))(function(a,c){function l(r){try{u(o.next(r))}catch(w){c(w)}}function d(r){try{u(o.throw(r))}catch(w){c(w)}}function u(r){r.done?a(r.value):n(r.value).then(l,d)}u((o=o.apply(i,e||[])).next())})};class D{constructor(e){this._semaphore=new P(1,e)}acquire(){return q(this,arguments,void 0,function*(e=0){const[,s]=yield this._semaphore.acquire(1,e);return s})}runExclusive(e,s=0){return this._semaphore.runExclusive(()=>e(),1,s)}isLocked(){return this._semaphore.isLocked()}waitForUnlock(e=0){return this._semaphore.waitForUnlock(1,e)}release(){this._semaphore.isLocked()&&this._semaphore.release()}cancel(){return this._semaphore.cancel()}}const R=i=>[...new Set(i)],F=(i,e,s=!0)=>{const o=new Map;return i.forEach(n=>{const a=e(n);if(o.has(a)){if(s)return;o.delete(a)}o.set(a,n)}),Array.from(o.values())},V=Object.freeze(Object.defineProperty({__proto__:null,by:F,unique:R},Symbol.toStringTag,{value:"Module"})),M="DA@",E="://",j=(i,e)=>M.concat(e,E,i),Z=i=>{const[e,s]=i.split(E);if(s==null)return[i,""];const[,o]=e.split(M);return[s,o]},b=(i,e)=>({...i,type:j(i.type,e)}),U=i=>{const[e,s]=Z(i.type);return{emitted:s!=null&&s.length>0,emitter:s,action:{...i,type:e}}},K=i=>{const{centerCount:e,processCount:s,focusCount:o,stage:n,key:a,prerenderLabel:c,reserved:l,minimized:d,...u}=i;return u},Q=async(i,e,s,o)=>{const n=(await s.listLabels()).filter(r=>r!==t.MAIN_WINDOW),a=Object.keys(i.windows).filter(r=>r!==t.MAIN_WINDOW);t.group(o,"syncInitial"),t.log(o,"existing windows in runtime",n.sort()),t.log(o,"non-main windows in state",a.sort()),t.groupEnd(o);const c=V.unique([...n,...a]);for(const r of c)!n.includes(r)&&s.isMain()?(t.log(o,"state window not in runtime, creating",r),await k(s,r,i.windows[r],o)):a.includes(r)||(t.log(o,"runtime window not in state, closing",r),await y(s,r,o));const l=s.label(),d=i.windows[l];if(d==null)return;const u={...t.INITIAL_WINDOW_STATE};await I(u,d,s,o),e(t.runtimeSetWindowProps({label:s.label(),...await s.getProps()}))},X=async(i,e,s,o)=>{t.log(o,"sync",i,e),s.isMain()&&await $(i,e,s,o);const n=i.windows[s.label()],a=e.windows[s.label()];n==null||a==null||await I(n,a,s,o)},I=async(i,e,s,o)=>{const n=[];e.title!=null&&e.title!==i.title&&n.push(["title",{prev:i.title,next:e.title},async()=>s.setTitle(e.title)]);const a=e.visible!=null&&e.visible!==i.visible,c=e.visible===!1,l=()=>n.push(["visible",{prev:i.visible,next:e.visible},async()=>{if(await s.setVisible(e.visible),e.visible===!1)return;let d=e.position;d??(d=(await s.getProps()).position),d!=null&&(await s.setPosition(t.K.translate(d,{x:1,y:1})),await s.setPosition(d))}]);if(a&&c&&l(),e.skipTaskbar!=null&&e.skipTaskbar!==i.skipTaskbar&&n.push(["skipTaskbar",{prev:i.skipTaskbar,next:e.skipTaskbar},async()=>await s.setSkipTaskbar(e.skipTaskbar)]),e.maximized!=null&&e.maximized!==i.maximized&&n.push(["maximized",{prev:i.maximized,next:e.maximized},async()=>await s.setMaximized(e.maximized)]),e.fullscreen!=null&&e.fullscreen!==i.fullscreen&&n.push(["fullscreen",{prev:i.fullscreen,next:e.fullscreen},async()=>await s.setFullscreen(e.fullscreen)]),e.centerCount!==i.centerCount&&n.push(["center",{prev:i.centerCount,next:e.centerCount},async()=>s.center()]),e.minimized!=null&&e.minimized!==i.minimized&&n.push(["minimized",{prev:i.minimized,next:e.minimized},async()=>await s.setMinimized(e.minimized)]),e.resizable!=null&&e.resizable!==i.resizable&&n.push(["resizable",{prev:i.resizable,next:e.resizable},async()=>await s.setResizable(e.resizable)]),e.minSize!=null&&!t.A.equals(e.minSize,i.minSize)&&n.push(["minSize",{prev:i.minSize,next:e.minSize},async()=>await s.setMinSize(e.minSize)]),e.maxSize!=null&&!t.A.equals(e.maxSize,i.maxSize)&&n.push(["maxSize",{prev:i.maxSize,next:e.maxSize},async()=>await s.setMaxSize(e.maxSize)]),e.size!=null&&!t.A.equals(e.size,i.size)&&n.push(["size",{prev:i.size,next:e.size},async()=>await s.setSize(e.size)]),e.position!=null&&!t.A.equals(e.position,i.position)&&n.push(["position",{prev:i.position,next:e.position},async()=>await s.setPosition(e.position)]),e.focusCount!==i.focusCount&&n.push(["setVisible",{prev:i.visible,next:e.visible},async()=>await s.setVisible(!0)],["focus",{prev:i.focusCount,next:e.focusCount},async()=>await s.focus()]),e.decorations!=null&&e.decorations!==i.decorations&&n.push(["decorations",{prev:i.decorations,next:e.decorations},async()=>await s.setDecorations(e.decorations)]),e.alwaysOnTop!=null&&e.alwaysOnTop!==i.alwaysOnTop&&n.push(["alwaysOnTop",{prev:i.alwaysOnTop,next:e.alwaysOnTop},async()=>await s.setAlwaysOnTop(e.alwaysOnTop)]),a&&!c&&l(),n.length!==0){t.group(o,`syncCurrent, label: ${s.label()}, key: ${e.key}`);for(const[d,{prev:u,next:r}]of n)t.log(o,d,u,"->",r);t.groupEnd(o);for(const[,,d]of n)await d()}},$=async(i,e,s,o)=>{const n=Object.keys(i.windows).filter(l=>!(l in e.windows)),a=Object.keys(e.windows).filter(l=>!(l in i.windows)),c=s.isMain();if(c&&n.length>0)for(const l of n)t.log(o,"syncMain","closing",l),l===t.MAIN_WINDOW&&await Promise.all(Object.keys(e.windows).filter(d=>d!==t.MAIN_WINDOW).map(async d=>await y(s,d,o))),await y(s,l,o);if(c&&a.length>0)for(const l of a)await k(s,l,e.windows[l],o)},k=async(i,e,s,o)=>(t.log(o,"createWindow",s),await i.create(e,K(s))),y=async(i,e,s)=>(t.log(s,"closeWindow",e),await i.close(e)),z="[drift] - unexpected undefined action",m="[drift] - unexpected undefined action type",p=i=>{if(i.emitted??(i.emitted=!1),i.action==null)throw console.warn(z,i),new Error(z);if(i.action.type==null||i.action.type.length===0)throw console.warn(m,i),new Error(m)},Y=new D,B=[t.runtimeSetWindowProps.type,t.reloadWindow.type],G=(i,e=!1)=>s=>o=>n=>{let{action:a,emitted:c,emitter:l}=U(n);const d=i.label();p({action:n,emitted:c,emitter:l});const u=t.isDriftAction(a.type);if(u&&t.log(e,"[drift] - middleware",{action:a,emitted:c,emitter:l,host:d}),l===i.label())return;const r=u&&!B.includes(a.type);let w=null;u&&(w=s.getState().drift,a=t.assignLabel(a,w));const h=o(a),_=r?s.getState().drift:null,v=t.shouldEmit(c,a.type);return Y.runExclusive(async()=>{try{w!==null&&_!==null&&await X(w,_,i,e),v&&await i.emit({action:a})}catch(S){t.log(e,"[drift] - ERROR",{error:S.message,action:a,emitted:c,emitter:l,host:d}),s.dispatch(t.setWindowError({key:d,message:S.message}))}}),h},H=(i,e,s=!1)=>o=>{const n=i!=null?typeof i=="function"?i(o):i:o();return[G(e,s),...n]},J=async({runtime:i,preloadedState:e,middleware:s,debug:o=!1,enablePrerender:n=!0,defaultWindowProps:a,...c})=>{await i.configure();let l;l=O.configureStore({...c,preloadedState:await x(o,i,()=>l,a,e),middleware:H(s,i,o)}),await Q(l.getState().drift,l.dispatch,i,o);const d=i.label();return l.dispatch(t.internalSetInitial({enablePrerender:n,defaultWindowProps:a,debug:o,label:d})),l.dispatch(t.setWindowStage({stage:"created"})),i.onCloseRequested(()=>l==null?void 0:l.dispatch(t.closeWindow({}))),l},x=async(i,e,s,o,n)=>e.isMain()?(await e.subscribe(({action:c,emitter:l,sendState:d})=>{const u=s();if(u==null)return;if(c!=null){p({action:c,emitter:l}),u.dispatch(b(c,l));return}const r=u.getState();d===!0&&e.emit({state:r},l)}),typeof n=="function"?g(o,i,await n()):g(o,i,n)):await new Promise((c,l)=>{(async()=>{try{await e.subscribe(({action:u,emitter:r,state:w})=>{const h=s();if(h==null)return w!=null?c(w):void 0;u!=null&&(p({action:u,emitter:r}),h.dispatch(b(u,r)))}),await e.emit({sendState:!0},t.MAIN_WINDOW)}catch(u){l(u)}})()}),A=J,g=(i,e,s)=>{if(s==null)return s;const o=s[t.SLICE_NAME];return o.config.debug=e??o.config.debug,o.windows=Object.fromEntries(Object.entries(o.windows).filter(([,n])=>n.reserved).map(([n,a])=>((i==null?void 0:i.visible)!=null&&(a.visible=i.visible),a.focusCount=0,a.centerCount=0,a.processCount=0,[n,a]))),s};class W{async emit(){}async subscribe(){}isMain(){return!0}label(){return t.MAIN_WINDOW}onCloseRequested(){}async listLabels(){return[]}async getProps(){return{}}async create(){}async close(){}async focus(){}async setMinimized(){}async setMaximized(){}async setVisible(){}async setFullscreen(){}async center(){}async setPosition(){}async setSize(){}async setMinSize(){}async setMaxSize(){}async setResizable(){}async setSkipTaskbar(){}async setAlwaysOnTop(){}async setDecorations(){}async setTitle(){}async configure(){}}const ee=Object.freeze(Object.defineProperty({__proto__:null,MAIN_WINDOW:t.MAIN_WINDOW,NoopRuntime:W,SLICE_NAME:t.SLICE_NAME,ZERO_SLICE_STATE:t.ZERO_SLICE_STATE,closeWindow:t.closeWindow,completeProcess:t.completeProcess,configureStore:A,createWindow:t.createWindow,focusWindow:t.focusWindow,reducer:t.reducer,registerProcess:t.registerProcess,reloadWindow:t.reloadWindow,selectSliceState:f.selectSliceState,selectWindow:f.selectWindow,selectWindowAttribute:f.selectWindowAttribute,selectWindowKey:f.selectWindowKey,selectWindowLabel:f.selectWindowLabel,selectWindows:f.selectWindows,setWindowAlwaysOnTop:t.setWindowAlwaysOnTop,setWindowDecorations:t.setWindowDecorations,setWindowFullscreen:t.setWindowFullscreen,setWindowMaxSize:t.setWindowMaxSize,setWindowMaximized:t.setWindowMaximized,setWindowMinSize:t.setWindowMinSize,setWindowMinimized:t.setWindowMinimized,setWindowPosition:t.setWindowPosition,setWindowProps:t.setWindowProps,setWindowResizable:t.setWindowResizable,setWindowSize:t.setWindowSize,setWindowSkipTaskbar:t.setWindowSkipTaskbar,setWindowStage:t.setWindowStage,setWindowTitle:t.setWindowTitle,setWindowVisible:t.setWindowVisible,windowPropsZ:t.windowPropsZ},Symbol.toStringTag,{value:"Module"}));exports.MAIN_WINDOW=t.MAIN_WINDOW;exports.SLICE_NAME=t.SLICE_NAME;exports.ZERO_SLICE_STATE=t.ZERO_SLICE_STATE;exports.closeWindow=t.closeWindow;exports.completeProcess=t.completeProcess;exports.createWindow=t.createWindow;exports.focusWindow=t.focusWindow;exports.reducer=t.reducer;exports.registerProcess=t.registerProcess;exports.reloadWindow=t.reloadWindow;exports.setWindowAlwaysOnTop=t.setWindowAlwaysOnTop;exports.setWindowDecorations=t.setWindowDecorations;exports.setWindowFullscreen=t.setWindowFullscreen;exports.setWindowMaxSize=t.setWindowMaxSize;exports.setWindowMaximized=t.setWindowMaximized;exports.setWindowMinSize=t.setWindowMinSize;exports.setWindowMinimized=t.setWindowMinimized;exports.setWindowPosition=t.setWindowPosition;exports.setWindowProps=t.setWindowProps;exports.setWindowResizable=t.setWindowResizable;exports.setWindowSize=t.setWindowSize;exports.setWindowSkipTaskbar=t.setWindowSkipTaskbar;exports.setWindowStage=t.setWindowStage;exports.setWindowTitle=t.setWindowTitle;exports.setWindowVisible=t.setWindowVisible;exports.windowPropsZ=t.windowPropsZ;exports.selectSliceState=f.selectSliceState;exports.selectWindow=f.selectWindow;exports.selectWindowAttribute=f.selectWindowAttribute;exports.selectWindowKey=f.selectWindowKey;exports.selectWindowLabel=f.selectWindowLabel;exports.selectWindows=f.selectWindows;exports.Drift=ee;exports.NoopRuntime=W;exports.configureStore=A;