From 05b9d81ee6bcc920defca76cff00178b301fffe8 Mon Sep 17 00:00:00 2001 From: Amr Bashir <48618675+amrbashir@users.noreply.github.com> Date: Mon, 2 Aug 2021 15:58:09 +0200 Subject: [PATCH] feat(api.js): add nodejs-inspired functions in `path` module (#2310) Co-authored-by: Lucas Nogueira --- .changes/api-path-module.md | 7 + core/tauri/Cargo.toml | 5 +- core/tauri/build.rs | 4 +- core/tauri/scripts/bundle.js | 2 +- core/tauri/src/endpoints.rs | 8 ++ core/tauri/src/endpoints/file_system.rs | 22 --- core/tauri/src/endpoints/path.rs | 156 ++++++++++++++++++++++ tooling/api/src/helpers/tauri.ts | 1 + tooling/api/src/path.ts | 170 ++++++++++++++++++------ tooling/cli.rs/config_definition.rs | 43 +++++- tooling/cli.rs/schema.json | 59 +++++++- tooling/cli.rs/src/helpers/config.rs | 3 +- 12 files changed, 406 insertions(+), 74 deletions(-) create mode 100644 .changes/api-path-module.md create mode 100644 core/tauri/src/endpoints/path.rs diff --git a/.changes/api-path-module.md b/.changes/api-path-module.md new file mode 100644 index 000000000..0a9673050 --- /dev/null +++ b/.changes/api-path-module.md @@ -0,0 +1,7 @@ +--- +"api": patch +--- + +- Add new nodejs-inspired functions which are `join`, `resolve`, `normalize`, `dirname`, `basename` and `extname`. +- Add `sep` and `delimiter` constants. +- Removed `resolvePath` API, use `resolve` instead. diff --git a/core/tauri/Cargo.toml b/core/tauri/Cargo.toml index a9e37e397..bf424a8f1 100644 --- a/core/tauri/Cargo.toml +++ b/core/tauri/Cargo.toml @@ -100,7 +100,8 @@ api-all = [ "shell-all", "os-all", "dialog-all", - "updater" + "updater", + "path-all" ] updater = [ "minisign-verify", "base64" ] menu = [ "tauri-runtime/menu", "tauri-runtime-wry/menu" ] @@ -117,7 +118,7 @@ fs-create-dir = [ ] fs-remove-dir = [ ] fs-remove-file = [ ] fs-rename-file = [ ] -fs-path = [ ] +path-all = [ ] window-all = [ ] window-create = [ ] shell-all = [ "shell-open", "shell-execute" ] diff --git a/core/tauri/build.rs b/core/tauri/build.rs index ce53dfb88..c95793273 100644 --- a/core/tauri/build.rs +++ b/core/tauri/build.rs @@ -23,7 +23,6 @@ fn main() { fs_remove_dir: { any(fs_all, feature = "fs-remove-dir") }, fs_remove_file: { any(fs_all, feature = "fs-remove-file") }, fs_rename_file: { any(fs_all, feature = "fs-rename-file") }, - fs_path: { any(fs_all, feature = "fs-path") }, // window window_all: { any(api_all, feature = "window-all") }, @@ -54,5 +53,8 @@ fn main() { // os os_all: { any(api_all, feature = "os-all") }, + + // path + path_all: { any(api_all, feature = "path-all") }, } } diff --git a/core/tauri/scripts/bundle.js b/core/tauri/scripts/bundle.js index 3d024ea65..6f9ca069f 100644 --- a/core/tauri/scripts/bundle.js +++ b/core/tauri/scripts/bundle.js @@ -1 +1 @@ -function _inherits(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&_setPrototypeOf(e,t)}function _setPrototypeOf(e,t){return(_setPrototypeOf=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function _createSuper(e){var t=_isNativeReflectConstruct();return function(){var r,n=_getPrototypeOf(e);if(t){var a=_getPrototypeOf(this).constructor;r=Reflect.construct(n,arguments,a)}else r=n.apply(this,arguments);return _possibleConstructorReturn(this,r)}}function _possibleConstructorReturn(e,t){return!t||"object"!==_typeof(t)&&"function"!=typeof t?_assertThisInitialized(e):t}function _assertThisInitialized(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function _isNativeReflectConstruct(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}function _getPrototypeOf(e){return(_getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function _createForOfIteratorHelper(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!r){if(Array.isArray(e)||(r=_unsupportedIterableToArray(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var n=0,a=function(){};return{s:a,n:function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}},e:function(e){throw e},f:a}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o,i=!0,u=!1;return{s:function(){r=r.call(e)},n:function(){var e=r.next();return i=e.done,e},e:function(e){u=!0,o=e},f:function(){try{i||null==r.return||r.return()}finally{if(u)throw o}}}}function _unsupportedIterableToArray(e,t){if(e){if("string"==typeof e)return _arrayLikeToArray(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?_arrayLikeToArray(e,t):void 0}}function _arrayLikeToArray(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r=0;--o){var i=this.tryEntries[o],u=i.completion;if("root"===i.tryLoc)return a("end");if(i.tryLoc<=this.prev){var s=n.call(i,"catchLoc"),c=n.call(i,"finallyLoc");if(s&&c){if(this.prev=0;--r){var a=this.tryEntries[r];if(a.tryLoc<=this.prev&&n.call(a,"finallyLoc")&&this.prev=0;--t){var r=this.tryEntries[t];if(r.finallyLoc===e)return this.complete(r.completion,r.afterLoc),M(r),d}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.tryLoc===e){var n=r.completion;if("throw"===n.type){var a=n.arg;M(r)}return a}}throw new Error("illegal catch attempt")},delegateYield:function(e,r,n){return this.delegate={iterator:O(e),resultName:r,nextLoc:n},"next"===this.method&&(this.arg=t),d}},e}("object"===("undefined"==typeof module?"undefined":_typeof(module))?module.exports:{});try{regeneratorRuntime=t}catch(e){Function("r","regeneratorRuntime = r")(t)}function r(e){for(var t=void 0,r=e[0],n=1;n1&&void 0!==arguments[1]&&arguments[1],a=n();return Object.defineProperty(window,a,{value:function(n){return t&&Reflect.deleteProperty(window,a),r([e,"optionalCall",function(e){return e(n)}])},writable:!1,configurable:!0}),a}function o(e){return i.apply(this,arguments)}function i(){return(i=_asyncToGenerator(regeneratorRuntime.mark((function e(t){var r,n=arguments;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=n.length>1&&void 0!==n[1]?n[1]:{},e.abrupt("return",new Promise((function(e,n){var o=a((function(t){e(t),Reflect.deleteProperty(window,i)}),!0),i=a((function(e){n(e),Reflect.deleteProperty(window,o)}),!0);window.rpc.notify(t,_objectSpread({__invokeKey:__TAURI_INVOKE_KEY__,callback:o,error:i},r))})));case 2:case"end":return e.stop()}}),e)})))).apply(this,arguments)}var u=Object.freeze({__proto__:null,transformCallback:a,invoke:o,convertFileSrc:function(e){return navigator.userAgent.includes("Windows")?"https://custom.protocol.asset_".concat(e):"asset://".concat(e)}});function s(e){return c.apply(this,arguments)}function c(){return(c=_asyncToGenerator(regeneratorRuntime.mark((function e(t){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",o("tauri",t));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function p(){return(p=_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"App",message:{cmd:"getAppVersion"}}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function l(){return(l=_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"App",message:{cmd:"getAppName"}}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function f(){return(f=_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"App",message:{cmd:"getTauriVersion"}}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}var h=Object.freeze({__proto__:null,getName:function(){return l.apply(this,arguments)},getVersion:function(){return p.apply(this,arguments)},getTauriVersion:function(){return f.apply(this,arguments)}});function m(){return(m=_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"Cli",message:{cmd:"cliMatches"}}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}var d=Object.freeze({__proto__:null,getMatches:function(){return m.apply(this,arguments)}});function y(){return(y=_asyncToGenerator(regeneratorRuntime.mark((function e(t){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"Clipboard",message:{cmd:"writeText",data:t}}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function g(){return(g=_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"Clipboard",message:{cmd:"readText"}}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}var _=Object.freeze({__proto__:null,writeText:function(e){return y.apply(this,arguments)},readText:function(){return g.apply(this,arguments)}});function v(){return(v=_asyncToGenerator(regeneratorRuntime.mark((function e(){var t,r=arguments;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return"object"===_typeof(t=r.length>0&&void 0!==r[0]?r[0]:{})&&Object.freeze(t),e.abrupt("return",s({__tauriModule:"Dialog",message:{cmd:"openDialog",options:t}}));case 3:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function w(){return(w=_asyncToGenerator(regeneratorRuntime.mark((function e(){var t,r=arguments;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return"object"===_typeof(t=r.length>0&&void 0!==r[0]?r[0]:{})&&Object.freeze(t),e.abrupt("return",s({__tauriModule:"Dialog",message:{cmd:"saveDialog",options:t}}));case 3:case"end":return e.stop()}}),e)})))).apply(this,arguments)}var b=Object.freeze({__proto__:null,open:function(){return v.apply(this,arguments)},save:function(){return w.apply(this,arguments)}});function R(e,t,r){return k.apply(this,arguments)}function k(){return(k=_asyncToGenerator(regeneratorRuntime.mark((function e(t,r,n){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,s({__tauriModule:"Event",message:{cmd:"emit",event:t,windowLabel:r,payload:n}});case 2:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function x(e){return T.apply(this,arguments)}function T(){return(T=_asyncToGenerator(regeneratorRuntime.mark((function e(t){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"Event",message:{cmd:"unlisten",eventId:t}}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function G(e,t){return M.apply(this,arguments)}function M(){return(M=_asyncToGenerator(regeneratorRuntime.mark((function e(t,r){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"Event",message:{cmd:"listen",event:t,handler:a(r)}}).then((function(e){return _asyncToGenerator(regeneratorRuntime.mark((function t(){return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",x(e));case 1:case"end":return t.stop()}}),t)})))})));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function P(e,t){return O.apply(this,arguments)}function O(){return(O=_asyncToGenerator(regeneratorRuntime.mark((function e(t,r){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",G(t,(function(e){r(e),x(e.id).catch((function(){}))})));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function C(e,t){return j.apply(this,arguments)}function j(){return(j=_asyncToGenerator(regeneratorRuntime.mark((function e(t,r){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",R(t,void 0,r));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}var S,F=Object.freeze({__proto__:null,listen:G,once:P,emit:C});function z(){return(z=_asyncToGenerator(regeneratorRuntime.mark((function e(t){var r,n=arguments;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=n.length>1&&void 0!==n[1]?n[1]:{},e.abrupt("return",s({__tauriModule:"Fs",message:{cmd:"readTextFile",path:t,options:r}}));case 2:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function A(){return(A=_asyncToGenerator(regeneratorRuntime.mark((function e(t){var r,n=arguments;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=n.length>1&&void 0!==n[1]?n[1]:{},e.abrupt("return",s({__tauriModule:"Fs",message:{cmd:"readBinaryFile",path:t,options:r}}));case 2:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function D(){return(D=_asyncToGenerator(regeneratorRuntime.mark((function e(t){var r,n=arguments;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return"object"===_typeof(r=n.length>1&&void 0!==n[1]?n[1]:{})&&Object.freeze(r),"object"===_typeof(t)&&Object.freeze(t),e.abrupt("return",s({__tauriModule:"Fs",message:{cmd:"writeFile",path:t.path,contents:t.contents,options:r}}));case 4:case"end":return e.stop()}}),e)})))).apply(this,arguments)}!function(e){e[e.Audio=1]="Audio";e[e.Cache=2]="Cache";e[e.Config=3]="Config";e[e.Data=4]="Data";e[e.LocalData=5]="LocalData";e[e.Desktop=6]="Desktop";e[e.Document=7]="Document";e[e.Download=8]="Download";e[e.Executable=9]="Executable";e[e.Font=10]="Font";e[e.Home=11]="Home";e[e.Picture=12]="Picture";e[e.Public=13]="Public";e[e.Runtime=14]="Runtime";e[e.Template=15]="Template";e[e.Video=16]="Video";e[e.Resource=17]="Resource";e[e.App=18]="App";e[e.Current=19]="Current"}(S||(S={}));var L=65536;function E(e){var t=function(e){if(e.length1&&void 0!==n[1]?n[1]:{})&&Object.freeze(r),"object"===_typeof(t)&&Object.freeze(t),e.abrupt("return",s({__tauriModule:"Fs",message:{cmd:"writeBinaryFile",path:t.path,contents:E(t.contents),options:r}}));case 4:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function I(){return(I=_asyncToGenerator(regeneratorRuntime.mark((function e(t){var r,n=arguments;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=n.length>1&&void 0!==n[1]?n[1]:{},e.abrupt("return",s({__tauriModule:"Fs",message:{cmd:"readDir",path:t,options:r}}));case 2:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function N(){return(N=_asyncToGenerator(regeneratorRuntime.mark((function e(t){var r,n=arguments;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=n.length>1&&void 0!==n[1]?n[1]:{},e.abrupt("return",s({__tauriModule:"Fs",message:{cmd:"createDir",path:t,options:r}}));case 2:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function U(){return(U=_asyncToGenerator(regeneratorRuntime.mark((function e(t){var r,n=arguments;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=n.length>1&&void 0!==n[1]?n[1]:{},e.abrupt("return",s({__tauriModule:"Fs",message:{cmd:"removeDir",path:t,options:r}}));case 2:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function B(){return(B=_asyncToGenerator(regeneratorRuntime.mark((function e(t,r){var n,a=arguments;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=a.length>2&&void 0!==a[2]?a[2]:{},e.abrupt("return",s({__tauriModule:"Fs",message:{cmd:"copyFile",source:t,destination:r,options:n}}));case 2:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function V(){return(V=_asyncToGenerator(regeneratorRuntime.mark((function e(t){var r,n=arguments;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=n.length>1&&void 0!==n[1]?n[1]:{},e.abrupt("return",s({__tauriModule:"Fs",message:{cmd:"removeFile",path:t,options:r}}));case 2:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function q(){return(q=_asyncToGenerator(regeneratorRuntime.mark((function e(t,r){var n,a=arguments;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=a.length>2&&void 0!==a[2]?a[2]:{},e.abrupt("return",s({__tauriModule:"Fs",message:{cmd:"renameFile",oldPath:t,newPath:r,options:n}}));case 2:case"end":return e.stop()}}),e)})))).apply(this,arguments)}var H=Object.freeze({__proto__:null,get BaseDirectory(){return S},get Dir(){return S},readTextFile:function(e){return z.apply(this,arguments)},readBinaryFile:function(e){return A.apply(this,arguments)},writeFile:function(e){return D.apply(this,arguments)},writeBinaryFile:function(e){return W.apply(this,arguments)},readDir:function(e){return I.apply(this,arguments)},createDir:function(e){return N.apply(this,arguments)},removeDir:function(e){return U.apply(this,arguments)},copyFile:function(e,t){return B.apply(this,arguments)},removeFile:function(e){return V.apply(this,arguments)},renameFile:function(e,t){return q.apply(this,arguments)}});function J(){return(J=_asyncToGenerator(regeneratorRuntime.mark((function e(t,r){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"GlobalShortcut",message:{cmd:"register",shortcut:t,handler:a(r)}}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function K(){return(K=_asyncToGenerator(regeneratorRuntime.mark((function e(t,r){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"GlobalShortcut",message:{cmd:"registerAll",shortcuts:t,handler:a(r)}}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function Y(){return(Y=_asyncToGenerator(regeneratorRuntime.mark((function e(t){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"GlobalShortcut",message:{cmd:"isRegistered",shortcut:t}}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function $(){return($=_asyncToGenerator(regeneratorRuntime.mark((function e(t){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"GlobalShortcut",message:{cmd:"unregister",shortcut:t}}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function Q(){return(Q=_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"GlobalShortcut",message:{cmd:"unregisterAll"}}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}var X,Z=Object.freeze({__proto__:null,register:function(e,t){return J.apply(this,arguments)},registerAll:function(e,t){return K.apply(this,arguments)},isRegistered:function(e){return Y.apply(this,arguments)},unregister:function(e){return $.apply(this,arguments)},unregisterAll:function(){return Q.apply(this,arguments)}});function ee(e,t){return null!=e?e:t()}function te(e){for(var t=void 0,r=e[0],n=1;n=200&&this.status<300,this.headers=t.headers,this.data=t.data},ae=function(){function e(t){_classCallCheck(this,e),this.id=t}var t,r,n,a,o,i,u;return _createClass(e,[{key:"drop",value:(u=_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"Http",message:{cmd:"dropClient",client:this.id}}));case 1:case"end":return e.stop()}}),e,this)}))),function(){return u.apply(this,arguments)})},{key:"request",value:(i=_asyncToGenerator(regeneratorRuntime.mark((function e(t){var r;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return(r=!t.responseType||t.responseType===X.JSON)&&(t.responseType=X.Text),e.abrupt("return",s({__tauriModule:"Http",message:{cmd:"httpRequest",client:this.id,options:t}}).then((function(e){var t=new ne(e);if(r){try{t.data=JSON.parse(t.data)}catch(e){if(t.ok)throw Error("Failed to parse response `".concat(t.data,"` as JSON: ").concat(e,";\n try setting the `responseType` option to `ResponseType.Text` or `ResponseType.Binary` if the API does not return a JSON response."))}return t}return t})));case 3:case"end":return e.stop()}}),e,this)}))),function(e){return i.apply(this,arguments)})},{key:"get",value:(o=_asyncToGenerator(regeneratorRuntime.mark((function e(t,r){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.request(_objectSpread({method:"GET",url:t},r)));case 1:case"end":return e.stop()}}),e,this)}))),function(e,t){return o.apply(this,arguments)})},{key:"post",value:(a=_asyncToGenerator(regeneratorRuntime.mark((function e(t,r,n){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.request(_objectSpread({method:"POST",url:t,body:r},n)));case 1:case"end":return e.stop()}}),e,this)}))),function(e,t,r){return a.apply(this,arguments)})},{key:"put",value:(n=_asyncToGenerator(regeneratorRuntime.mark((function e(t,r,n){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.request(_objectSpread({method:"PUT",url:t,body:r},n)));case 1:case"end":return e.stop()}}),e,this)}))),function(e,t,r){return n.apply(this,arguments)})},{key:"patch",value:(r=_asyncToGenerator(regeneratorRuntime.mark((function e(t,r){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.request(_objectSpread({method:"PATCH",url:t},r)));case 1:case"end":return e.stop()}}),e,this)}))),function(e,t){return r.apply(this,arguments)})},{key:"delete",value:(t=_asyncToGenerator(regeneratorRuntime.mark((function e(t,r){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.request(_objectSpread({method:"DELETE",url:t},r)));case 1:case"end":return e.stop()}}),e,this)}))),function(e,r){return t.apply(this,arguments)})}]),e}();function oe(e){return ie.apply(this,arguments)}function ie(){return(ie=_asyncToGenerator(regeneratorRuntime.mark((function e(t){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"Http",message:{cmd:"createClient",options:t}}).then((function(e){return new ae(e)})));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}var ue=null;function se(){return(se=_asyncToGenerator(regeneratorRuntime.mark((function e(t,r){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(null!==ue){e.next=4;break}return e.next=3,oe();case 3:ue=e.sent;case 4:return e.abrupt("return",ue.request(_objectSpread({url:t,method:ee(te([r,"optionalAccess",function(e){return e.method}]),(function(){return"GET"}))},r)));case 5:case"end":return e.stop()}}),e)})))).apply(this,arguments)}var ce=Object.freeze({__proto__:null,getClient:oe,fetch:function(e,t){return se.apply(this,arguments)},Body:re,Client:ae,Response:ne,get ResponseType(){return X}});function pe(){return(pe=_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if("default"===window.Notification.permission){e.next=2;break}return e.abrupt("return",Promise.resolve("granted"===window.Notification.permission));case 2:return e.abrupt("return",s({__tauriModule:"Notification",message:{cmd:"isNotificationPermissionGranted"}}));case 3:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function le(){return(le=_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",window.Notification.requestPermission());case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}var fe=Object.freeze({__proto__:null,sendNotification:function(e){"string"==typeof e?new window.Notification(e):new window.Notification(e.title,e)},requestPermission:function(){return le.apply(this,arguments)},isPermissionGranted:function(){return pe.apply(this,arguments)}});function he(){return(he=_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"Fs",message:{cmd:"resolvePath",path:"",directory:S.App}}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function me(){return(me=_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"Fs",message:{cmd:"resolvePath",path:"",directory:S.Audio}}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function de(){return(de=_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"Fs",message:{cmd:"resolvePath",path:"",directory:S.Cache}}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function ye(){return(ye=_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"Fs",message:{cmd:"resolvePath",path:"",directory:S.Config}}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function ge(){return(ge=_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"Fs",message:{cmd:"resolvePath",path:"",directory:S.Data}}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function _e(){return(_e=_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"Fs",message:{cmd:"resolvePath",path:"",directory:S.Desktop}}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function ve(){return(ve=_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"Fs",message:{cmd:"resolvePath",path:"",directory:S.Document}}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function we(){return(we=_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"Fs",message:{cmd:"resolvePath",path:"",directory:S.Download}}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function be(){return(be=_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"Fs",message:{cmd:"resolvePath",path:"",directory:S.Executable}}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function Re(){return(Re=_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"Fs",message:{cmd:"resolvePath",path:"",directory:S.Font}}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function ke(){return(ke=_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"Fs",message:{cmd:"resolvePath",path:"",directory:S.Home}}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function xe(){return(xe=_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"Fs",message:{cmd:"resolvePath",path:"",directory:S.LocalData}}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function Te(){return(Te=_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"Fs",message:{cmd:"resolvePath",path:"",directory:S.Picture}}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function Ge(){return(Ge=_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"Fs",message:{cmd:"resolvePath",path:"",directory:S.Public}}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function Me(){return(Me=_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"Fs",message:{cmd:"resolvePath",path:"",directory:S.Resource}}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function Pe(){return(Pe=_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"Fs",message:{cmd:"resolvePath",path:"",directory:S.Runtime}}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function Oe(){return(Oe=_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"Fs",message:{cmd:"resolvePath",path:"",directory:S.Template}}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function Ce(){return(Ce=_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"Fs",message:{cmd:"resolvePath",path:"",directory:S.Video}}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function je(){return(je=_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"Fs",message:{cmd:"resolvePath",path:"",directory:S.Current}}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function Se(){return(Se=_asyncToGenerator(regeneratorRuntime.mark((function e(t,r){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"Fs",message:{cmd:"resolvePath",path:t,directory:r}}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}var Fe=Object.freeze({__proto__:null,appDir:function(){return he.apply(this,arguments)},audioDir:function(){return me.apply(this,arguments)},cacheDir:function(){return de.apply(this,arguments)},configDir:function(){return ye.apply(this,arguments)},dataDir:function(){return ge.apply(this,arguments)},desktopDir:function(){return _e.apply(this,arguments)},documentDir:function(){return ve.apply(this,arguments)},downloadDir:function(){return we.apply(this,arguments)},executableDir:function(){return be.apply(this,arguments)},fontDir:function(){return Re.apply(this,arguments)},homeDir:function(){return ke.apply(this,arguments)},localDataDir:function(){return xe.apply(this,arguments)},pictureDir:function(){return Te.apply(this,arguments)},publicDir:function(){return Ge.apply(this,arguments)},resourceDir:function(){return Me.apply(this,arguments)},runtimeDir:function(){return Pe.apply(this,arguments)},templateDir:function(){return Oe.apply(this,arguments)},videoDir:function(){return Ce.apply(this,arguments)},currentDir:function(){return je.apply(this,arguments)},resolvePath:function(e,t){return Se.apply(this,arguments)},get BaseDirectory(){return S}});function ze(){return(ze=_asyncToGenerator(regeneratorRuntime.mark((function e(){var t,r=arguments;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return t=r.length>0&&void 0!==r[0]?r[0]:0,e.abrupt("return",s({__tauriModule:"Process",message:{cmd:"exit",exitCode:t}}));case 2:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function Ae(){return(Ae=_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"Process",message:{cmd:"relaunch"}}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}var De=Object.freeze({__proto__:null,exit:function(){return ze.apply(this,arguments)},relaunch:function(){return Ae.apply(this,arguments)}});function Le(e,t){return null!=e?e:t()}function Ee(e,t,r,n){return We.apply(this,arguments)}function We(){return(We=_asyncToGenerator(regeneratorRuntime.mark((function e(t,r,n,o){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return"object"===_typeof(n)&&Object.freeze(n),e.abrupt("return",s({__tauriModule:"Shell",message:{cmd:"execute",program:r,args:"string"==typeof n?[n]:n,options:o,onEventFn:a(t)}}));case 2:case"end":return e.stop()}}),e)})))).apply(this,arguments)}var Ie=function(){function e(){_classCallCheck(this,e),e.prototype.__init.call(this)}return _createClass(e,[{key:"__init",value:function(){this.eventListeners=Object.create(null)}},{key:"addEventListener",value:function(e,t){e in this.eventListeners?this.eventListeners[e].push(t):this.eventListeners[e]=[t]}},{key:"_emit",value:function(e,t){if(e in this.eventListeners){var r,n=_createForOfIteratorHelper(this.eventListeners[e]);try{for(n.s();!(r=n.n()).done;){(0,r.value)(t)}}catch(e){n.e(e)}finally{n.f()}}}},{key:"on",value:function(e,t){return this.addEventListener(e,t),this}}]),e}(),Ne=function(){function e(t){_classCallCheck(this,e),this.pid=t}var t,r;return _createClass(e,[{key:"write",value:(r=_asyncToGenerator(regeneratorRuntime.mark((function e(t){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"Shell",message:{cmd:"stdinWrite",pid:this.pid,buffer:t}}));case 1:case"end":return e.stop()}}),e,this)}))),function(e){return r.apply(this,arguments)})},{key:"kill",value:(t=_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"Shell",message:{cmd:"killChild",pid:this.pid}}));case 1:case"end":return e.stop()}}),e,this)}))),function(){return t.apply(this,arguments)})}]),e}(),Ue=function(e){_inherits(a,e);var t,r,n=_createSuper(a);function a(e){var t,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[],o=arguments.length>2?arguments[2]:void 0;return _classCallCheck(this,a),t=n.call(this),a.prototype.__init2.call(_assertThisInitialized(t)),a.prototype.__init3.call(_assertThisInitialized(t)),t.program=e,t.args="string"==typeof r?[r]:r,t.options=Le(o,(function(){return{}})),t}return _createClass(a,[{key:"__init2",value:function(){this.stdout=new Ie}},{key:"__init3",value:function(){this.stderr=new Ie}},{key:"spawn",value:(r=_asyncToGenerator(regeneratorRuntime.mark((function e(){var t=this;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",Ee((function(e){switch(e.event){case"Error":t._emit("error",e.payload);break;case"Terminated":t._emit("close",e.payload);break;case"Stdout":t.stdout._emit("data",e.payload);break;case"Stderr":t.stderr._emit("data",e.payload)}}),this.program,this.args,this.options).then((function(e){return new Ne(e)})));case 1:case"end":return e.stop()}}),e,this)}))),function(){return r.apply(this,arguments)})},{key:"execute",value:(t=_asyncToGenerator(regeneratorRuntime.mark((function e(){var t=this;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",new Promise((function(e,r){t.on("error",r);var n=[],a=[];t.stdout.on("data",(function(e){n.push(e)})),t.stderr.on("data",(function(e){a.push(e)})),t.on("close",(function(t){e({code:t.code,signal:t.signal,stdout:n.join("\n"),stderr:a.join("\n")})})),t.spawn().catch(r)})));case 1:case"end":return e.stop()}}),e)}))),function(){return t.apply(this,arguments)})}],[{key:"sidecar",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[],r=arguments.length>2?arguments[2]:void 0,n=new a(e,t,r);return n.options.sidecar=!0,n}}]),a}(Ie);function Be(){return(Be=_asyncToGenerator(regeneratorRuntime.mark((function e(t,r){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"Shell",message:{cmd:"open",path:t,with:r}}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}var Ve=Object.freeze({__proto__:null,Command:Ue,Child:Ne,open:function(e,t){return Be.apply(this,arguments)}});function qe(e){for(var t=void 0,r=e[0],n=1;n1&&void 0!==arguments[1]?arguments[1]:{};return _classCallCheck(this,r),n=t.call(this,e),Ye([a,"optionalAccess",function(e){return e.skip}])||s({__tauriModule:"Window",message:{cmd:"createWebview",data:{options:_objectSpread({label:e},a)}}}).then(_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",n.emit("tauri://created"));case 1:case"end":return e.stop()}}),e)})))).catch(function(){var e=_asyncToGenerator(regeneratorRuntime.mark((function e(t){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",n.emit("tauri://error",t));case 1:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}()),n}return _createClass(r,null,[{key:"getByLabel",value:function(e){return tt().some((function(t){return t.label===e}))?new r(e,{skip:!0}):null}}]),r}(at),it=new ot(null,{skip:!0});function ut(){return(ut=_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"Window",message:{cmd:"manage",data:{cmd:{type:"currentMonitor"}}}}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function st(){return(st=_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"Window",message:{cmd:"manage",data:{cmd:{type:"primaryMonitor"}}}}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function ct(){return(ct=_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"Window",message:{cmd:"manage",data:{cmd:{type:"availableMonitors"}}}}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}var pt=Object.freeze({__proto__:null,WebviewWindow:ot,WebviewWindowHandle:nt,WindowManager:at,getCurrent:function(){return new ot(window.__TAURI__.__currentWindow.label,{skip:!0})},getAll:tt,appWindow:it,LogicalSize:Qe,PhysicalSize:Xe,LogicalPosition:Ze,PhysicalPosition:et,get UserAttentionType(){return $e},currentMonitor:function(){return ut.apply(this,arguments)},primaryMonitor:function(){return st.apply(this,arguments)},availableMonitors:function(){return ct.apply(this,arguments)}});var lt=navigator.appVersion.includes("Win")?"\r\n":"\n";function ft(){return(ft=_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"Os",message:{cmd:"platform"}}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function ht(){return(ht=_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"Os",message:{cmd:"version"}}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function mt(){return(mt=_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"Os",message:{cmd:"type"}}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function dt(){return(dt=_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"Os",message:{cmd:"arch"}}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function yt(){return(yt=_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"Os",message:{cmd:"tempdir"}}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}var gt=Object.freeze({__proto__:null,EOL:lt,platform:function(){return ft.apply(this,arguments)},version:function(){return ht.apply(this,arguments)},type:function(){return mt.apply(this,arguments)},arch:function(){return dt.apply(this,arguments)},tempdir:function(){return yt.apply(this,arguments)}}),_t=o;e.app=h,e.cli=d,e.clipboard=_,e.dialog=b,e.event=F,e.fs=H,e.globalShortcut=Z,e.http=ce,e.invoke=_t,e.notification=fe,e.os=gt,e.path=Fe,e.process=De,e.shell=Ve,e.tauri=u,e.updater=Ke,e.window=pt,Object.defineProperty(e,"__esModule",{value:!0})})); +function _inherits(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&_setPrototypeOf(e,t)}function _setPrototypeOf(e,t){return(_setPrototypeOf=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function _createSuper(e){var t=_isNativeReflectConstruct();return function(){var r,n=_getPrototypeOf(e);if(t){var a=_getPrototypeOf(this).constructor;r=Reflect.construct(n,arguments,a)}else r=n.apply(this,arguments);return _possibleConstructorReturn(this,r)}}function _possibleConstructorReturn(e,t){return!t||"object"!==_typeof(t)&&"function"!=typeof t?_assertThisInitialized(e):t}function _assertThisInitialized(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function _isNativeReflectConstruct(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}function _getPrototypeOf(e){return(_getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function _createForOfIteratorHelper(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!r){if(Array.isArray(e)||(r=_unsupportedIterableToArray(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var n=0,a=function(){};return{s:a,n:function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}},e:function(e){throw e},f:a}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var o,i=!0,u=!1;return{s:function(){r=r.call(e)},n:function(){var e=r.next();return i=e.done,e},e:function(e){u=!0,o=e},f:function(){try{i||null==r.return||r.return()}finally{if(u)throw o}}}}function _unsupportedIterableToArray(e,t){if(e){if("string"==typeof e)return _arrayLikeToArray(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?_arrayLikeToArray(e,t):void 0}}function _arrayLikeToArray(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r=0;--o){var i=this.tryEntries[o],u=i.completion;if("root"===i.tryLoc)return a("end");if(i.tryLoc<=this.prev){var s=n.call(i,"catchLoc"),c=n.call(i,"finallyLoc");if(s&&c){if(this.prev=0;--r){var a=this.tryEntries[r];if(a.tryLoc<=this.prev&&n.call(a,"finallyLoc")&&this.prev=0;--t){var r=this.tryEntries[t];if(r.finallyLoc===e)return this.complete(r.completion,r.afterLoc),P(r),d}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.tryLoc===e){var n=r.completion;if("throw"===n.type){var a=n.arg;P(r)}return a}}throw new Error("illegal catch attempt")},delegateYield:function(e,r,n){return this.delegate={iterator:O(e),resultName:r,nextLoc:n},"next"===this.method&&(this.arg=t),d}},e}("object"===("undefined"==typeof module?"undefined":_typeof(module))?module.exports:{});try{regeneratorRuntime=t}catch(e){Function("r","regeneratorRuntime = r")(t)}function r(e){for(var t=void 0,r=e[0],n=1;n1&&void 0!==arguments[1]&&arguments[1],a=n();return Object.defineProperty(window,a,{value:function(n){return t&&Reflect.deleteProperty(window,a),r([e,"optionalCall",function(e){return e(n)}])},writable:!1,configurable:!0}),a}function o(e){return i.apply(this,arguments)}function i(){return(i=_asyncToGenerator(regeneratorRuntime.mark((function e(t){var r,n=arguments;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=n.length>1&&void 0!==n[1]?n[1]:{},e.abrupt("return",new Promise((function(e,n){var o=a((function(t){e(t),Reflect.deleteProperty(window,i)}),!0),i=a((function(e){n(e),Reflect.deleteProperty(window,o)}),!0);window.rpc.notify(t,_objectSpread({__invokeKey:__TAURI_INVOKE_KEY__,callback:o,error:i},r))})));case 2:case"end":return e.stop()}}),e)})))).apply(this,arguments)}var u=Object.freeze({__proto__:null,transformCallback:a,invoke:o,convertFileSrc:function(e){return navigator.userAgent.includes("Windows")?"https://custom.protocol.asset_".concat(e):"asset://".concat(e)}});function s(e){return c.apply(this,arguments)}function c(){return(c=_asyncToGenerator(regeneratorRuntime.mark((function e(t){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",o("tauri",t));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function p(){return(p=_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"App",message:{cmd:"getAppVersion"}}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function l(){return(l=_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"App",message:{cmd:"getAppName"}}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function f(){return(f=_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"App",message:{cmd:"getTauriVersion"}}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}var h=Object.freeze({__proto__:null,getName:function(){return l.apply(this,arguments)},getVersion:function(){return p.apply(this,arguments)},getTauriVersion:function(){return f.apply(this,arguments)}});function m(){return(m=_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"Cli",message:{cmd:"cliMatches"}}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}var d=Object.freeze({__proto__:null,getMatches:function(){return m.apply(this,arguments)}});function y(){return(y=_asyncToGenerator(regeneratorRuntime.mark((function e(t){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"Clipboard",message:{cmd:"writeText",data:t}}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function g(){return(g=_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"Clipboard",message:{cmd:"readText"}}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}var _=Object.freeze({__proto__:null,writeText:function(e){return y.apply(this,arguments)},readText:function(){return g.apply(this,arguments)}});function v(){return(v=_asyncToGenerator(regeneratorRuntime.mark((function e(){var t,r=arguments;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return"object"===_typeof(t=r.length>0&&void 0!==r[0]?r[0]:{})&&Object.freeze(t),e.abrupt("return",s({__tauriModule:"Dialog",message:{cmd:"openDialog",options:t}}));case 3:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function w(){return(w=_asyncToGenerator(regeneratorRuntime.mark((function e(){var t,r=arguments;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return"object"===_typeof(t=r.length>0&&void 0!==r[0]?r[0]:{})&&Object.freeze(t),e.abrupt("return",s({__tauriModule:"Dialog",message:{cmd:"saveDialog",options:t}}));case 3:case"end":return e.stop()}}),e)})))).apply(this,arguments)}var b=Object.freeze({__proto__:null,open:function(){return v.apply(this,arguments)},save:function(){return w.apply(this,arguments)}});function R(e,t,r){return k.apply(this,arguments)}function k(){return(k=_asyncToGenerator(regeneratorRuntime.mark((function e(t,r,n){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,s({__tauriModule:"Event",message:{cmd:"emit",event:t,windowLabel:r,payload:n}});case 2:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function x(e){return T.apply(this,arguments)}function T(){return(T=_asyncToGenerator(regeneratorRuntime.mark((function e(t){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"Event",message:{cmd:"unlisten",eventId:t}}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function G(e,t){return P.apply(this,arguments)}function P(){return(P=_asyncToGenerator(regeneratorRuntime.mark((function e(t,r){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"Event",message:{cmd:"listen",event:t,handler:a(r)}}).then((function(e){return _asyncToGenerator(regeneratorRuntime.mark((function t(){return regeneratorRuntime.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",x(e));case 1:case"end":return t.stop()}}),t)})))})));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function M(e,t){return O.apply(this,arguments)}function O(){return(O=_asyncToGenerator(regeneratorRuntime.mark((function e(t,r){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",G(t,(function(e){r(e),x(e.id).catch((function(){}))})));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function C(e,t){return j.apply(this,arguments)}function j(){return(j=_asyncToGenerator(regeneratorRuntime.mark((function e(t,r){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",R(t,void 0,r));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}var S,A=Object.freeze({__proto__:null,listen:G,once:M,emit:C});function z(){return(z=_asyncToGenerator(regeneratorRuntime.mark((function e(t){var r,n=arguments;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=n.length>1&&void 0!==n[1]?n[1]:{},e.abrupt("return",s({__tauriModule:"Fs",message:{cmd:"readTextFile",path:t,options:r}}));case 2:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function D(){return(D=_asyncToGenerator(regeneratorRuntime.mark((function e(t){var r,n=arguments;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=n.length>1&&void 0!==n[1]?n[1]:{},e.abrupt("return",s({__tauriModule:"Fs",message:{cmd:"readBinaryFile",path:t,options:r}}));case 2:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function L(){return(L=_asyncToGenerator(regeneratorRuntime.mark((function e(t){var r,n=arguments;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return"object"===_typeof(r=n.length>1&&void 0!==n[1]?n[1]:{})&&Object.freeze(r),"object"===_typeof(t)&&Object.freeze(t),e.abrupt("return",s({__tauriModule:"Fs",message:{cmd:"writeFile",path:t.path,contents:t.contents,options:r}}));case 4:case"end":return e.stop()}}),e)})))).apply(this,arguments)}!function(e){e[e.Audio=1]="Audio";e[e.Cache=2]="Cache";e[e.Config=3]="Config";e[e.Data=4]="Data";e[e.LocalData=5]="LocalData";e[e.Desktop=6]="Desktop";e[e.Document=7]="Document";e[e.Download=8]="Download";e[e.Executable=9]="Executable";e[e.Font=10]="Font";e[e.Home=11]="Home";e[e.Picture=12]="Picture";e[e.Public=13]="Public";e[e.Runtime=14]="Runtime";e[e.Template=15]="Template";e[e.Video=16]="Video";e[e.Resource=17]="Resource";e[e.App=18]="App";e[e.Current=19]="Current"}(S||(S={}));var E=65536;function F(e){var t=function(e){if(e.length1&&void 0!==n[1]?n[1]:{})&&Object.freeze(r),"object"===_typeof(t)&&Object.freeze(t),e.abrupt("return",s({__tauriModule:"Fs",message:{cmd:"writeBinaryFile",path:t.path,contents:F(t.contents),options:r}}));case 4:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function I(){return(I=_asyncToGenerator(regeneratorRuntime.mark((function e(t){var r,n=arguments;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=n.length>1&&void 0!==n[1]?n[1]:{},e.abrupt("return",s({__tauriModule:"Fs",message:{cmd:"readDir",path:t,options:r}}));case 2:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function N(){return(N=_asyncToGenerator(regeneratorRuntime.mark((function e(t){var r,n=arguments;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=n.length>1&&void 0!==n[1]?n[1]:{},e.abrupt("return",s({__tauriModule:"Fs",message:{cmd:"createDir",path:t,options:r}}));case 2:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function U(){return(U=_asyncToGenerator(regeneratorRuntime.mark((function e(t){var r,n=arguments;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=n.length>1&&void 0!==n[1]?n[1]:{},e.abrupt("return",s({__tauriModule:"Fs",message:{cmd:"removeDir",path:t,options:r}}));case 2:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function B(){return(B=_asyncToGenerator(regeneratorRuntime.mark((function e(t,r){var n,a=arguments;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=a.length>2&&void 0!==a[2]?a[2]:{},e.abrupt("return",s({__tauriModule:"Fs",message:{cmd:"copyFile",source:t,destination:r,options:n}}));case 2:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function V(){return(V=_asyncToGenerator(regeneratorRuntime.mark((function e(t){var r,n=arguments;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return r=n.length>1&&void 0!==n[1]?n[1]:{},e.abrupt("return",s({__tauriModule:"Fs",message:{cmd:"removeFile",path:t,options:r}}));case 2:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function q(){return(q=_asyncToGenerator(regeneratorRuntime.mark((function e(t,r){var n,a=arguments;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n=a.length>2&&void 0!==a[2]?a[2]:{},e.abrupt("return",s({__tauriModule:"Fs",message:{cmd:"renameFile",oldPath:t,newPath:r,options:n}}));case 2:case"end":return e.stop()}}),e)})))).apply(this,arguments)}var H=Object.freeze({__proto__:null,get BaseDirectory(){return S},get Dir(){return S},readTextFile:function(e){return z.apply(this,arguments)},readBinaryFile:function(e){return D.apply(this,arguments)},writeFile:function(e){return L.apply(this,arguments)},writeBinaryFile:function(e){return W.apply(this,arguments)},readDir:function(e){return I.apply(this,arguments)},createDir:function(e){return N.apply(this,arguments)},removeDir:function(e){return U.apply(this,arguments)},copyFile:function(e,t){return B.apply(this,arguments)},removeFile:function(e){return V.apply(this,arguments)},renameFile:function(e,t){return q.apply(this,arguments)}});function J(){return(J=_asyncToGenerator(regeneratorRuntime.mark((function e(t,r){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"GlobalShortcut",message:{cmd:"register",shortcut:t,handler:a(r)}}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function K(){return(K=_asyncToGenerator(regeneratorRuntime.mark((function e(t,r){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"GlobalShortcut",message:{cmd:"registerAll",shortcuts:t,handler:a(r)}}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function Y(){return(Y=_asyncToGenerator(regeneratorRuntime.mark((function e(t){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"GlobalShortcut",message:{cmd:"isRegistered",shortcut:t}}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function $(){return($=_asyncToGenerator(regeneratorRuntime.mark((function e(t){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"GlobalShortcut",message:{cmd:"unregister",shortcut:t}}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function Q(){return(Q=_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"GlobalShortcut",message:{cmd:"unregisterAll"}}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}var X,Z=Object.freeze({__proto__:null,register:function(e,t){return J.apply(this,arguments)},registerAll:function(e,t){return K.apply(this,arguments)},isRegistered:function(e){return Y.apply(this,arguments)},unregister:function(e){return $.apply(this,arguments)},unregisterAll:function(){return Q.apply(this,arguments)}});function ee(e,t){return null!=e?e:t()}function te(e){for(var t=void 0,r=e[0],n=1;n=200&&this.status<300,this.headers=t.headers,this.data=t.data},ae=function(){function e(t){_classCallCheck(this,e),this.id=t}var t,r,n,a,o,i,u;return _createClass(e,[{key:"drop",value:(u=_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"Http",message:{cmd:"dropClient",client:this.id}}));case 1:case"end":return e.stop()}}),e,this)}))),function(){return u.apply(this,arguments)})},{key:"request",value:(i=_asyncToGenerator(regeneratorRuntime.mark((function e(t){var r;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return(r=!t.responseType||t.responseType===X.JSON)&&(t.responseType=X.Text),e.abrupt("return",s({__tauriModule:"Http",message:{cmd:"httpRequest",client:this.id,options:t}}).then((function(e){var t=new ne(e);if(r){try{t.data=JSON.parse(t.data)}catch(e){if(t.ok)throw Error("Failed to parse response `".concat(t.data,"` as JSON: ").concat(e,";\n try setting the `responseType` option to `ResponseType.Text` or `ResponseType.Binary` if the API does not return a JSON response."))}return t}return t})));case 3:case"end":return e.stop()}}),e,this)}))),function(e){return i.apply(this,arguments)})},{key:"get",value:(o=_asyncToGenerator(regeneratorRuntime.mark((function e(t,r){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.request(_objectSpread({method:"GET",url:t},r)));case 1:case"end":return e.stop()}}),e,this)}))),function(e,t){return o.apply(this,arguments)})},{key:"post",value:(a=_asyncToGenerator(regeneratorRuntime.mark((function e(t,r,n){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.request(_objectSpread({method:"POST",url:t,body:r},n)));case 1:case"end":return e.stop()}}),e,this)}))),function(e,t,r){return a.apply(this,arguments)})},{key:"put",value:(n=_asyncToGenerator(regeneratorRuntime.mark((function e(t,r,n){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.request(_objectSpread({method:"PUT",url:t,body:r},n)));case 1:case"end":return e.stop()}}),e,this)}))),function(e,t,r){return n.apply(this,arguments)})},{key:"patch",value:(r=_asyncToGenerator(regeneratorRuntime.mark((function e(t,r){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.request(_objectSpread({method:"PATCH",url:t},r)));case 1:case"end":return e.stop()}}),e,this)}))),function(e,t){return r.apply(this,arguments)})},{key:"delete",value:(t=_asyncToGenerator(regeneratorRuntime.mark((function e(t,r){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",this.request(_objectSpread({method:"DELETE",url:t},r)));case 1:case"end":return e.stop()}}),e,this)}))),function(e,r){return t.apply(this,arguments)})}]),e}();function oe(e){return ie.apply(this,arguments)}function ie(){return(ie=_asyncToGenerator(regeneratorRuntime.mark((function e(t){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"Http",message:{cmd:"createClient",options:t}}).then((function(e){return new ae(e)})));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}var ue=null;function se(){return(se=_asyncToGenerator(regeneratorRuntime.mark((function e(t,r){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(null!==ue){e.next=4;break}return e.next=3,oe();case 3:ue=e.sent;case 4:return e.abrupt("return",ue.request(_objectSpread({url:t,method:ee(te([r,"optionalAccess",function(e){return e.method}]),(function(){return"GET"}))},r)));case 5:case"end":return e.stop()}}),e)})))).apply(this,arguments)}var ce=Object.freeze({__proto__:null,getClient:oe,fetch:function(e,t){return se.apply(this,arguments)},Body:re,Client:ae,Response:ne,get ResponseType(){return X}});function pe(){return(pe=_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if("default"===window.Notification.permission){e.next=2;break}return e.abrupt("return",Promise.resolve("granted"===window.Notification.permission));case 2:return e.abrupt("return",s({__tauriModule:"Notification",message:{cmd:"isNotificationPermissionGranted"}}));case 3:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function le(){return(le=_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",window.Notification.requestPermission());case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}var fe=Object.freeze({__proto__:null,sendNotification:function(e){"string"==typeof e?new window.Notification(e):new window.Notification(e.title,e)},requestPermission:function(){return le.apply(this,arguments)},isPermissionGranted:function(){return pe.apply(this,arguments)}});function he(){return navigator.appVersion.includes("Win")}function me(){return(me=_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"Path",message:{cmd:"resolvePath",path:"",directory:S.App}}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function de(){return(de=_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"Path",message:{cmd:"resolvePath",path:"",directory:S.Audio}}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function ye(){return(ye=_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"Path",message:{cmd:"resolvePath",path:"",directory:S.Cache}}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function ge(){return(ge=_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"Path",message:{cmd:"resolvePath",path:"",directory:S.Config}}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function _e(){return(_e=_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"Path",message:{cmd:"resolvePath",path:"",directory:S.Data}}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function ve(){return(ve=_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"Path",message:{cmd:"resolvePath",path:"",directory:S.Desktop}}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function we(){return(we=_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"Path",message:{cmd:"resolvePath",path:"",directory:S.Document}}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function be(){return(be=_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"Path",message:{cmd:"resolvePath",path:"",directory:S.Download}}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function Re(){return(Re=_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"Path",message:{cmd:"resolvePath",path:"",directory:S.Executable}}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function ke(){return(ke=_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"Path",message:{cmd:"resolvePath",path:"",directory:S.Font}}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function xe(){return(xe=_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"Path",message:{cmd:"resolvePath",path:"",directory:S.Home}}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function Te(){return(Te=_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"Path",message:{cmd:"resolvePath",path:"",directory:S.LocalData}}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function Ge(){return(Ge=_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"Path",message:{cmd:"resolvePath",path:"",directory:S.Picture}}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function Pe(){return(Pe=_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"Path",message:{cmd:"resolvePath",path:"",directory:S.Public}}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function Me(){return(Me=_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"Path",message:{cmd:"resolvePath",path:"",directory:S.Resource}}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function Oe(){return(Oe=_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"Path",message:{cmd:"resolvePath",path:"",directory:S.Runtime}}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function Ce(){return(Ce=_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"Path",message:{cmd:"resolvePath",path:"",directory:S.Template}}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function je(){return(je=_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"Path",message:{cmd:"resolvePath",path:"",directory:S.Video}}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function Se(){return(Se=_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"Path",message:{cmd:"resolvePath",path:"",directory:S.Current}}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}var Ae=he()?"\\":"/",ze=he()?";":":";function De(){return(De=_asyncToGenerator(regeneratorRuntime.mark((function e(){var t,r,n,a=arguments;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:for(t=a.length,r=new Array(t),n=0;n0&&void 0!==r[0]?r[0]:0,e.abrupt("return",s({__tauriModule:"Process",message:{cmd:"exit",exitCode:t}}));case 2:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function Ve(){return(Ve=_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"Process",message:{cmd:"relaunch"}}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}var qe=Object.freeze({__proto__:null,exit:function(){return Be.apply(this,arguments)},relaunch:function(){return Ve.apply(this,arguments)}});function He(e,t){return null!=e?e:t()}function Je(e,t,r,n){return Ke.apply(this,arguments)}function Ke(){return(Ke=_asyncToGenerator(regeneratorRuntime.mark((function e(t,r,n,o){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return"object"===_typeof(n)&&Object.freeze(n),e.abrupt("return",s({__tauriModule:"Shell",message:{cmd:"execute",program:r,args:"string"==typeof n?[n]:n,options:o,onEventFn:a(t)}}));case 2:case"end":return e.stop()}}),e)})))).apply(this,arguments)}var Ye=function(){function e(){_classCallCheck(this,e),e.prototype.__init.call(this)}return _createClass(e,[{key:"__init",value:function(){this.eventListeners=Object.create(null)}},{key:"addEventListener",value:function(e,t){e in this.eventListeners?this.eventListeners[e].push(t):this.eventListeners[e]=[t]}},{key:"_emit",value:function(e,t){if(e in this.eventListeners){var r,n=_createForOfIteratorHelper(this.eventListeners[e]);try{for(n.s();!(r=n.n()).done;){(0,r.value)(t)}}catch(e){n.e(e)}finally{n.f()}}}},{key:"on",value:function(e,t){return this.addEventListener(e,t),this}}]),e}(),$e=function(){function e(t){_classCallCheck(this,e),this.pid=t}var t,r;return _createClass(e,[{key:"write",value:(r=_asyncToGenerator(regeneratorRuntime.mark((function e(t){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"Shell",message:{cmd:"stdinWrite",pid:this.pid,buffer:t}}));case 1:case"end":return e.stop()}}),e,this)}))),function(e){return r.apply(this,arguments)})},{key:"kill",value:(t=_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"Shell",message:{cmd:"killChild",pid:this.pid}}));case 1:case"end":return e.stop()}}),e,this)}))),function(){return t.apply(this,arguments)})}]),e}(),Qe=function(e){_inherits(a,e);var t,r,n=_createSuper(a);function a(e){var t,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[],o=arguments.length>2?arguments[2]:void 0;return _classCallCheck(this,a),t=n.call(this),a.prototype.__init2.call(_assertThisInitialized(t)),a.prototype.__init3.call(_assertThisInitialized(t)),t.program=e,t.args="string"==typeof r?[r]:r,t.options=He(o,(function(){return{}})),t}return _createClass(a,[{key:"__init2",value:function(){this.stdout=new Ye}},{key:"__init3",value:function(){this.stderr=new Ye}},{key:"spawn",value:(r=_asyncToGenerator(regeneratorRuntime.mark((function e(){var t=this;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",Je((function(e){switch(e.event){case"Error":t._emit("error",e.payload);break;case"Terminated":t._emit("close",e.payload);break;case"Stdout":t.stdout._emit("data",e.payload);break;case"Stderr":t.stderr._emit("data",e.payload)}}),this.program,this.args,this.options).then((function(e){return new $e(e)})));case 1:case"end":return e.stop()}}),e,this)}))),function(){return r.apply(this,arguments)})},{key:"execute",value:(t=_asyncToGenerator(regeneratorRuntime.mark((function e(){var t=this;return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",new Promise((function(e,r){t.on("error",r);var n=[],a=[];t.stdout.on("data",(function(e){n.push(e)})),t.stderr.on("data",(function(e){a.push(e)})),t.on("close",(function(t){e({code:t.code,signal:t.signal,stdout:n.join("\n"),stderr:a.join("\n")})})),t.spawn().catch(r)})));case 1:case"end":return e.stop()}}),e)}))),function(){return t.apply(this,arguments)})}],[{key:"sidecar",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[],r=arguments.length>2?arguments[2]:void 0,n=new a(e,t,r);return n.options.sidecar=!0,n}}]),a}(Ye);function Xe(){return(Xe=_asyncToGenerator(regeneratorRuntime.mark((function e(t,r){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"Shell",message:{cmd:"open",path:t,with:r}}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}var Ze=Object.freeze({__proto__:null,Command:Qe,Child:$e,open:function(e,t){return Xe.apply(this,arguments)}});function et(e){for(var t=void 0,r=e[0],n=1;n1&&void 0!==arguments[1]?arguments[1]:{};return _classCallCheck(this,r),n=t.call(this,e),at([a,"optionalAccess",function(e){return e.skip}])||s({__tauriModule:"Window",message:{cmd:"createWebview",data:{options:_objectSpread({label:e},a)}}}).then(_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",n.emit("tauri://created"));case 1:case"end":return e.stop()}}),e)})))).catch(function(){var e=_asyncToGenerator(regeneratorRuntime.mark((function e(t){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",n.emit("tauri://error",t));case 1:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}()),n}return _createClass(r,null,[{key:"getByLabel",value:function(e){return pt().some((function(t){return t.label===e}))?new r(e,{skip:!0}):null}}]),r}(ht),dt=new mt(null,{skip:!0});function yt(){return(yt=_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"Window",message:{cmd:"manage",data:{cmd:{type:"currentMonitor"}}}}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function gt(){return(gt=_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"Window",message:{cmd:"manage",data:{cmd:{type:"primaryMonitor"}}}}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function _t(){return(_t=_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"Window",message:{cmd:"manage",data:{cmd:{type:"availableMonitors"}}}}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}var vt=Object.freeze({__proto__:null,WebviewWindow:mt,WebviewWindowHandle:ft,WindowManager:ht,getCurrent:function(){return new mt(window.__TAURI__.__currentWindow.label,{skip:!0})},getAll:pt,appWindow:dt,LogicalSize:it,PhysicalSize:ut,LogicalPosition:st,PhysicalPosition:ct,get UserAttentionType(){return ot},currentMonitor:function(){return yt.apply(this,arguments)},primaryMonitor:function(){return gt.apply(this,arguments)},availableMonitors:function(){return _t.apply(this,arguments)}}),wt=he()?"\r\n":"\n";function bt(){return(bt=_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"Os",message:{cmd:"platform"}}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function Rt(){return(Rt=_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"Os",message:{cmd:"version"}}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function kt(){return(kt=_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"Os",message:{cmd:"type"}}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function xt(){return(xt=_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"Os",message:{cmd:"arch"}}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}function Tt(){return(Tt=_asyncToGenerator(regeneratorRuntime.mark((function e(){return regeneratorRuntime.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",s({__tauriModule:"Os",message:{cmd:"tempdir"}}));case 1:case"end":return e.stop()}}),e)})))).apply(this,arguments)}var Gt=Object.freeze({__proto__:null,EOL:wt,platform:function(){return bt.apply(this,arguments)},version:function(){return Rt.apply(this,arguments)},type:function(){return kt.apply(this,arguments)},arch:function(){return xt.apply(this,arguments)},tempdir:function(){return Tt.apply(this,arguments)}}),Pt=o;e.app=h,e.cli=d,e.clipboard=_,e.dialog=b,e.event=A,e.fs=H,e.globalShortcut=Z,e.http=ce,e.invoke=Pt,e.notification=fe,e.os=Gt,e.path=Ue,e.process=qe,e.shell=Ze,e.tauri=u,e.updater=nt,e.window=vt,Object.defineProperty(e,"__esModule",{value:!0})})); diff --git a/core/tauri/src/endpoints.rs b/core/tauri/src/endpoints.rs index 5c402e58f..8ef9ea067 100644 --- a/core/tauri/src/endpoints.rs +++ b/core/tauri/src/endpoints.rs @@ -25,6 +25,7 @@ mod http; mod internal; mod notification; mod operating_system; +mod path; mod process; mod shell; mod window; @@ -49,6 +50,7 @@ enum Module { Process(process::Cmd), Fs(file_system::Cmd), Os(operating_system::Cmd), + Path(path::Cmd), Window(Box), Shell(shell::Cmd), Event(event::Cmd), @@ -84,6 +86,12 @@ impl Module { .and_then(|r| r.json) .map_err(InvokeError::from) }), + Self::Path(cmd) => resolver.respond_async(async move { + cmd + .run(config, &package_info) + .and_then(|r| r.json) + .map_err(InvokeError::from) + }), Self::Os(cmd) => resolver .respond_async(async move { cmd.run().and_then(|r| r.json).map_err(InvokeError::from) }), Self::Window(cmd) => resolver.respond_async(async move { diff --git a/core/tauri/src/endpoints/file_system.rs b/core/tauri/src/endpoints/file_system.rs index 8794ed74d..08a29a313 100644 --- a/core/tauri/src/endpoints/file_system.rs +++ b/core/tauri/src/endpoints/file_system.rs @@ -93,11 +93,6 @@ pub enum Cmd { new_path: PathBuf, options: Option, }, - /// The resolve path API - ResolvePath { - path: String, - directory: Option, - }, } impl Cmd { @@ -201,13 +196,6 @@ impl Cmd { Self::RenameFile { .. } => Err(crate::Error::ApiNotAllowlisted( "fs > renameFile".to_string(), )), - - #[cfg(fs_path)] - Self::ResolvePath { path, directory } => { - resolve_path_handler(&config, package_info, path, directory).map(Into::into) - } - #[cfg(not(fs_path))] - Self::ResolvePath { .. } => Err(crate::Error::ApiNotAllowlisted("fs > path".to_string())), } } } @@ -405,16 +393,6 @@ pub fn read_binary_file( .map_err(crate::Error::FailedToExecuteApi) } -#[cfg(fs_path)] -pub fn resolve_path_handler( - config: &Config, - package_info: &PackageInfo, - path: String, - directory: Option, -) -> crate::Result { - resolve_path(config, package_info, path, directory).map_err(Into::into) -} - // test webview functionality. #[cfg(test)] mod test { diff --git a/core/tauri/src/endpoints/path.rs b/core/tauri/src/endpoints/path.rs new file mode 100644 index 000000000..8d06b9a0d --- /dev/null +++ b/core/tauri/src/endpoints/path.rs @@ -0,0 +1,156 @@ +// Copyright 2019-2021 Tauri Programme within The Commons Conservancy +// SPDX-License-Identifier: Apache-2.0 +// SPDX-License-Identifier: MIT + +use super::InvokeResponse; +use crate::{api::path::BaseDirectory, Config, PackageInfo}; +use serde::Deserialize; +#[cfg(path_all)] +use std::path::{Path, PathBuf}; +use std::sync::Arc; +/// The API descriptor. +#[derive(Deserialize)] +#[serde(tag = "cmd", rename_all = "camelCase")] +pub enum Cmd { + ResolvePath { + path: String, + directory: Option, + }, + Resolve { + paths: Vec, + }, + Normalize { + path: String, + }, + Join { + paths: Vec, + }, + Dirname { + path: String, + }, + Extname { + path: String, + }, + Basename { + path: String, + ext: Option, + }, + IsAbsolute { + path: String, + }, +} + +impl Cmd { + #[allow(unused_variables)] + pub fn run( + self, + config: Arc, + package_info: &PackageInfo, + ) -> crate::Result { + #[cfg(path_all)] + return match self { + Cmd::ResolvePath { directory, path } => { + resolve_path_handler(&config, package_info, path, directory).map(Into::into) + } + Cmd::Resolve { paths } => resolve(paths).map(Into::into), + Cmd::Normalize { path } => normalize(path).map(Into::into), + Cmd::Join { paths } => join(paths).map(Into::into), + Cmd::Dirname { path } => dirname(path).map(Into::into), + Cmd::Extname { path } => extname(path).map(Into::into), + Cmd::Basename { path, ext } => basename(path, ext).map(Into::into), + Cmd::IsAbsolute { path } => Ok(Path::new(&path).is_absolute()).map(Into::into), + }; + #[cfg(not(path_all))] + Err(crate::Error::ApiNotAllowlisted("path".into())) + } +} + +#[cfg(path_all)] +pub fn resolve_path_handler( + config: &Config, + package_info: &PackageInfo, + path: String, + directory: Option, +) -> crate::Result { + crate::api::path::resolve_path(config, package_info, path, directory).map_err(Into::into) +} + +#[cfg(path_all)] +fn resolve(paths: Vec) -> crate::Result { + // start with the current directory + let mut resolved_path = PathBuf::new().join("."); + + for path in paths { + let path_buf = PathBuf::from(path); + + // if we encounter an absolute path, we use it as the starting path for next iteration + if path_buf.is_absolute() { + resolved_path = path_buf; + } else { + resolved_path = resolved_path.join(&path_buf); + } + } + + normalize(resolved_path.to_string_lossy().to_string()) +} + +#[cfg(path_all)] +fn normalize(path: String) -> crate::Result { + let path = std::fs::canonicalize(path)?; + let path = path.to_string_lossy().to_string(); + + // remove `\\\\?\\` on windows, UNC path + #[cfg(target_os = "windows")] + let path = path.replace("\\\\?\\", ""); + + Ok(path) +} + +#[cfg(path_all)] +fn join(paths: Vec) -> crate::Result { + let mut joined_path = PathBuf::new(); + for path in paths { + joined_path = joined_path.join(path); + } + normalize(joined_path.to_string_lossy().to_string()) +} + +#[cfg(path_all)] +fn dirname(path: String) -> crate::Result { + match Path::new(&path).parent() { + Some(path) => Ok(path.to_string_lossy().to_string()), + None => Err(crate::Error::FailedToExecuteApi(crate::api::Error::Path( + "Couldn't get the parent directory".into(), + ))), + } +} + +#[cfg(path_all)] +fn extname(path: String) -> crate::Result { + match Path::new(&path) + .extension() + .and_then(std::ffi::OsStr::to_str) + { + Some(path) => Ok(path.to_string()), + None => Err(crate::Error::FailedToExecuteApi(crate::api::Error::Path( + "Couldn't get the extension of the file".into(), + ))), + } +} + +#[cfg(path_all)] +fn basename(path: String, ext: Option) -> crate::Result { + match Path::new(&path) + .file_name() + .and_then(std::ffi::OsStr::to_str) + { + Some(path) => Ok(if let Some(ext) = ext { + path.replace(ext.as_str(), "") + } else { + path.to_string() + }), + None => Err(crate::Error::FailedToExecuteApi(crate::api::Error::Path( + "Couldn't get the basename".into(), + ))), + } +} diff --git a/tooling/api/src/helpers/tauri.ts b/tooling/api/src/helpers/tauri.ts index 5ad2ed677..e0df6fc07 100644 --- a/tooling/api/src/helpers/tauri.ts +++ b/tooling/api/src/helpers/tauri.ts @@ -9,6 +9,7 @@ import { invoke } from '../tauri' type TauriModule = | 'App' | 'Fs' + | 'Path' | 'Os' | 'Window' | 'Shell' diff --git a/tooling/api/src/path.ts b/tooling/api/src/path.ts index 45b93744b..16cb897d5 100644 --- a/tooling/api/src/path.ts +++ b/tooling/api/src/path.ts @@ -4,9 +4,10 @@ import { invokeTauriCommand } from './helpers/tauri' import { BaseDirectory } from './fs' +import { isWindows } from './helpers/os-check' /** - * Read common system paths such as home, config and cache directories. + * The path module provides utilities for working with file and directory paths. * * This package is also accessible with `window.__TAURI__.path` when `tauri.conf.json > build > withGlobalTauri` is set to true. * @@ -15,9 +16,8 @@ import { BaseDirectory } from './fs' * { * "tauri": { * "allowlist": { - * "fs": { - * "all": true, // enable all FS APIs - * "path": true // enable path APIs + * "path": { + * "all": true, // enable all Path APIs * } * } * } @@ -35,7 +35,7 @@ import { BaseDirectory } from './fs' */ async function appDir(): Promise { return invokeTauriCommand({ - __tauriModule: 'Fs', + __tauriModule: 'Path', message: { cmd: 'resolvePath', path: '', @@ -57,7 +57,7 @@ async function appDir(): Promise { */ async function audioDir(): Promise { return invokeTauriCommand({ - __tauriModule: 'Fs', + __tauriModule: 'Path', message: { cmd: 'resolvePath', path: '', @@ -79,7 +79,7 @@ async function audioDir(): Promise { */ async function cacheDir(): Promise { return invokeTauriCommand({ - __tauriModule: 'Fs', + __tauriModule: 'Path', message: { cmd: 'resolvePath', path: '', @@ -101,7 +101,7 @@ async function cacheDir(): Promise { */ async function configDir(): Promise { return invokeTauriCommand({ - __tauriModule: 'Fs', + __tauriModule: 'Path', message: { cmd: 'resolvePath', path: '', @@ -123,7 +123,7 @@ async function configDir(): Promise { */ async function dataDir(): Promise { return invokeTauriCommand({ - __tauriModule: 'Fs', + __tauriModule: 'Path', message: { cmd: 'resolvePath', path: '', @@ -145,7 +145,7 @@ async function dataDir(): Promise { */ async function desktopDir(): Promise { return invokeTauriCommand({ - __tauriModule: 'Fs', + __tauriModule: 'Path', message: { cmd: 'resolvePath', path: '', @@ -167,7 +167,7 @@ async function desktopDir(): Promise { */ async function documentDir(): Promise { return invokeTauriCommand({ - __tauriModule: 'Fs', + __tauriModule: 'Path', message: { cmd: 'resolvePath', path: '', @@ -189,7 +189,7 @@ async function documentDir(): Promise { */ async function downloadDir(): Promise { return invokeTauriCommand({ - __tauriModule: 'Fs', + __tauriModule: 'Path', message: { cmd: 'resolvePath', path: '', @@ -211,7 +211,7 @@ async function downloadDir(): Promise { */ async function executableDir(): Promise { return invokeTauriCommand({ - __tauriModule: 'Fs', + __tauriModule: 'Path', message: { cmd: 'resolvePath', path: '', @@ -233,7 +233,7 @@ async function executableDir(): Promise { */ async function fontDir(): Promise { return invokeTauriCommand({ - __tauriModule: 'Fs', + __tauriModule: 'Path', message: { cmd: 'resolvePath', path: '', @@ -255,7 +255,7 @@ async function fontDir(): Promise { */ async function homeDir(): Promise { return invokeTauriCommand({ - __tauriModule: 'Fs', + __tauriModule: 'Path', message: { cmd: 'resolvePath', path: '', @@ -277,7 +277,7 @@ async function homeDir(): Promise { */ async function localDataDir(): Promise { return invokeTauriCommand({ - __tauriModule: 'Fs', + __tauriModule: 'Path', message: { cmd: 'resolvePath', path: '', @@ -299,7 +299,7 @@ async function localDataDir(): Promise { */ async function pictureDir(): Promise { return invokeTauriCommand({ - __tauriModule: 'Fs', + __tauriModule: 'Path', message: { cmd: 'resolvePath', path: '', @@ -321,7 +321,7 @@ async function pictureDir(): Promise { */ async function publicDir(): Promise { return invokeTauriCommand({ - __tauriModule: 'Fs', + __tauriModule: 'Path', message: { cmd: 'resolvePath', path: '', @@ -337,7 +337,7 @@ async function publicDir(): Promise { */ async function resourceDir(): Promise { return invokeTauriCommand({ - __tauriModule: 'Fs', + __tauriModule: 'Path', message: { cmd: 'resolvePath', path: '', @@ -359,7 +359,7 @@ async function resourceDir(): Promise { */ async function runtimeDir(): Promise { return invokeTauriCommand({ - __tauriModule: 'Fs', + __tauriModule: 'Path', message: { cmd: 'resolvePath', path: '', @@ -381,7 +381,7 @@ async function runtimeDir(): Promise { */ async function templateDir(): Promise { return invokeTauriCommand({ - __tauriModule: 'Fs', + __tauriModule: 'Path', message: { cmd: 'resolvePath', path: '', @@ -403,7 +403,7 @@ async function templateDir(): Promise { */ async function videoDir(): Promise { return invokeTauriCommand({ - __tauriModule: 'Fs', + __tauriModule: 'Path', message: { cmd: 'resolvePath', path: '', @@ -419,7 +419,7 @@ async function videoDir(): Promise { */ async function currentDir(): Promise { return invokeTauriCommand({ - __tauriModule: 'Fs', + __tauriModule: 'Path', message: { cmd: 'resolvePath', path: '', @@ -429,22 +429,110 @@ async function currentDir(): Promise { } /** - * Resolves the path with the optional base directory. - * - * @param path A path to resolve - * @param directory A base directory to use when resolving the given path - * @returns A path resolved to the given base directory. + * Provides the platform-specific path segment separator: + * - `\` on Windows + * - `/` on POSIX */ -async function resolvePath( - path: string, - directory: BaseDirectory -): Promise { +const sep = isWindows() ? '\\' : '/' + +/** + * Provides the platform-specific path segment delimiter: + * - `;` on Windows + * - `:` on POSIX + */ +const delimiter = isWindows() ? ';' : ':' + +/** + * Resolves a sequence of `paths` or `path` segments into an absolute path. + * + * @param paths A sequence of paths or path segments. + */ +async function resolve(...paths: string[]): Promise { return invokeTauriCommand({ - __tauriModule: 'Fs', + __tauriModule: 'Path', message: { - cmd: 'resolvePath', + cmd: 'resolve', + paths + } + }) +} + +/** + * Normalizes the given `path`, resolving `'..'` and `'.'` segments and resolve symolic links. + */ +async function normalize(path: string): Promise { + return invokeTauriCommand({ + __tauriModule: 'Path', + message: { + cmd: 'normalize', + path + } + }) +} + +/** + * Joins all given `path` segments together using the platform-specific separator as a delimiter, then normalizes the resulting path. + * + * @param paths A sequence of path segments. + */ +async function join(...paths: string[]): Promise { + return invokeTauriCommand({ + __tauriModule: 'Path', + message: { + cmd: 'join', + paths + } + }) +} + +/** + * Returns the directory name of a `path`. Trailing directory separators are ignored. + */ +async function dirname(path: string): Promise { + return invokeTauriCommand({ + __tauriModule: 'Path', + message: { + cmd: 'dirname', + path + } + }) +} + +/** + * Returns the extension of the `path`. + */ +async function extname(path: string): Promise { + return invokeTauriCommand({ + __tauriModule: 'Path', + message: { + cmd: 'extname', + path + } + }) +} + +/** + * Returns the last portion of a `path`. Trailing directory separators are ignored. + * + * @param ext An optional file extension to be removed from the returned path. + */ +async function basename(path: string, ext?: string): Promise { + return invokeTauriCommand({ + __tauriModule: 'Path', + message: { + cmd: 'basename', path, - directory + ext + } + }) +} + +async function isAbsolute(path: string): Promise { + return invokeTauriCommand({ + __tauriModule: 'Path', + message: { + cmd: 'isAbsolute', + path } }) } @@ -469,6 +557,14 @@ export { templateDir, videoDir, currentDir, - resolvePath, - BaseDirectory + BaseDirectory, + sep, + delimiter, + resolve, + normalize, + join, + dirname, + extname, + basename, + isAbsolute } diff --git a/tooling/cli.rs/config_definition.rs b/tooling/cli.rs/config_definition.rs index 61c9bda77..ff839aef5 100644 --- a/tooling/cli.rs/config_definition.rs +++ b/tooling/cli.rs/config_definition.rs @@ -380,8 +380,6 @@ pub struct FsAllowlistConfig { pub remove_file: bool, #[serde(default)] pub rename_file: bool, - #[serde(default)] - pub path: bool, } impl Allowlist for FsAllowlistConfig { @@ -400,7 +398,6 @@ impl Allowlist for FsAllowlistConfig { check_feature!(self, features, remove_dir, "fs-remove-dir"); check_feature!(self, features, remove_file, "fs-remove-file"); check_feature!(self, features, rename_file, "fs-rename-file"); - check_feature!(self, features, path, "fs-path"); features } } @@ -530,6 +527,40 @@ impl Allowlist for GlobalShortcutAllowlistConfig { } } +#[derive(Debug, Default, PartialEq, Clone, Deserialize, Serialize, JsonSchema)] +#[serde(rename_all = "camelCase", deny_unknown_fields)] +pub struct OsAllowlistConfig { + #[serde(default)] + pub all: bool, +} + +impl Allowlist for OsAllowlistConfig { + fn to_features(&self) -> Vec<&str> { + if self.all { + vec!["os-all"] + } else { + vec![] + } + } +} + +#[derive(Debug, Default, PartialEq, Clone, Deserialize, Serialize, JsonSchema)] +#[serde(rename_all = "camelCase", deny_unknown_fields)] +pub struct PathAllowlistConfig { + #[serde(default)] + pub all: bool, +} + +impl Allowlist for PathAllowlistConfig { + fn to_features(&self) -> Vec<&str> { + if self.all { + vec!["path-all"] + } else { + vec![] + } + } +} + #[derive(Debug, Default, PartialEq, Clone, Deserialize, Serialize, JsonSchema)] #[serde(rename_all = "camelCase", deny_unknown_fields)] pub struct AllowlistConfig { @@ -549,6 +580,10 @@ pub struct AllowlistConfig { pub notification: NotificationAllowlistConfig, #[serde(default)] pub global_shortcut: GlobalShortcutAllowlistConfig, + #[serde(default)] + pub os: OsAllowlistConfig, + #[serde(default)] + pub path: PathAllowlistConfig, } impl Allowlist for AllowlistConfig { @@ -564,6 +599,8 @@ impl Allowlist for AllowlistConfig { features.extend(self.http.to_features()); features.extend(self.notification.to_features()); features.extend(self.global_shortcut.to_features()); + features.extend(self.os.to_features()); + features.extend(self.path.to_features()); features } } diff --git a/tooling/cli.rs/schema.json b/tooling/cli.rs/schema.json index 086837052..f6d3b197c 100644 --- a/tooling/cli.rs/schema.json +++ b/tooling/cli.rs/schema.json @@ -49,7 +49,6 @@ "all": false, "copyFile": false, "createDir": false, - "path": false, "readBinaryFile": false, "readDir": false, "readTextFile": false, @@ -69,6 +68,12 @@ "notification": { "all": false }, + "os": { + "all": false + }, + "path": { + "all": false + }, "shell": { "all": false, "execute": false, @@ -133,7 +138,6 @@ "all": false, "copyFile": false, "createDir": false, - "path": false, "readBinaryFile": false, "readDir": false, "readTextFile": false, @@ -180,6 +184,26 @@ } ] }, + "os": { + "default": { + "all": false + }, + "allOf": [ + { + "$ref": "#/definitions/OsAllowlistConfig" + } + ] + }, + "path": { + "default": { + "all": false + }, + "allOf": [ + { + "$ref": "#/definitions/PathAllowlistConfig" + } + ] + }, "shell": { "default": { "all": false, @@ -724,10 +748,6 @@ "default": false, "type": "boolean" }, - "path": { - "default": false, - "type": "boolean" - }, "readBinaryFile": { "default": false, "type": "boolean" @@ -846,6 +866,16 @@ }, "additionalProperties": false }, + "OsAllowlistConfig": { + "type": "object", + "properties": { + "all": { + "default": false, + "type": "boolean" + } + }, + "additionalProperties": false + }, "PackageConfig": { "type": "object", "properties": { @@ -866,6 +896,16 @@ }, "additionalProperties": false }, + "PathAllowlistConfig": { + "type": "object", + "properties": { + "all": { + "default": false, + "type": "boolean" + } + }, + "additionalProperties": false + }, "SecurityConfig": { "type": "object", "properties": { @@ -930,7 +970,6 @@ "all": false, "copyFile": false, "createDir": false, - "path": false, "readBinaryFile": false, "readDir": false, "readTextFile": false, @@ -950,6 +989,12 @@ "notification": { "all": false }, + "os": { + "all": false + }, + "path": { + "all": false + }, "shell": { "all": false, "execute": false, diff --git a/tooling/cli.rs/src/helpers/config.rs b/tooling/cli.rs/src/helpers/config.rs index 4ca27ce6c..ab9a58104 100644 --- a/tooling/cli.rs/src/helpers/config.rs +++ b/tooling/cli.rs/src/helpers/config.rs @@ -135,7 +135,6 @@ pub fn all_allowlist_features() -> Vec<&'static str> { remove_dir: true, remove_file: true, rename_file: true, - path: true, }, window: WindowAllowlistConfig { all: true, @@ -157,6 +156,8 @@ pub fn all_allowlist_features() -> Vec<&'static str> { }, notification: NotificationAllowlistConfig { all: true }, global_shortcut: GlobalShortcutAllowlistConfig { all: true }, + os: OsAllowlistConfig { all: true }, + path: PathAllowlistConfig { all: true }, } .to_features() }