UNPKG

@glue42/web

Version:

Glue42 Core client application package

1 lines 243 kB
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):((e="undefined"!=typeof globalThis?globalThis:e||self).web=e.web||{},e.web.min=t())}(this,(function(){"use strict";function e(e,t){var n={};for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(i=Object.getOwnPropertySymbols(e);o<i.length;o++)t.indexOf(i[o])<0&&Object.prototype.propertyIsEnumerable.call(e,i[o])&&(n[i[o]]=e[i[o]])}return n}function t(e,t,n,i){return new(n||(n=Promise))((function(o,r){function s(e){try{c(i.next(e))}catch(e){r(e)}}function a(e){try{c(i.throw(e))}catch(e){r(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(s,a)}c((i=i.apply(e,t||[])).next())}))}const n={logger:"info",gateway:{webPlatform:{}},libraries:[],exposeGlue:!0};var i=function(e){return{ok:!0,result:e}},o=function(e){return{ok:!1,error:e}},r=function(e){return!0===e.ok?Promise.resolve(e.result):Promise.reject(e.error)},s=function(e){if(!0===e.ok)return e.result;throw e.error},a=function(e,t){return!0===t.ok?i(e(t.result)):t},c=function(e,t,n){return!1===t.ok?t:!1===n.ok?n:i(e(t.result,n.result))},u=function(e,t){return!0===t.ok?t:o(e(t.error))},d=function(e,t){return!0===t.ok?e(t.result):t},h=function(){return h=Object.assign||function(e){for(var t,n=1,i=arguments.length;n<i;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},h.apply(this,arguments)};function l(e,t){if(e===t)return!0;if(null===e&&null===t)return!0;if(typeof e!=typeof t)return!1;if("object"==typeof e){if(Array.isArray(e)){if(!Array.isArray(t))return!1;if(e.length!==t.length)return!1;for(var n=0;n<e.length;n++)if(!l(e[n],t[n]))return!1;return!0}var i=Object.keys(e);if(i.length!==Object.keys(t).length)return!1;for(n=0;n<i.length;n++){if(!t.hasOwnProperty(i[n]))return!1;if(!l(e[i[n]],t[i[n]]))return!1}return!0}}var p=function(e){return Array.isArray(e)},f=function(e){return"object"==typeof e&&null!==e&&!p(e)},g=function(e,t){return"expected "+e+", got "+function(e){switch(typeof e){case"string":return"a string";case"number":return"a number";case"boolean":return"a boolean";case"undefined":return"undefined";case"object":return e instanceof Array?"an array":null===e?"null":"an object";default:return JSON.stringify(e)}}(t)},m=function(e){return e.map((function(e){return"string"==typeof e?"."+e:"["+e+"]"})).join("")},v=function(e,t){var n=t.at,i=function(e,t){var n={};for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&t.indexOf(i)<0&&(n[i]=e[i]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(i=Object.getOwnPropertySymbols(e);o<i.length;o++)t.indexOf(i[o])<0&&Object.prototype.propertyIsEnumerable.call(e,i[o])&&(n[i[o]]=e[i[o]])}return n}(t,["at"]);return h({at:e+(n||"")},i)},y=function(){function e(t){var n=this;this.decode=t,this.run=function(e){return u((function(t){return{kind:"DecoderError",input:e,at:"input"+(t.at||""),message:t.message||""}}),n.decode(e))},this.runPromise=function(e){return r(n.run(e))},this.runWithException=function(e){return s(n.run(e))},this.map=function(t){return new e((function(e){return a(t,n.decode(e))}))},this.andThen=function(t){return new e((function(e){return d((function(n){return t(n).decode(e)}),n.decode(e))}))},this.where=function(t,i){return n.andThen((function(n){return t(n)?e.succeed(n):e.fail(i)}))}}return e.string=function(){return new e((function(e){return"string"==typeof e?i(e):o({message:g("a string",e)})}))},e.number=function(){return new e((function(e){return"number"==typeof e?i(e):o({message:g("a number",e)})}))},e.boolean=function(){return new e((function(e){return"boolean"==typeof e?i(e):o({message:g("a boolean",e)})}))},e.constant=function(t){return new e((function(e){return l(e,t)?i(t):o({message:"expected "+JSON.stringify(t)+", got "+JSON.stringify(e)})}))},e.object=function(t){return new e((function(e){if(f(e)&&t){var n={};for(var r in t)if(t.hasOwnProperty(r)){var s=t[r].decode(e[r]);if(!0!==s.ok)return void 0===e[r]?o({message:"the key '"+r+"' is required but was not present"}):o(v("."+r,s.error));void 0!==s.result&&(n[r]=s.result)}return i(n)}return f(e)?i(e):o({message:g("an object",e)})}))},e.array=function(t){return new e((function(e){if(p(e)&&t){return e.reduce((function(e,n,i){return c((function(e,t){return e.concat([t])}),e,function(e,n){return u((function(e){return v("["+n+"]",e)}),t.decode(e))}(n,i))}),i([]))}return p(e)?i(e):o({message:g("an array",e)})}))},e.tuple=function(t){return new e((function(e){if(p(e)){if(e.length!==t.length)return o({message:"expected a tuple of length "+t.length+", got one of length "+e.length});for(var n=[],r=0;r<t.length;r++){var s=t[r].decode(e[r]);if(!s.ok)return o(v("["+r+"]",s.error));n[r]=s.result}return i(n)}return o({message:g("a tuple of length "+t.length,e)})}))},e.union=function(t,n){for(var i=[],o=2;o<arguments.length;o++)i[o-2]=arguments[o];return e.oneOf.apply(e,[t,n].concat(i))},e.intersection=function(t,n){for(var o=[],r=2;r<arguments.length;r++)o[r-2]=arguments[r];return new e((function(e){return[t,n].concat(o).reduce((function(t,n){return c(Object.assign,t,n.decode(e))}),i({}))}))},e.anyJson=function(){return new e((function(e){return i(e)}))},e.unknownJson=function(){return new e((function(e){return i(e)}))},e.dict=function(t){return new e((function(e){if(f(e)){var n={};for(var r in e)if(e.hasOwnProperty(r)){var s=t.decode(e[r]);if(!0!==s.ok)return o(v("."+r,s.error));n[r]=s.result}return i(n)}return o({message:g("an object",e)})}))},e.optional=function(t){return new e((function(e){return null==e?i(void 0):t.decode(e)}))},e.oneOf=function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];return new e((function(e){for(var n=[],i=0;i<t.length;i++){var r=t[i].decode(e);if(!0===r.ok)return r;n[i]=r.error}var s=n.map((function(e){return"at error"+(e.at||"")+": "+e.message})).join('", "');return o({message:'expected a value matching one of the decoders, got the errors ["'+s+'"]'})}))},e.withDefault=function(t,n){return new e((function(e){return i(function(e,t){return!0===t.ok?t.result:e}(t,n.decode(e)))}))},e.valueAt=function(t,n){return new e((function(e){for(var i=e,r=0;r<t.length;r++){if(void 0===i)return o({at:m(t.slice(0,r+1)),message:"path does not exist"});if("string"==typeof t[r]&&!f(i))return o({at:m(t.slice(0,r+1)),message:g("an object",i)});if("number"==typeof t[r]&&!p(i))return o({at:m(t.slice(0,r+1)),message:g("an array",i)});i=i[t[r]]}return u((function(e){return void 0===i?{at:m(t),message:"path does not exist"}:v(m(t),e)}),n.decode(i))}))},e.succeed=function(t){return new e((function(e){return i(t)}))},e.fail=function(t){return new e((function(e){return o({message:t})}))},e.lazy=function(t){return new e((function(e){return t().decode(e)}))},e}(),b=y.string,w=y.number,I=y.boolean,S=y.anyJson;y.unknownJson;var C=y.constant,x=y.object,_=y.array;y.tuple,y.dict;var T=y.optional,P=y.oneOf;y.union,y.intersection,y.withDefault,y.valueAt,y.succeed,y.fail;var k=y.lazy;const M=b().where((e=>e.length>0),"Expected a non-empty string"),R=w().where((e=>e>=0),"Expected a non-negative number"),j=P(C("system"),C("windows"),C("appManager"),C("layouts"),C("intents"),C("notifications"),C("channels"),C("extension"),C("themes")),E=P(C("openWindow"),C("windowHello"),C("windowAdded"),C("windowRemoved"),C("getBounds"),C("getFrameBounds"),C("getUrl"),C("moveResize"),C("focus"),C("close"),C("getTitle"),C("setTitle"),C("focusChange")),A=P(C("appHello"),C("appDirectoryStateChange"),C("instanceStarted"),C("instanceStopped"),C("applicationStart"),C("instanceStop"),C("clear")),O=P(C("layoutAdded"),C("layoutChanged"),C("layoutRemoved"),C("get"),C("getAll"),C("export"),C("import"),C("remove"),C("clientSaveRequest"),C("getGlobalPermissionState"),C("checkGlobalActivated"),C("requestGlobalPermission"),C("getDefaultGlobal"),C("setDefaultGlobal"),C("clearDefaultGlobal")),N=P(C("raiseNotification"),C("requestPermission"),C("notificationShow"),C("notificationClick"),C("getPermission"),C("list"),C("notificationRaised"),C("notificationClosed"),C("click"),C("clear"),C("clearAll")),D=P(C("getEnvironment"),C("getBase"),C("platformShutdown")),W=P(C("top"),C("left"),C("right"),C("bottom")),L=x({top:w(),left:w(),width:R,height:R}),q=T(x({top:T(w()),left:T(w()),width:T(R),height:T(R),context:T(S()),relativeTo:T(M),relativeDirection:T(W),windowId:T(M),layoutComponentId:T(M)})),F=x({name:M,url:M,options:q}),G=x({windowId:T(M)}),U=x({windowId:M,name:M}),B=x({windowId:M}),$=x({windows:_(U),isWorkspaceFrame:I()}),J=x({windowId:M,title:b()}),H=x({windowId:M,hasFocus:I()}),K=x({windowId:M,top:T(w()),left:T(w()),width:T(R),height:T(R),relative:T(I())}),V=x({windowId:M,bounds:x({top:w(),left:w(),width:R,height:R})}),z=x({bounds:x({top:w(),left:w(),width:R,height:R})}),Q=x({windowId:M,url:M}),X=S(),Y=x({top:T(w()),left:T(w()),width:T(R),height:T(R)}),Z=x({id:M,applicationName:M}),ee=x({url:M,top:T(w()),left:T(w()),width:T(R),height:T(R)}),te=x({name:M,displayName:T(b()),contexts:T(_(b())),customConfig:T(x())}),ne=x({name:M,title:T(M),version:T(M),appId:T(M),manifest:M,manifestType:M,tooltip:T(M),description:T(M),contactEmail:T(M),supportEmail:T(M),publisher:T(M),images:T(_(x({url:T(M)}))),icons:T(_(x({icon:T(M)}))),customConfig:S(),intents:T(_(te))}),ie=x({name:M,type:M.where((e=>"window"===e),"Expected a value of window"),title:T(M),version:T(M),customProperties:T(S()),icon:T(b()),caption:T(b()),details:ee,intents:T(_(te)),hidden:T(I())}),oe=P(ie,ne);x({definitions:_(oe),mode:P(C("replace"),C("merge"))});const re=x({name:M}),se=x({definitions:_(ie)}),ae=x({name:M,type:M.where((e=>"window"===e),"Expected a value of window"),instances:_(Z),userProperties:T(S()),title:T(M),version:T(M),icon:T(M),caption:T(M)}),ce=x({name:M,type:M.where((e=>"window"===e),"Expected a value of window"),userProperties:S(),title:T(M),version:T(M),icon:T(M),caption:T(M)}),ue=x({appsAdded:_(ce),appsChanged:_(ce),appsRemoved:_(ce)}),de=x({apps:_(ae)}),he=x({id:M}),le=x({name:M,waitForAGMReady:I(),id:T(M),context:T(S()),top:T(w()),left:T(w()),width:T(R),height:T(R),relativeTo:T(M),relativeDirection:T(P(C("top"),C("left"),C("right"),C("bottom"))),forceChromeTab:T(I()),layoutComponentId:T(M)}),pe=P(C("Global"),C("Activity"),C("ApplicationDefault"),C("Swimlane"),C("Workspace")),fe=P(C("application"),C("activity")),ge=x({context:T(S()),bounds:L,createArgs:x({name:T(M),url:T(M),context:T(S())}),windowState:T(M),restoreState:T(M),instanceId:M,isCollapsed:T(I()),isSticky:T(I()),restoreSettings:x({groupId:T(M),groupZOrder:T(w())})}),me=x({type:C("window"),componentType:T(fe),application:M,state:ge}),ve=x({type:C("window"),config:x({appName:M,url:T(M),title:T(b()),allowExtract:T(I()),allowReorder:T(I()),showCloseButton:T(I()),isMaximized:T(I())})}),ye=x({type:C("group"),config:S(),children:_(P(ve))}),be=x({type:C("column"),config:S(),children:_(P(ye,ve,k((()=>be)),k((()=>we))))}),we=x({type:C("row"),config:S(),children:_(P(be,ye,ve,k((()=>we))))}),Ie=x({config:S(),context:S(),children:_(P(we,be,ye,ve))}),Se=x({type:C("Workspace"),application:T(M),state:Ie}),Ce=x({bounds:L,instanceId:M,selectedWorkspace:R,workspaces:_(Ie),windowState:T(M),restoreState:T(M),context:T(S())}),xe=x({type:C("workspaceFrame"),application:M,componentType:T(fe),state:Ce}),_e=x({name:M,type:pe,components:_(P(me,Se,xe)),context:T(S()),metadata:T(S()),version:T(w())}),Te=x({name:M,context:T(S()),metadata:T(S()),instances:T(_(M)),ignoreInstances:T(_(M))}),Pe=x({name:M,context:T(S()),closeRunningInstance:T(I()),closeMe:T(I()),timeout:T(R)}),ke=x({name:M,type:pe,context:T(S()),metadata:T(S())}),Me=x({name:M,type:pe}),Re=x({layout:Te}),je=x({layout:Pe}),Ee=x({type:pe}),Ae=x({layouts:_(_e)}),Oe=P(C("replace"),C("merge")),Ne=x({layouts:_(_e),mode:Oe,isManagerOperation:T(I())}),De=x({summaries:_(ke)}),We=x({layout:_e}),Le=x({layout:T(_e)}),qe=x({name:M}),Fe=P(C("findIntent"),C("getIntents"),C("raiseIntent"),C("raise")),Ge=x({applicationName:M,applicationTitle:b(),applicationDescription:T(b()),applicationIcon:T(b()),type:P(C("app"),C("instance")),displayName:T(b()),contextTypes:T(_(M)),instanceId:T(b()),instanceTitle:T(b()),resultType:T(b())});x({applicationName:b(),applicationIcon:T(b()),instanceId:T(b())});const Ue=x({intent:M,handler:Ge}),Be=x({name:M,handlers:_(Ge)}),$e=P(C("startNew"),C("reuse"),x({app:T(M),instance:T(M)})),Je=x({type:T(M),data:T(S())}),He=x({intents:_(Be)}),Ke=x({name:T(M),contextType:T(M),resultType:T(M)}),Ve=P(M,Ke),ze=x({filter:T(Ke)}),Qe=x({intent:M,target:T($e),context:T(Je),options:T(q),handlers:T(_(Ge)),timeout:T(R),waitUserResponseIndefinitely:T(I())}),Xe=P(M,Qe),Ye=x({enabled:I(),appName:M,waitResponseTimeout:w()}),Ze=x({intentRequest:Qe,resolverConfig:Ye}),et=x({request:Qe,handler:Ge,result:S()}),tt=x({intent:M,contextTypes:T(_(M)),displayName:T(b()),icon:T(b()),description:T(b()),resultType:T(b())}),nt=P(M,tt),it=e=>M.where((t=>e.includes(t)),"Expected a valid channel name"),ot=x({method:M,arguments:T(S()),target:T(P(C("all"),C("best")))}),rt=x({action:b(),title:M,icon:T(b()),interop:T(ot)}),st=x({badge:T(b()),body:T(b()),data:T(S()),dir:T(P(C("auto"),C("ltr"),C("rtl"))),icon:T(b()),image:T(b()),lang:T(b()),renotify:T(I()),requireInteraction:T(I()),silent:T(I()),tag:T(b()),timestamp:T(R),vibrate:T(_(w()))}),at=x({title:M,clickInterop:T(ot),actions:T(_(rt)),focusPlatformOnDefaultClick:T(I()),badge:T(b()),body:T(b()),data:T(S()),dir:T(P(C("auto"),C("ltr"),C("rtl"))),icon:T(b()),image:T(b()),lang:T(b()),renotify:T(I()),requireInteraction:T(I()),silent:T(I()),tag:T(b()),timestamp:T(R),vibrate:T(_(w())),severity:T(P(C("Low"),C("None"),C("Medium"),C("High"),C("Critical"))),showToast:T(I()),showInPanel:T(I())}),ct=x({name:M,meta:x({color:M}),data:T(x())}),ut=x({settings:at,id:M}),dt=x({settings:at}),ht=x({permissionGranted:I()}),lt=x({permission:P(C("default"),C("granted"),C("denied"))}),pt=x({definition:st,action:T(b()),id:T(M)}),ft=x({layoutType:P(C("Global"),C("Workspace")),layoutName:M,context:T(S())}),gt=x({windowContext:T(S())}),mt=x({state:P(C("prompt"),C("denied"),C("granted"))}),vt=x({isAvailable:I()}),yt=x({itemId:M}),bt=x({isSupported:I()}),wt=x({operation:M}),It=x({bounds:L}),St=x({displayName:M,name:M}),Ct=x({theme:St}),xt=x({themes:_(St)}),_t=x({name:M}),Tt=x({id:M,title:M,clickInterop:T(ot),actions:T(_(rt)),focusPlatformOnDefaultClick:T(I()),badge:T(b()),body:T(b()),data:T(S()),dir:T(P(C("auto"),C("ltr"),C("rtl"))),icon:T(b()),image:T(b()),lang:T(b()),renotify:T(I()),requireInteraction:T(I()),silent:T(I()),tag:T(b()),timestamp:T(R),vibrate:T(_(w())),severity:T(P(C("Low"),C("None"),C("Medium"),C("High"),C("Critical"))),showToast:T(I()),showInPanel:T(I())}),Pt=x({notification:Tt}),kt=x({notifications:_(Tt)}),Mt=x({id:M}),Rt={openWindow:{name:"openWindow",dataDecoder:F,resultDecoder:U},windowHello:{name:"windowHello",dataDecoder:G,resultDecoder:$},windowAdded:{name:"windowAdded",dataDecoder:U},windowRemoved:{name:"windowRemoved",dataDecoder:B},getBounds:{name:"getBounds",dataDecoder:B,resultDecoder:V},getFrameBounds:{name:"getFrameBounds",dataDecoder:B,resultDecoder:z},getUrl:{name:"getUrl",dataDecoder:B,resultDecoder:Q},moveResize:{name:"moveResize",dataDecoder:K},focus:{name:"focus",dataDecoder:B},close:{name:"close",dataDecoder:B},getTitle:{name:"getTitle",dataDecoder:B,resultDecoder:J},setTitle:{name:"setTitle",dataDecoder:J},focusChange:{name:"focusChange",dataDecoder:H}};function jt(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function Et(e){if(e&&e.errorHandling&&"function"!=typeof e.errorHandling&&"log"!==e.errorHandling&&"silent"!==e.errorHandling&&"throw"!==e.errorHandling)throw new Error('Invalid options passed to createRegistry. Prop errorHandling should be ["log" | "silent" | "throw" | (err) => void], but '+typeof e.errorHandling+" was passed");var t=e&&"function"==typeof e.errorHandling&&e.errorHandling,n={};function i(n,i){var o=n instanceof Error?n:new Error(n);if(t)t(o);else{var r='[ERROR] callback-registry: User callback for key "'+i+'" failed: '+o.stack;if(e)switch(e.errorHandling){case"log":return console.error(r);case"silent":return;case"throw":throw new Error(r)}console.error(r)}}return{add:function(e,t,o){var r=n[e];return r||(r=[],n[e]=r),r.push(t),o&&setTimeout((function(){o.forEach((function(o){var r;if(null===(r=n[e])||void 0===r?void 0:r.includes(t))try{Array.isArray(o)?t.apply(void 0,o):t.apply(void 0,[o])}catch(t){i(t,e)}}))}),0),function(){var i=n[e];i&&(0===(i=i.reduce((function(e,n,i){return n===t&&e.length===i||e.push(n),e}),[])).length?delete n[e]:n[e]=i)}},execute:function(e){for(var t=[],o=1;o<arguments.length;o++)t[o-1]=arguments[o];var r=n[e];if(!r||0===r.length)return[];var s=[];return r.forEach((function(n){try{var o=n.apply(void 0,t);s.push(o)}catch(t){s.push(void 0),i(t,e)}})),s},clear:function(){n={}},clearKey:function(e){n[e]&&delete n[e]}}}Et.default=Et;var At=Et;class Ot{constructor(e,t,n){this._id=e,this._name=t,this._bridge=n,this.registry=At(),this.myCtxKey=`___window___${this.id}`}get id(){return this._id.slice()}get name(){return this._name.slice()}clean(){this.ctxUnsubscribe&&this.ctxUnsubscribe()}processSelfFocusEvent(e){this.me.isFocused=e,this.registry.execute("focus-change",this.me)}toApi(){return t(this,void 0,void 0,(function*(){return this.ctxUnsubscribe=yield this._bridge.contextLib.subscribe(this.myCtxKey,(e=>this.registry.execute("context-updated",e))),this.me={id:this.id,name:this.name,isFocused:!1,getURL:this.getURL.bind(this),moveResize:this.moveResize.bind(this),resizeTo:this.resizeTo.bind(this),moveTo:this.moveTo.bind(this),focus:this.focus.bind(this),close:this.close.bind(this),getTitle:this.getTitle.bind(this),setTitle:this.setTitle.bind(this),getBounds:this.getBounds.bind(this),getContext:this.getContext.bind(this),updateContext:this.updateContext.bind(this),setContext:this.setContext.bind(this),onContextUpdated:this.onContextUpdated.bind(this),onFocusChanged:this.onFocusChanged.bind(this)},this.me}))}getURL(){return t(this,void 0,void 0,(function*(){return(yield this._bridge.send("windows",Rt.getUrl,{windowId:this.id})).url}))}onFocusChanged(e){if("function"!=typeof e)throw new Error("Cannot subscribe to context changes, because the provided callback is not a function!");return this.registry.add("focus-change",e)}moveResize(e){return t(this,void 0,void 0,(function*(){const t=Y.runWithException(e),n=Object.assign({},t,{windowId:this.id,relative:!1});return yield this._bridge.send("windows",Rt.moveResize,n),this.me}))}resizeTo(e,n){return t(this,void 0,void 0,(function*(){if(void 0===e&&void 0===n)return this.me;void 0!==e&&R.runWithException(e),void 0!==n&&R.runWithException(n);const t=Object.assign({},{width:e,height:n},{windowId:this.id,relative:!0});return yield this._bridge.send("windows",Rt.moveResize,t),this.me}))}moveTo(e,n){return t(this,void 0,void 0,(function*(){if(void 0===e&&void 0===n)return this.me;void 0!==e&&w().runWithException(e),void 0!==n&&w().runWithException(n);const t=Object.assign({},{top:e,left:n},{windowId:this.id,relative:!0});return yield this._bridge.send("windows",Rt.moveResize,t),this.me}))}focus(){return t(this,void 0,void 0,(function*(){return"Platform"===this.name?window.open(void 0,this.id):yield this._bridge.send("windows",Rt.focus,{windowId:this.id}),this.me}))}close(){return t(this,void 0,void 0,(function*(){return yield this._bridge.send("windows",Rt.close,{windowId:this.id}),this.me}))}getTitle(){return t(this,void 0,void 0,(function*(){return(yield this._bridge.send("windows",Rt.getTitle,{windowId:this.id})).title}))}setTitle(e){return t(this,void 0,void 0,(function*(){const t=M.runWithException(e);return yield this._bridge.send("windows",Rt.setTitle,{windowId:this.id,title:t}),this.me}))}getBounds(){return t(this,void 0,void 0,(function*(){return(yield this._bridge.send("windows",Rt.getBounds,{windowId:this.id})).bounds}))}getContext(){return t(this,void 0,void 0,(function*(){return yield this._bridge.contextLib.get(this.myCtxKey)}))}updateContext(e){return t(this,void 0,void 0,(function*(){const t=X.runWithException(e);return yield this._bridge.contextLib.update(this.myCtxKey,t),this.me}))}setContext(e){return t(this,void 0,void 0,(function*(){const t=X.runWithException(e);return yield this._bridge.contextLib.set(this.myCtxKey,t),this.me}))}onContextUpdated(e){if("function"!=typeof e)throw new Error("Cannot subscribe to context changes, because the provided callback is not a function!");return this.registry.add("context-updated",(t=>{e(t,this.me)}))}}const Nt={operationCheck:{name:"operationCheck",dataDecoder:wt,resultDecoder:bt},getWorkspaceWindowFrameBounds:{name:"getWorkspaceWindowFrameBounds",resultDecoder:It,dataDecoder:yt}},Dt=(e,t,n)=>new Promise(((i,o)=>{const r=setTimeout((()=>{o(n||`Promise timeout hit: ${t}`)}),t);new Promise(e).then((e=>{clearTimeout(r),i(e)})).catch((e=>{clearTimeout(r),o(e)}))}));class Wt{constructor(){this.registry=At(),this.allWindowProjections=[]}start(e,n){return t(this,void 0,void 0,(function*(){this.logger=e.logger.subLogger("windows.controller.web"),this.logger.trace("starting the web windows controller"),this.publicWindowId=n.publicWindowId,this.addWindowOperationExecutors(),this.ioc=n,this.bridge=n.bridge,this.instanceId=e.interop.instance.instance,this.logger.trace(`set the public window id: ${this.publicWindowId}, set the bridge operations and ioc, registering with the platform now`),this.platformRegistration=this.registerWithPlatform(),yield this.platformRegistration,yield this.initializeFocusTracking(),this.logger.trace("registration with the platform successful, attaching the windows property to glue and returning");const t=this.toApi();e.windows=t}))}handlePlatformShutdown(){this.registry.clear(),this.allWindowProjections=[],this.focusEventHandler&&(document.removeEventListener("visibilityChange",this.focusEventHandler),window.removeEventListener("focus",this.focusEventHandler),window.removeEventListener("blur",this.focusEventHandler))}handleBridgeMessage(e){return t(this,void 0,void 0,(function*(){yield this.platformRegistration;const t=E.runWithException(e.operation),n=Rt[t];if(!n.execute)return;let i=e.data;return n.dataDecoder&&(i=n.dataDecoder.runWithException(e.data)),yield n.execute(i)}))}open(e,n,i){return t(this,void 0,void 0,(function*(){M.runWithException(e),M.runWithException(n);const t=q.runWithException(i),o=yield this.bridge.send("windows",Rt.openWindow,{name:e,url:n,options:t});return this.waitForWindowAdded(o.windowId)}))}list(){return this.allWindowProjections.map((e=>e.api))}findById(e){var t;return M.runWithException(e),null===(t=this.allWindowProjections.find((t=>t.id===e)))||void 0===t?void 0:t.api}toApi(){return{open:this.open.bind(this),my:this.my.bind(this),list:this.list.bind(this),findById:this.findById.bind(this),onWindowAdded:this.onWindowAdded.bind(this),onWindowRemoved:this.onWindowRemoved.bind(this),onWindowGotFocus:this.onWindowGotFocus.bind(this),onWindowLostFocus:this.onWindowLostFocus.bind(this)}}addWindowOperationExecutors(){Rt.focusChange.execute=this.handleFocusChangeEvent.bind(this),Rt.windowAdded.execute=this.handleWindowAdded.bind(this),Rt.windowRemoved.execute=this.handleWindowRemoved.bind(this),Rt.getBounds.execute=this.handleGetBounds.bind(this),Rt.getFrameBounds.execute=this.handleGetBounds.bind(this),Rt.getTitle.execute=this.handleGetTitle.bind(this),Rt.getUrl.execute=this.handleGetUrl.bind(this),Rt.moveResize.execute=this.handleMoveResize.bind(this),Rt.setTitle.execute=this.handleSetTitle.bind(this)}my(){return Object.assign({},this.me)}onWindowAdded(e){if("function"!=typeof e)throw new Error("Cannot subscribe to window added, because the provided callback is not a function!");return this.registry.add("window-added",e)}onWindowRemoved(e){if("function"!=typeof e)throw new Error("Cannot subscribe to window removed, because the provided callback is not a function!");return this.registry.add("window-removed",e)}onWindowGotFocus(e){if("function"!=typeof e)throw new Error("Cannot subscribe to onWindowGotFocus, because the provided callback is not a function!");return this.registry.add("window-got-focus",e)}onWindowLostFocus(e){if("function"!=typeof e)throw new Error("Cannot subscribe to onWindowLostFocus, because the provided callback is not a function!");return this.registry.add("window-lost-focus",e)}sayHello(){return t(this,void 0,void 0,(function*(){return yield this.bridge.send("windows",Rt.windowHello,{windowId:this.publicWindowId})}))}registerWithPlatform(){return t(this,void 0,void 0,(function*(){const{windows:e,isWorkspaceFrame:t}=yield this.sayHello();if(this.isWorkspaceFrame=t,this.logger.trace("the platform responded to the hello message"),!this.isWorkspaceFrame&&this.publicWindowId){this.logger.trace("i am not treated as a workspace frame, setting my window");const t=e.find((e=>e.windowId===this.publicWindowId));if(!t)throw new Error("Cannot initialize the window library, because I received no information about me from the platform");const n=yield this.ioc.buildWebWindow(this.publicWindowId,t.name);this.me=n.api,this.allWindowProjections.push(n)}const n=yield Promise.all(e.filter((e=>e.windowId!==this.publicWindowId)).map((e=>this.ioc.buildWebWindow(e.windowId,e.name))));this.logger.trace("all windows projections are completed, building the list collection"),this.allWindowProjections.push(...n)}))}handleFocusChangeEvent(e){return t(this,void 0,void 0,(function*(){const t=this.allWindowProjections.find((t=>t.id===e.windowId));if(!t)return;t.model.processSelfFocusEvent(e.hasFocus);const n=e.hasFocus?"window-got-focus":"window-lost-focus";this.registry.execute(n,t.api)}))}handleWindowAdded(e){return t(this,void 0,void 0,(function*(){if(this.allWindowProjections.some((t=>t.id===e.windowId)))return;const t=yield this.ioc.buildWebWindow(e.windowId,e.name);this.allWindowProjections.push(t),this.registry.execute("window-added",t.api)}))}handleWindowRemoved(e){return t(this,void 0,void 0,(function*(){const t=this.allWindowProjections.find((t=>t.id===e.windowId));t&&(this.allWindowProjections=this.allWindowProjections.filter((t=>t.id!==e.windowId)),t.model.clean(),this.registry.execute("window-removed",t.api))}))}handleGetBounds(){return t(this,void 0,void 0,(function*(){if(!this.me&&!this.isWorkspaceFrame)throw new Error("This window cannot report it's bounds, because it is not a Glue Window, most likely because it is an iframe");return{windowId:this.isWorkspaceFrame?"noop":this.me.id,bounds:{top:window.screenTop,left:window.screenLeft,width:window.innerWidth,height:window.innerHeight}}}))}handleGetTitle(){return t(this,void 0,void 0,(function*(){if(!this.me)throw new Error("This window cannot report it's title, because it is not a Glue Window, most likely because it is an iframe");return{windowId:this.me.id,title:document.title}}))}handleGetUrl(){return t(this,void 0,void 0,(function*(){if(!this.me)throw new Error("This window cannot report it's url, because it is not a Glue Window, most likely because it is an iframe");return{windowId:this.me.id,url:window.location.href}}))}handleMoveResize(e){return t(this,void 0,void 0,(function*(){const t="number"==typeof e.top?e.top:e.relative?0:window.screenTop,n="number"==typeof e.left?e.left:e.relative?0:window.screenLeft,i="number"==typeof e.height?e.height:e.relative?0:window.innerHeight,o="number"==typeof e.width?e.width:e.relative?0:window.innerWidth,r=e.relative?window.moveBy:window.moveTo,s=e.relative?window.resizeBy:window.resizeTo;r(n,t),s(o,i)}))}handleSetTitle(e){return t(this,void 0,void 0,(function*(){document.title=e.title}))}initializeFocusTracking(){return t(this,void 0,void 0,(function*(){if(this.isWorkspaceFrame)return void this.logger.trace("Ignoring the focus tracking, because this client is a workspace frame");try{yield this.bridge.send("windows",Nt.operationCheck,{operation:"focusChange"})}catch(e){return void this.logger.warn("The platform of this client is outdated and does not support focus tracking, disabling focus events for this client.")}const e=document.hasFocus();yield this.transmitFocusChange(!0),e||(yield this.transmitFocusChange(!1)),this.defineEventListeners()}))}processFocusEvent(){const e=document.hasFocus();this.transmitFocusChange(e)}waitForWindowAdded(e){const t=this.allWindowProjections.find((t=>t.id===e));return t?Promise.resolve(t.api):Dt((t=>{const n=this.onWindowAdded((i=>{i.id===e&&(n(),t(i))}))}),3e4,`Timed out waiting for ${e} to be announced`)}transmitFocusChange(e){var n;return t(this,void 0,void 0,(function*(){const t={windowId:(null===(n=this.me)||void 0===n?void 0:n.id)||`iframe-${this.instanceId}`,hasFocus:e};this.me&&(this.me.isFocused=e),yield this.bridge.send("windows",Rt.focusChange,t)}))}defineEventListeners(){this.focusEventHandler=this.processFocusEvent.bind(this),document.addEventListener("visibilityChange",this.focusEventHandler),window.addEventListener("focus",this.focusEventHandler),window.addEventListener("blur",this.focusEventHandler)}}const Lt="T42.Web.Platform.Control",qt="T42.Web.Platform.Stream",Ft="T42.Web.Client.Control",Gt="T42.Core.Plus.Themes.Stream";class Ut{constructor(e,t){this.coreGlue=e,this.communicationId=t,this.platformMethodTimeoutMs=1e4}get contextLib(){return this.coreGlue.contexts}get interopInstance(){return this.coreGlue.interop.instance.instance}stop(){return t(this,void 0,void 0,(function*(){this.running=!1,this.sub.close(),yield this.coreGlue.interop.unregister(Ft)}))}start(e){return t(this,void 0,void 0,(function*(){this.running=!0,this.controllers=e,yield Promise.all([this.checkWaitMethod(Lt),this.checkWaitMethod(qt)]);const t=this.communicationId,[n]=yield Promise.all([this.coreGlue.interop.subscribe(qt,t?{target:{instance:this.communicationId}}:void 0),this.coreGlue.interop.registerAsync(Ft,((e,t,n,i)=>this.passMessageController(e,n,i)))]);this.sub=n,this.sub.onData((e=>this.passMessageController(e.data)))}))}getInteropInstance(e){const t=this.coreGlue.interop.servers().find((t=>t.windowId&&t.windowId===e));return{application:null==t?void 0:t.application,applicationName:null==t?void 0:t.applicationName,peerId:null==t?void 0:t.peerId,instance:null==t?void 0:t.instance,windowId:null==t?void 0:t.windowId}}send(e,n,i,o,r){return t(this,void 0,void 0,(function*(){if(n.dataDecoder)try{n.dataDecoder.runWithException(i)}catch(e){throw new Error(`Unexpected Web->Platform outgoing validation error: ${e.message}, for operation: ${n.name} and input: ${JSON.stringify(e.input)}`)}if(!(!(null==r?void 0:r.includeOperationCheck)||(yield this.checkOperationSupported(e,n)).isSupported))throw new Error(`Cannot complete operation: ${n.name} for domain: ${e} because this client is connected to a platform which does not support it`);try{const t=yield this.transmitMessage(e,n,i,o);return n.resultDecoder&&n.resultDecoder.runWithException(t),t}catch(e){if(e.kind)throw new Error(`Unexpected Web<-Platform incoming validation error: ${e.message}, for operation: ${n.name} and input: ${JSON.stringify(e.input)}`);throw new Error(e.message)}}))}createNotificationsSteam(){return t(this,void 0,void 0,(function*(){if(!this.coreGlue.interop.methods().some((e=>e.name===Gt)))throw new Error("Cannot subscribe to theme changes, because the underlying interop stream does not exist. Most likely this is the case when this client is not connected to Core Plus.");return this.coreGlue.interop.subscribe(Gt,this.communicationId?{target:{instance:this.communicationId}}:void 0)}))}checkOperationSupported(e,n){return t(this,void 0,void 0,(function*(){try{return yield this.send(e,Nt.operationCheck,{operation:n.name})}catch(e){return{isSupported:!1}}}))}checkWaitMethod(e){return Dt((t=>{if(this.coreGlue.interop.methods().some((t=>{const n=t.name===e,i=!this.communicationId||t.getServers().some((e=>e.instance===this.communicationId));return n&&i})))return t();const n=this.coreGlue.interop.serverMethodAdded((i=>{const o=i.method,r=i.server,s=!this.communicationId||r.instance===this.communicationId;o.name===e&&s&&(n(),t())}))}),this.platformMethodTimeoutMs,`Cannot initiate Glue Web, because a system method's discovery timed out: ${e}`)}passMessageController(e,t,n){const i=j.run(e.domain);if(!i.ok)return void(n&&n(`Cannot execute this client control, because of domain validation error: ${JSON.stringify(i.error)}`));const o=i.result;this.controllers[o].handleBridgeMessage(e).then((e=>{t&&t(e)})).catch((e=>{n&&n(e),console.warn(e)}))}transmitMessage(e,n,i,o){return t(this,void 0,void 0,(function*(){const t={domain:e,data:i,operation:n.name};let r;const s=`Internal Platform Communication Error. Attempted operation: ${JSON.stringify(n.name)} with data: ${JSON.stringify(i)}. `,a=this.communicationId;try{if(!this.running)throw new Error("Cannot send a control message, because the platform shut down");if(r=yield this.coreGlue.interop.invoke(Lt,t,a?{instance:this.communicationId}:void 0,o),!r)throw new Error("Received unsupported result from the platform - empty result");if(!Array.isArray(r.all_return_values)||0===r.all_return_values.length)throw new Error("Received unsupported result from the platform - empty values collection")}catch(e){if(e&&e.all_errors&&e.all_errors.length){const t=e.all_errors[0].message;throw new Error(`${s} -> Inner message: ${t}`)}throw new Error(`${s} -> Inner message: ${e.message}`)}return r.all_return_values[0].returned}))}}const Bt={appHello:{name:"appHello",dataDecoder:G,resultDecoder:de},appDirectoryStateChange:{name:"appDirectoryStateChange",dataDecoder:ue},instanceStarted:{name:"instanceStarted",dataDecoder:Z},instanceStopped:{name:"instanceStopped",dataDecoder:Z},applicationStart:{name:"applicationStart",dataDecoder:le,resultDecoder:Z},instanceStop:{name:"instanceStop",dataDecoder:he},import:{name:"import"},remove:{name:"remove",dataDecoder:re},export:{name:"export",resultDecoder:se},clear:{name:"clear"}};class $t{constructor(){this.baseApplicationsTimeoutMS=6e4,this.appImportTimeoutMS=20,this.registry=At(),this.applications=[],this.instances=[]}handlePlatformShutdown(){this.registry.clear(),this.applications=[],this.instances=[],delete this.me}start(e,n){return t(this,void 0,void 0,(function*(){this.logger=e.logger.subLogger("appManger.controller.web"),this.logger.trace("starting the web appManager controller"),this.publicWindowId=n.publicWindowId,this.addOperationsExecutors(),this.ioc=n,this.bridge=n.bridge,this.platformRegistration=this.registerWithPlatform(),yield this.platformRegistration,this.logger.trace("registration with the platform successful, attaching the appManager property to glue and returning");const t=this.toApi();e.appManager=t}))}handleBridgeMessage(e){return t(this,void 0,void 0,(function*(){yield this.platformRegistration;const t=A.runWithException(e.operation),n=Bt[t];if(!n.execute)return;let i=e.data;return n.dataDecoder&&(i=n.dataDecoder.runWithException(e.data)),yield n.execute(i)}))}onInstanceStarted(e){if("function"!=typeof e)throw new Error("onInstanceStarted requires a single argument of type function");return this.registry.add("instance-started",e,this.instances)}onInstanceStopped(e){if("function"!=typeof e)throw new Error("onInstanceStopped requires a single argument of type function");return this.registry.add("instance-stopped",e)}startApplication(e,n,i){var o;return t(this,void 0,void 0,(function*(){const t={name:e,waitForAGMReady:null===(o=null==i?void 0:i.waitForAGMReady)||void 0===o||o,context:n,top:null==i?void 0:i.top,left:null==i?void 0:i.left,width:null==i?void 0:i.width,height:null==i?void 0:i.height,relativeTo:null==i?void 0:i.relativeTo,relativeDirection:null==i?void 0:i.relativeDirection,id:null==i?void 0:i.reuseId,forceChromeTab:null==i?void 0:i.forceTab,layoutComponentId:null==i?void 0:i.layoutComponentId},r=yield this.bridge.send("appManager",Bt.applicationStart,t),s=this.applications.find((e=>e.name===r.applicationName));return this.ioc.buildInstance(r,s)}))}getApplication(e){const t=M.runWithException(e);return this.applications.find((e=>e.name===t))}getInstances(){return this.instances.slice()}toApi(){return{myInstance:this.me,inMemory:{import:this.import.bind(this),remove:this.remove.bind(this),export:this.export.bind(this),clear:this.clear.bind(this)},application:this.getApplication.bind(this),applications:this.getApplications.bind(this),instances:this.getInstances.bind(this),onAppAdded:this.onAppAdded.bind(this),onAppChanged:this.onAppChanged.bind(this),onAppRemoved:this.onAppRemoved.bind(this),onInstanceStarted:this.onInstanceStarted.bind(this),onInstanceStopped:this.onInstanceStopped.bind(this)}}addOperationsExecutors(){Bt.appDirectoryStateChange.execute=this.handleAppDirectoryStateChange.bind(this),Bt.instanceStarted.execute=this.handleInstanceStartedMessage.bind(this),Bt.instanceStopped.execute=this.handleInstanceStoppedMessage.bind(this)}handleAppDirectoryStateChange(e){return t(this,void 0,void 0,(function*(){e.appsAdded.forEach(this.handleApplicationAddedMessage.bind(this)),e.appsChanged.forEach(this.handleApplicationChangedMessage.bind(this)),e.appsRemoved.forEach(this.handleApplicationRemovedMessage.bind(this))}))}onAppAdded(e){if("function"!=typeof e)throw new Error("onAppAdded requires a single argument of type function");return this.registry.add("application-added",e,this.applications)}onAppRemoved(e){if("function"!=typeof e)throw new Error("onAppRemoved requires a single argument of type function");return this.registry.add("application-removed",e)}onAppChanged(e){if("function"!=typeof e)throw new Error("onAppChanged requires a single argument of type function");return this.registry.add("application-changed",e)}handleApplicationAddedMessage(e){return t(this,void 0,void 0,(function*(){if(this.applications.some((t=>t.name===e.name)))return;const t=yield this.ioc.buildApplication(e,[]),n=this.instances.filter((e=>e.application.name===t.name));t.instances.push(...n),this.applications.push(t),this.registry.execute("application-added",t)}))}handleApplicationRemovedMessage(e){return t(this,void 0,void 0,(function*(){const t=this.applications.findIndex((t=>t.name===e.name));if(t<0)return;const n=this.applications[t];this.applications.splice(t,1),this.registry.execute("application-removed",n)}))}handleApplicationChangedMessage(e){return t(this,void 0,void 0,(function*(){const t=this.applications.find((t=>t.name===e.name));if(!t)return this.handleApplicationAddedMessage(e);t.title=e.title,t.version=e.version,t.icon=e.icon,t.caption=e.caption,t.userProperties=e.userProperties,this.registry.execute("application-changed",t)}))}handleInstanceStartedMessage(e){return t(this,void 0,void 0,(function*(){if(this.instances.some((t=>t.id===e.id)))return;const t=this.applications.find((t=>t.name===e.applicationName));if(!t)throw new Error(`Cannot add instance: ${e.id}, because there is no application definition associated with it`);const n=this.ioc.buildInstance(e,t);this.instances.push(n),t.instances.push(n),this.registry.execute("instance-started",n)}))}handleInstanceStoppedMessage(e){return t(this,void 0,void 0,(function*(){const t=this.instances.find((t=>t.id===e.id));if(t){const t=this.instances.findIndex((t=>t.id===e.id));this.instances.splice(t,1)}const n=this.applications.find((t=>t.instances.some((t=>t.id===e.id))));if(n){const t=n.instances.findIndex((t=>t.id===e.id));n.instances.splice(t,1)}t&&this.registry.execute("instance-stopped",t)}))}import(e,n="replace"){return t(this,void 0,void 0,(function*(){if(Oe.runWithException(n),!Array.isArray(e))throw new Error("Import must be called with an array of definitions");if(e.length>1e4)throw new Error("Cannot import more than 10000 app definitions in Glue42 Core.");const t=e.reduce(((e,t)=>{const n=oe.run(t);return n.ok?e.valid.push(t):e.invalid.push({app:null==t?void 0:t.name,error:JSON.stringify(n.error)}),e}),{valid:[],invalid:[]}),i=this.baseApplicationsTimeoutMS+this.appImportTimeoutMS*t.valid.length;return yield this.bridge.send("appManager",Bt.import,{definitions:t.valid,mode:n},{methodResponseTimeoutMs:i}),{imported:t.valid.map((e=>e.name)),errors:t.invalid}}))}remove(e){return t(this,void 0,void 0,(function*(){M.runWithException(e),yield this.bridge.send("appManager",Bt.remove,{name:e},{methodResponseTimeoutMs:this.baseApplicationsTimeoutMS})}))}clear(){return t(this,void 0,void 0,(function*(){yield this.bridge.send("appManager",Bt.clear,void 0,{methodResponseTimeoutMs:this.baseApplicationsTimeoutMS})}))}export(){return t(this,void 0,void 0,(function*(){return(yield this.bridge.send("appManager",Bt.export,void 0,{methodResponseTimeoutMs:this.baseApplicationsTimeoutMS})).definitions}))}getApplications(){return this.applications.slice()}registerWithPlatform(){return t(this,void 0,void 0,(function*(){const e=yield this.bridge.send("appManager",Bt.appHello,{windowId:this.publicWindowId},{methodResponseTimeoutMs:this.baseApplicationsTimeoutMS});this.logger.trace("the platform responded to the hello message with a full list of apps"),this.applications=yield Promise.all(e.apps.map((e=>this.ioc.buildApplication(e,e.instances)))),this.instances=this.applications.reduce(((e,t)=>(e.push(...t.instances),e)),[]),this.me=this.findMyInstance(),this.logger.trace(`all applications were parsed and saved. I am ${this.me?"NOT a":"a"} valid instance`)}))}findMyInstance(){for(const e of this.applications){const t=e.instances.find((e=>e.id===this.publicWindowId));if(t)return t}}}class Jt{constructor(e,t,n){this.data=e,this.bridge=t,this.application=n,this.myCtxKey=`___instance___${this.data.id}`}toApi(){const e=this.bridge.getInteropInstance(this.data.id),t={id:this.data.id,agm:e,application:this.application,stop:this.stop.bind(this),getContext:this.getContext.bind(this)};return this.me=Object.freeze(t),this.me}getContext(){return t(this,void 0,void 0,(function*(){return this.bridge.contextLib.get(this.myCtxKey)}))}stop(){return t(this,void 0,void 0,(function*(){yield this.bridge.send("appManager",Bt.instanceStop,{id:this.data.id})}))}}class Ht{constructor(e,t,n){this.data=e,this.instances=t,this.controller=n}toApi(){const e={name:this.data.name,title:this.data.title,version:this.data.version,icon:this.data.icon,caption:this.data.caption,userProperties:this.data.userProperties,instances:this.instances,start:this.start.bind(this),onInstanceStarted:this.onInstanceStarted.bind(this),onInstanceStopped:this.onInstanceStopped.bind(this)};return this.me=e,this.me}onInstanceStarted(e){if("function"!=typeof e)throw new Error("OnInstanceStarted requires a single argument of type function");return this.controller.onInstanceStarted((t=>{t.application.name===this.data.name&&e(t)}))}onInstanceStopped(e){if("function"!=typeof e)throw new Error("OnInstanceStarted requires a single argument of type function");return this.controller.onInstanceStopped((t=>{t.application.name===this.data.name&&e(t)}))}start(e,n){return t(this,void 0,void 0,(function*(){return this.controller.startApplication(this.data.name,e,n)}))}}const Kt={layoutAdded:{name:"layoutAdded",dataDecoder:_e},layoutChanged:{name:"layoutChanged",dataDecoder:_e},layoutRemoved:{name:"layoutRemoved",dataDecoder:_e},get:{name:"get",dataDecoder:Me,resultDecoder:Le},getAll:{name:"getAll",dataDecoder:Ee,resultDecoder:De},export:{name:"export",dataDecoder:Ee,resultDecoder:Ae},import:{name:"import",dataDecoder:Ne},remove:{name:"remove",dataDecoder:Me},save:{name:"save",dataDecoder:Re,resultDecoder:We},restore:{name:"restore",dataDecoder:je},clientSaveRequest:{name:"clientSaveRequest",dataDecoder:ft,resultDecoder:gt},getGlobalPermissionState:{name:"getGlobalPermissionState",resultDecoder:mt},requestGlobalPermission:{name:"requestGlobalPermission",resultDecoder:vt},checkGlobalActivated:{name:"checkGlobalActivated",resultDecoder:vt},getDefaultGlobal:{name:"getDefaultGlobal",resultDecoder:Le},setDefaultGlobal:{name:"setDefaultGlobal",dataDecoder:qe},clearDefaultGlobal:{name:"clearDefaultGlobal"}};class Vt{constructor(){this.defaultLayoutRestoreTimeoutMS=12e4,this.registry=At()}handlePlatformShutdown(){this.registry.clear()}start(e,n){return t(this,void 0,void 0,(function*(){this.logger=e.logger.subLogger("layouts.controller.web"),this.logger.trace("starting the web layouts controller"),this.bridge=n.bridge,this.windowsController=n.windowsController,this.addOperationsExecutors();const t=this.toApi();this.logger.trace("no need for platform registration, attaching the layouts property to glue and returning"),e.layouts=t}))}handleBridgeMessage(e){return t(this,void 0,void 0,(function*(){const t=O.runWithException(e.operation),n=Kt[t];if(!n.execute)return;let i=e.data;return n.dataDecoder&&(i=n.dataDecoder.runWithException(e.data)),yield n.execute(i)}))}toApi(){const e={get:this.get.bind(this),getAll:this.getAll.bind(this),export:this.export.bind(this),import:this.import.bind(this),save:this.save.bind(this),restore:this.restore.bind(this),remove:this.remove.bind(this),onAdded:this.onAdded.bind(this),onChanged:this.onChanged.bind(this),onRemoved:this.onRemoved.bind(this),onSaveRequested:this.subscribeOnSaveRequested.bind(this),getMultiScreenPermissionState:this.getGlobalPermissionState.bind(this),requestMultiScreenPermission:this.requestGlobalPermission.bind(this),getGlobalTypeState:this.checkGlobalActivated.bind(this),getDefaultGlobal:this.getDefaultGlobal.bind(this),setDefaultGlobal:this.setDefaultGlobal.bind(this),clearDefaultGlobal:this.clearDefaultGlobal.bind(this)};return Object.freeze(e)}addOperationsExecutors(){Kt.layoutAdded.execute=this.handleOnAdded.bind(this),Kt.layoutChanged.execute=this.handleOnChanged.bind(this),Kt.layoutRemoved.execute=this.handleOnRemoved.bind(this),Kt.clientSaveRequest.execute=this.handleSaveRequest.bind(this)}get(e,n){return t(this,void 0,void 0,(function*(){M.runWithException(e),pe.runWithException(n);return(yield this.bridge.send("layouts",Kt.get,{name:e,type:n})).layout}))}getAll(e){return t(this,void 0,void 0,(function*(){pe.runWithException(e);return(yield this.bridge.send("layouts",Kt.getAll,{type:e})).summaries}))}export(e){return t(this,void 0,void 0,(function*(){pe.runWithException(e);return(yield this.bridge.send("layouts",Kt.export,{type:e})).layouts}))}import(e,n="replace"){return t(this,void 0,void 0,(function*(){if(Oe.runWithException(n),!Array.isArray(e))throw new Error("Import must be called with an array of layouts");if(e.length>1e3)throw new Error("Cannot import more than 1000 layouts at once in Glue42 Core.");const t=e.reduce(((e,t)=>{const n=_e.run(t);return n.ok?e.valid.push(t):this.logger.warn(`A layout with name: ${t.name} was not imported, because of error: ${JSON.stringify(n.error)}`),e}),{valid:[]}),i=e.filter((e=>t.valid.some((t=>t.name===e.name))));yield this.bridge.send("layouts",Kt.import,{layouts:i,mode:n})}))}save(e){return t(this,void 0,void 0,(function*(){Te.runWithException(e);return(yield this.bridge.send("layouts",Kt.save,{layout:e})).layout}))}restore(e){return t(this,void 0,void 0,(function*(){Pe.runWithException(e);const t=e.timeout?2*e.timeout:this.defaultLayoutRestoreTimeoutMS;yield this.bridge.send("layouts",Kt.restore,{layout:e},{methodResponseTimeoutMs:t})}))}remove(e,n){return t(this,void 0,void 0,(function*(){pe.runWithException(e),M.runWithException(n),yield this.bridge.send("layouts",Kt.remove,{type:e,name:n})}))}handleSaveRequest(e){return t(this,void 0,void 0,(function*(){const t={};if(this.saveRequestSubscription)try{const n=this.saveRequestSubscription(e);t.windowContext=null==n?void 0:n.windowContext}catch(e){this.logger.warn(`An error was thrown by the onSaveRequested callback, ignoring the callback: ${JSON.stringify(e)}`)}return t}))}getGlobalPermissionState(){return t(this,void 0,void 0,(function*(){return yield this.bridge.send("layouts",Kt.getGlobalPermissionState,void 0)}))}requestGlobalPermission(){return t(this,void 0,void 0,(function*(){const e=(yield this.getGlobalPermissionState()).state;if("denied"===e)return{permissionGranted:!1};if("granted"===e)return{permissionGranted:!0};const t=this.windowsController.my(),n=window.glue42core.isPlatformFrame;if("Platform"!==t.name&&!n)throw new Error("Cannot request permission for multi-window placement from any app other than the Platform.");return{permissionGranted:(yield this.bridge.send("layouts",Kt.requestGlobalPermission,void 0,{methodResponseTimeoutMs:18e4})).isAvailable}}))}checkGlobalActivated(){return t(this,void 0,void 0,(function*(){return{activated:(yield this.bridge.send("layouts",Kt.checkGlobalActivated,void 0)).isAvailable}}))}getDefaultGlobal(){return t(this,void 0,void 0,(function*(){return(yield this.bridge.send("layouts",Kt.getDefaultGlobal,void 0,void 0,{includeOperationCheck:!0})).layout}))}setDefaultGlobal(e){return t(this,void 0,void 0,(function*(){M.runWithException(e),yield this.bridge.send("layouts",Kt.setDefaultGlobal,{name:e},void 0,{includeOperationCheck:!0})}))}clearDefaultGlobal(){return t(this,void 0,void 0,(function*(){yield this.bridge.send("layouts",Kt.clearDefaultGlobal,void 0,void 0,{includeOperationCheck:!0})}))}onAdded(e){return this.export("Global").then((t=>t.forEach((t=>e(t))))).catch((()=>{})),this.export("Workspace").then((t=>t.forEach((t=>e(t))))).catch((()=>{})),this.registry.add(Kt.layoutAdded.name,e)}onChanged(e){return this.registry.add(Kt.layoutChanged.name,e)}onRemoved(e){return this.registry.add(Kt.layoutRemoved.name,e)}subscribeOnSaveRequested(e){if("function"!=typeof e)throw new Error("Cannot subscribe to onSaveRequested, because the provided argument is not a valid callback function.");if(this.saveRequestSubscription)throw new Error("Cannot subscribe to onSaveRequested, because this client has already subscribed and only one subscription is supported. Consider unsubscribing from the initial one.");return this.saveRequestSubscription=e,()=>{delete this.saveRequestSubscription}}handleOnAdded(e){return t(this,void 0,void 0,(function*(){this.registry.execute(Kt.layoutAdded.name,e)}))}handleOnChanged(e){return t(this,void 0,void 0,(fu