You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
tauri-plugins-workspace/plugins/store/src/api-iife.js

2 lines
4.1 KiB

if("__TAURI__"in window){var __TAURI_STORE__=function(e){"use strict";var t=Object.defineProperty,a=(e,a)=>{for(var n in a)t(e,n,{get:a[n],enumerable:!0})},n=(e,t,a)=>{if(!t.has(e))throw TypeError("Cannot "+a)},r=(e,t,a)=>(n(e,t,"read from private field"),a?a.call(e):t.get(e)),i=(e,t,a,r)=>(n(e,t,"write to private field"),r?r.call(e,a):t.set(e,a),a);function s(e,t=!1){let a=window.crypto.getRandomValues(new Uint32Array(1))[0],n=`_${a}`;return Object.defineProperty(window,n,{value:a=>(t&&Reflect.deleteProperty(window,n),e?.(a)),writable:!1,configurable:!0}),a}a({},{Channel:()=>o,PluginListener:()=>l,addPluginListener:()=>u,convertFileSrc:()=>c,invoke:()=>h,transformCallback:()=>s});var _,o=class{constructor(){this.__TAURI_CHANNEL_MARKER__=!0,((e,t,a)=>{if(t.has(e))throw TypeError("Cannot add the same private member more than once");t instanceof WeakSet?t.add(e):t.set(e,a)})(this,_,(()=>{})),this.id=s((e=>{r(this,_).call(this,e)}))}set onmessage(e){i(this,_,e)}get onmessage(){return r(this,_)}toJSON(){return`__CHANNEL__:${this.id}`}};_=new WeakMap;var l=class{constructor(e,t,a){this.plugin=e,this.event=t,this.channelId=a}async unregister(){return h(`plugin:${this.plugin}|remove_listener`,{event:this.event,channelId:this.channelId})}};async function u(e,t,a){let n=new o;return n.onmessage=a,h(`plugin:${e}|register_listener`,{event:t,handler:n}).then((()=>new l(e,t,n.id)))}async function h(e,t={},a){return new Promise(((n,r)=>{let i=s((e=>{n(e),Reflect.deleteProperty(window,`_${_}`)}),!0),_=s((e=>{r(e),Reflect.deleteProperty(window,`_${i}`)}),!0);window.__TAURI_IPC__({cmd:e,callback:i,error:_,payload:t,options:a})}))}function c(e,t="asset"){return window.__TAURI__.convertFileSrc(e,t)}a({},{TauriEvent:()=>p,emit:()=>y,listen:()=>d,once:()=>I});var p=(e=>(e.WINDOW_RESIZED="tauri://resize",e.WINDOW_MOVED="tauri://move",e.WINDOW_CLOSE_REQUESTED="tauri://close-requested",e.WINDOW_CREATED="tauri://window-created",e.WINDOW_DESTROYED="tauri://destroyed",e.WINDOW_FOCUS="tauri://focus",e.WINDOW_BLUR="tauri://blur",e.WINDOW_SCALE_FACTOR_CHANGED="tauri://scale-change",e.WINDOW_THEME_CHANGED="tauri://theme-changed",e.WINDOW_FILE_DROP="tauri://file-drop",e.WINDOW_FILE_DROP_HOVER="tauri://file-drop-hover",e.WINDOW_FILE_DROP_CANCELLED="tauri://file-drop-cancelled",e.MENU="tauri://menu",e))(p||{});async function w(e,t){await h("plugin:event|unlisten",{event:e,eventId:t})}async function d(e,t,a){return h("plugin:event|listen",{event:e,windowLabel:a?.target,handler:s(t)}).then((t=>async()=>w(e,t)))}async function I(e,t,a){return d(e,(a=>{t(a),w(e,a.id).catch((()=>{}))}),a)}async function y(e,t,a){await h("plugin:event|emit",{event:e,windowLabel:a?.target,payload:t})}return e.Store=class{constructor(e){this.path=e}async set(e,t){return await window.__TAURI_INVOKE__("plugin:store|set",{path:this.path,key:e,value:t})}async get(e){return await window.__TAURI_INVOKE__("plugin:store|get",{path:this.path,key:e})}async has(e){return await window.__TAURI_INVOKE__("plugin:store|has",{path:this.path,key:e})}async delete(e){return await window.__TAURI_INVOKE__("plugin:store|delete",{path:this.path,key:e})}async clear(){return await window.__TAURI_INVOKE__("plugin:store|clear",{path:this.path})}async reset(){return await window.__TAURI_INVOKE__("plugin:store|reset",{path:this.path})}async keys(){return await window.__TAURI_INVOKE__("plugin:store|keys",{path:this.path})}async values(){return await window.__TAURI_INVOKE__("plugin:store|values",{path:this.path})}async entries(){return await window.__TAURI_INVOKE__("plugin:store|entries",{path:this.path})}async length(){return await window.__TAURI_INVOKE__("plugin:store|length",{path:this.path})}async load(){return await window.__TAURI_INVOKE__("plugin:store|load",{path:this.path})}async save(){return await window.__TAURI_INVOKE__("plugin:store|save",{path:this.path})}async onKeyChange(e,t){return await d("store://change",(a=>{a.payload.path===this.path&&a.payload.key===e&&t(a.payload.value)}))}async onChange(e){return await d("store://change",(t=>{t.payload.path===this.path&&e(t.payload.key,t.payload.value)}))}},e}({});Object.defineProperty(window.__TAURI__,"store",{value:__TAURI_STORE__})}