@synnaxlabs/drift 0.43.0 → 0.44.1

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/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 _=(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;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("./state-BXNWz8wb.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,10 +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 _, r as H } from "./state-C1PObbun.js";
5
- import { o as Z } from "./debounce-DOZKRZa9.js";
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 = [
7
- E,
1
+ import { M as h, r as v } from "./state-C0QVe0pH.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,
8
8
  S,
9
9
  w,
10
10
  z,
@@ -18,45 +18,39 @@ const E = "drift://action", S = "drift://create", w = "drift://focus", z = "drif
18
18
  A,
19
19
  V,
20
20
  x,
21
- k,
22
- C,
23
- P,
24
- L,
25
- p
26
- ], U = (t) => {
27
- if (!F.includes(t))
21
+ W,
22
+ T
23
+ ], H = (t) => {
24
+ if (!B.includes(t))
28
25
  throw new Error(`Event ${t} is not on the list of allowed events`);
29
- }, q = [E], $ = (t) => {
30
- if (!q.includes(t))
26
+ }, Z = [u], F = (t) => {
27
+ if (!Z.includes(t))
31
28
  throw new Error(`Event ${t} is not on the list of allowed events`);
32
- }, G = [p, W], J = (t) => {
33
- if (!G.includes(t))
29
+ }, U = [T, k], q = (t) => {
30
+ if (!U.includes(t))
34
31
  throw new Error(`Command ${t} is not on the list of allowed commands`);
35
- }, K = (t) => {
36
- 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();
37
51
  return {
38
- x: (e = t.position) == null ? void 0 : e.x,
39
- y: (o = t.position) == null ? void 0 : o.y,
40
- width: (r = t.size) == null ? void 0 : r.width,
41
- height: (l = t.size) == null ? void 0 : l.height,
42
- center: t.center,
43
- minHeight: (u = t.minSize) == null ? void 0 : u.height,
44
- minWidth: (d = t.minSize) == null ? void 0 : d.width,
45
- maxHeight: (T = t.maxSize) == null ? void 0 : T.height,
46
- maxWidth: (f = t.maxSize) == null ? void 0 : f.width,
47
- resizable: t.resizable,
48
- fullscreen: t.fullscreen,
49
- skipTaskbar: t.skipTaskbar,
50
- title: t.title,
51
- show: t.visible,
52
- transparent: t.transparent,
53
- alwaysOnTop: t.alwaysOnTop
54
- };
55
- }, X = (t) => {
56
- const [e, o] = t.getSize(), [r, l] = t.getPosition();
57
- return {
58
- size: { width: e, height: o },
59
- position: { x: r, y: l },
52
+ size: { width: s, height: a },
53
+ position: { x: o, y: l },
60
54
  minimized: t.isMinimized(),
61
55
  maximized: t.isMaximized(),
62
56
  fullscreen: t.isFullScreen(),
@@ -67,181 +61,180 @@ const E = "drift://action", S = "drift://create", w = "drift://focus", z = "drif
67
61
  alwaysOnTop: t.isAlwaysOnTop(),
68
62
  decorations: !1
69
63
  };
70
- }, ee = ({ mainWindow: t, createWindow: e }) => {
71
- const o = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Map();
72
- o.set(_, t.id), r.set(t.id, _);
73
- const { ipcMain: l, BrowserWindow: u } = require("electron"), d = (s, i) => l.on(s, (n, a) => {
74
- const c = u.fromWebContents(n.sender);
75
- 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);
76
70
  });
77
- l.on(z, (s, i) => {
78
- const n = o.get(i);
71
+ l.on(p, (i, e) => {
72
+ const n = a.get(e);
79
73
  if (n == null) return;
80
- const a = u.fromId(n);
81
- a != null && (a.close(), o.delete(i), r.delete(n));
82
- }), l.handle(p, (s) => {
83
- const i = u.fromWebContents(s.sender);
84
- return i == null ? void 0 : { ...X(i), label: r.get(i.id) };
85
- }), l.handle(W, (s) => {
86
- const i = u.fromWebContents(s.sender);
87
- if (i != null)
88
- 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);
89
83
  });
90
- const T = (s, i, n) => {
91
- s.on(i, Z(n, 500));
92
- }, f = (s) => {
93
- var i;
94
- for (const n of r.keys())
95
- (i = u.fromId(n)) == null || i.webContents.send(E, s);
96
- }, D = (s, i) => {
97
- const n = (a, c) => {
98
- T(i, a, () => {
99
- f({
100
- 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) }),
101
94
  emitter: "WHITELIST"
102
95
  });
103
96
  });
104
97
  };
105
- n("resize", (a) => {
106
- const [c, v] = a.getSize();
107
- return { size: { width: c, height: v } };
98
+ n("resize", (r) => {
99
+ const [c, L] = r.getSize();
100
+ return { size: { width: c, height: L } };
108
101
  }), n("move", () => {
109
- const [a, c] = i.getPosition();
110
- return { position: { x: a, y: c } };
111
- }), 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 }));
112
105
  };
113
- 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 }) => {
114
- s.setPosition(Math.round(i), Math.round(n));
115
- }), d(g, (s, { width: i, height: n }) => {
116
- 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));
117
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(
118
117
  A,
119
- (s, { width: i, height: n }) => s.setMinimumSize(Math.round(i), Math.round(n))
118
+ (i, e) => i.setSkipTaskbar(e)
120
119
  ), d(
121
120
  V,
122
- (s, { width: i, height: n }) => s.setMaximumSize(Math.round(i), Math.round(n))
123
- ), d(x, (s, i) => s.setResizable(i)), d(
124
- k,
125
- (s, i) => s.setSkipTaskbar(i)
126
- ), d(
127
- C,
128
- (s, i) => s.setAlwaysOnTop(i)
129
- ), d(P, (s, i) => s.setTitle(i)), l.on(
130
- S,
131
- (s, i, n) => {
132
- const a = e(K(n));
133
- 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);
134
127
  }
135
- ), l.on(E, (s, i, n) => {
136
- if (i == null) return;
137
- if (n == null) return f(i);
138
- const a = o.get(n);
139
- if (a == null) return;
140
- const c = u.fromId(a);
141
- 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);
142
135
  });
143
- }, h = "driftAPI", te = () => {
144
- const { ipcRenderer: t, contextBridge: e } = require("electron"), o = {
145
- send: (r, ...l) => {
146
- 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);
147
140
  },
148
- invoke: async (r, ...l) => (J(r), await t.invoke(r, ...l)),
149
- on: (r, l) => {
150
- $(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);
151
144
  }
152
145
  };
153
- e.exposeInMainWorld(h, o);
154
- }, ie = async () => {
155
- if (!(h in window))
146
+ s.exposeInMainWorld(f, a);
147
+ }, j = async () => {
148
+ if (!(f in window))
156
149
  throw new Error(
157
150
  "Drift API not found. Make sure to call configurePreload in your preload script."
158
151
  );
159
- return await window[h].invoke(W);
152
+ return await window[f].invoke(k);
160
153
  };
161
- class se {
154
+ class Q {
155
+ _label = "";
156
+ props = null;
157
+ api;
162
158
  constructor() {
163
- m(this, "_label", "");
164
- m(this, "props", null);
165
- m(this, "api");
166
- if (!(h in window))
159
+ if (!(f in window))
167
160
  throw new Error(
168
161
  "Drift API not found. Make sure to call configurePreload in your preload script."
169
162
  );
170
- this.api = window[h];
163
+ this.api = window[f];
171
164
  }
172
165
  async configure() {
173
- const { label: e, ...o } = await this.api.invoke(p);
174
- this._label = e, this.props = o;
166
+ const { label: s, ...a } = await this.api.invoke(T);
167
+ this._label = s, this.props = a;
175
168
  }
176
169
  label() {
177
170
  return this._label;
178
171
  }
179
172
  isMain() {
180
- return this._label === _;
173
+ return this._label === h;
181
174
  }
182
175
  release() {
183
176
  }
184
- async emit(e, o) {
185
- this.api.send(E, { ...e, emitter: this.label() }, o);
177
+ async emit(s, a) {
178
+ this.api.send(u, { ...s, emitter: this.label() }, a);
186
179
  }
187
- async subscribe(e) {
188
- this.api.on(E, (o, r) => e(r));
180
+ async subscribe(s) {
181
+ this.api.on(u, (a, o) => s(o));
189
182
  }
190
183
  onCloseRequested() {
191
184
  }
192
- async create(e, o) {
193
- 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)));
194
187
  }
195
- async close(e) {
196
- this.api.send(z, e);
188
+ async close(s) {
189
+ this.api.send(p, s);
197
190
  }
198
191
  async listLabels() {
199
192
  return [];
200
193
  }
201
194
  async focus() {
202
- this.api.send(w);
195
+ this.api.send(_);
203
196
  }
204
- async setMinimized(e) {
205
- this.api.send(b, e);
197
+ async setMinimized(s) {
198
+ this.api.send(S, s);
206
199
  }
207
- async setMaximized(e) {
208
- this.api.send(y, e);
200
+ async setMaximized(s) {
201
+ this.api.send(w, s);
209
202
  }
210
- async setVisible(e) {
211
- this.api.send(I, e);
203
+ async setVisible(s) {
204
+ this.api.send(z, s);
212
205
  }
213
- async setFullscreen(e) {
214
- this.api.send(N, e);
206
+ async setFullscreen(s) {
207
+ this.api.send(b, s);
215
208
  }
216
209
  async center() {
217
- this.api.send(M);
210
+ this.api.send(y);
218
211
  }
219
- async setPosition(e) {
220
- this.api.send(O, e);
212
+ async setPosition(s) {
213
+ this.api.send(I, s);
221
214
  }
222
- async setSize(e) {
223
- this.api.send(g, e);
215
+ async setSize(s) {
216
+ this.api.send(N, s);
224
217
  }
225
- async setMinSize(e) {
226
- this.api.send(A, e);
218
+ async setMinSize(s) {
219
+ this.api.send(M, s);
227
220
  }
228
- async setMaxSize(e) {
229
- this.api.send(V, e);
221
+ async setMaxSize(s) {
222
+ this.api.send(O, s);
230
223
  }
231
- async setResizable(e) {
232
- this.api.send(x, e);
224
+ async setResizable(s) {
225
+ this.api.send(g, s);
233
226
  }
234
- async setSkipTaskbar(e) {
235
- this.api.send(k, e);
227
+ async setSkipTaskbar(s) {
228
+ this.api.send(A, s);
236
229
  }
237
- async setAlwaysOnTop(e) {
238
- this.api.send(C, e);
230
+ async setAlwaysOnTop(s) {
231
+ this.api.send(V, s);
239
232
  }
240
- async setTitle(e) {
241
- this.api.send(P, e);
233
+ async setTitle(s) {
234
+ this.api.send(x, s);
242
235
  }
243
- async setDecorations(e) {
244
- this.api.send(L, e);
236
+ async setDecorations(s) {
237
+ this.api.send(W, s);
245
238
  }
246
239
  async getProps() {
247
240
  if (this.props != null) return this.props;
@@ -249,8 +242,8 @@ class se {
249
242
  }
250
243
  }
251
244
  export {
252
- se as ElectronRuntime,
253
- te as exposeAPI,
254
- ie as getWindowLabel,
255
- ee as listenOnMain
245
+ Q as ElectronRuntime,
246
+ Y as exposeAPI,
247
+ j as getWindowLabel,
248
+ X as listenOnMain
256
249
  };
package/dist/index.cjs CHANGED
@@ -1 +1 @@
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;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const A=require("@reduxjs/toolkit"),t=require("./state-BXNWz8wb.cjs"),f=require("./selectors-CKscOzcZ.cjs"),P=new Error("request for lock canceled");var N=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 C{constructor(e,s=P){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 N(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 C(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??=(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._.equals(e.minSize,i.minSize)&&n.push(["minSize",{prev:i.minSize,next:e.minSize},async()=>await s.setMinSize(e.minSize)]),e.maxSize!=null&&!t._.equals(e.maxSize,i.maxSize)&&n.push(["maxSize",{prev:i.maxSize,next:e.maxSize},async()=>await s.setMaxSize(e.maxSize)]),e.size!=null&&!t._.equals(e.size,i.size)&&n.push(["size",{prev:i.size,next:e.size},async()=>await s.setSize(e.size)]),e.position!=null&&!t._.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??=!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,O=t.shouldEmit(c,a.type);return Y.runExclusive(async()=>{try{w!==null&&_!==null&&await X(w,_,i,e),O&&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=A.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?.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)}})()}),W=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?.visible!=null&&(a.visible=i.visible),a.focusCount=0,a.centerCount=0,a.processCount=0,[n,a]))),s};class v{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:v,SLICE_NAME:t.SLICE_NAME,ZERO_SLICE_STATE:t.ZERO_SLICE_STATE,closeWindow:t.closeWindow,completeProcess:t.completeProcess,configureStore:W,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=v;exports.configureStore=W;