123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418 |
- /* eslint-disable */
- /**
- * * THIS FILE IS GENERATED AUTOMATICALLY.
- * DO NOT EDIT.
- *
- * Please whitelist these API functions in tauri.conf.js
- *
- **/
- /**
- * @module tauri
- * @description This API interface makes powerful interactions available
- * to be run on client side applications. They are opt-in features, and
- * must be enabled in tauri.conf.js
- *
- * Each binding MUST provide these interfaces in order to be compliant,
- * and also whitelist them based upon the developer's settings.
- */
- function s4() {
- return Math.floor((1 + Math.random()) * 0x10000)
- .toString(16)
- .substring(1)
- }
- var uid = function () {
- return s4() + s4() + '-' + s4() + '-' + s4() + '-' +
- s4() + '-' + s4() + s4() + s4()
- }
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
- function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
- <% if (ctx.dev) { %>
- /**
- * @name __reject
- * @description is a private promise used to deflect un-whitelisted tauri API calls
- * Its only purpose is to maintain thenable structure in client code without
- * breaking the application
- * * @type {Promise<any>}
- * @private
- */
- <% } %>
- var __reject = new Promise(function (reject) {
- reject;
- });
- window.tauri = {
- <% if (ctx.dev) { %>
- /**
- * @name invoke
- * @description Calls a Tauri Core feature, such as setTitle
- * @param {Object} args
- */
- <% } %>
- invoke: function invoke(args) {
- window.external.invoke(JSON.stringify(args));
- },
- <% if (ctx.dev) { %>
- /**
- * @name listen
- * @description Add an event listener to Tauri backend
- * @param {String} event
- * @param {Function} handler
- * @param {Boolean} once
- */
- <% } %>
- listen: function listen(event, handler) {
- var once = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
- this.invoke({
- cmd: 'listen',
- event: event,
- handler: window.tauri.transformCallback(handler, once),
- once: once
- });
- },
- <% if (ctx.dev) { %>
- /**
- * @name emit
- * @description Emits an evt to the Tauri back end
- * @param {String} evt
- * @param {Object} payload
- */
- <% } %>
- emit: function emit(evt, payload) {
- this.invoke({
- cmd: 'emit',
- event: evt,
- payload: payload || ''
- });
- },
- <% if (ctx.dev) { %>
- /**
- * @name transformCallback
- * @description Registers a callback with a uid
- * @param {Function} callback
- * @param {Boolean} once
- * @returns {*}
- */
- <% } %>
- transformCallback: function transformCallback(callback) {
- var once = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
- var identifier = Object.freeze(uid());
- window[identifier] = function (result) {
- if (once) {
- delete window[identifier];
- }
- return callback && callback(result);
- };
- return identifier;
- },
- <% if (ctx.dev) { %>
- /**
- * @name promisified
- * @description Turns a request into a chainable promise
- * @param {Object} args
- * @returns {Promise<any>}
- */
- <% } %>
- promisified: function promisified(args) {
- var _this = this;
- return new Promise(function (resolve, reject) {
- _this.invoke(_objectSpread({
- callback: _this.transformCallback(resolve),
- error: _this.transformCallback(reject)
- }, args));
- });
- },
- <% if (ctx.dev) { %>
- /**
- * @name readTextFile
- * @description Accesses a non-binary file on the user's filesystem
- * and returns the content. Permissions based on the app's PID owner
- * @param {String} path
- * @returns {*|Promise<any>|Promise}
- */
- <% } %>
- readTextFile: function readTextFile(path) {
- <% if (tauri.whitelist.readTextFile === true || tauri.whitelist.all === true) { %>
- Object.freeze(path);
- return this.promisified({
- cmd: 'readTextFile',
- path: path
- });
- <% } else { %>
- <% if (ctx.dev) { %>
- __whitelistWarning('readTextFile')
- <% } %>
- return __reject
- <% } %>
- },
- <% if (ctx.dev) { %>
- /**
- * @name readBinaryFile
- * @description Accesses a binary file on the user's filesystem
- * and returns the content. Permissions based on the app's PID owner
- * @param {String} path
- * @returns {*|Promise<any>|Promise}
- */
- <% } %>
- readBinaryFile: function readBinaryFile(path) {
- <% if (tauri.whitelist.readBinaryFile === true || tauri.whitelist.all === true) { %>
- Object.freeze(path);
- return this.promisified({
- cmd: 'readBinaryFile',
- path: path
- });
- <% } else { %>
- <% if (ctx.dev) { %>
- __whitelistWarning('readBinaryFile')
- <% } %>
- return __reject
- <% } %>
- },
- <% if (ctx.dev) { %>
- /**
- * @name writeFile
- * @description Write a file to the Local Filesystem.
- * Permissions based on the app's PID owner
- * @param {Object} cfg
- * @param {String} cfg.file
- * @param {String|Binary} cfg.contents
- */
- <% } %>
- writeFile: function writeFile(cfg) {
- <% if (tauri.whitelist.writeFile === true || tauri.whitelist.all === true) { %>
- Object.freeze(cfg);
- this.invoke({
- cmd: 'writeFile',
- file: cfg.file,
- contents: cfg.contents
- });
- <% } else { %>
- <% if (ctx.dev) { %>
- __whitelistWarning('writeFile')
- <% } %>
- return __reject
- <% } %>
- },
- <% if (ctx.dev) { %>
- /**
- * @name listFiles
- * @description Get the files in a path.
- * Permissions based on the app's PID owner
- * @param {String} path
- * @returns {*|Promise<any>|Promise}
- */
- <% } %>
- listFiles: function listFiles(path) {
- <% if (tauri.whitelist.listFiles === true || tauri.whitelist.all === true) { %>
- Object.freeze(path);
- return this.promisified({
- cmd: 'listFiles',
- path: path
- });
- <% } else { %>
- <% if (ctx.dev) { %>
- __whitelistWarning('listDirs')
- <% } %>
- return __reject
- <% } %>
- },
- <% if (ctx.dev) { %>
- /**
- * @name listDirs
- * @description Get the directories in a path.
- * Permissions based on the app's PID owner
- * @param {String} path
- * @returns {*|Promise<any>|Promise}
- */
- <% } %>
- listDirs: function listDirs(path) {
- <% if (tauri.whitelist.listDirs === true || tauri.whitelist.all === true) { %>
- Object.freeze(path);
- return this.promisified({
- cmd: 'listDirs',
- path: path
- });
- <% } else { %>
- <% if (ctx.dev) { %>
- __whitelistWarning('listDirs')
- <% } %>
- return __reject
- <% } %>
- },
- <% if (ctx.dev) { %>
- /**
- * @name setTitle
- * @description Set the application's title
- * @param {String} title
- */
- <% } %>
- setTitle: function setTitle(title) {
- <% if (tauri.whitelist.setTitle === true || tauri.whitelist.all === true) { %>
- Object.freeze(title);
- this.invoke({
- cmd: 'setTitle',
- title: title
- });
- <% } else { %>
- <% if (ctx.dev) { %>
- __whitelistWarning('setTitle')
- <% } %>
- return __reject
- <% } %>
- },
- <% if (ctx.dev) { %>
- /**
- * @name open
- * @description Open an URI
- * @param {String} uri
- */
- <% } %>
- open: function open(uri) {
- <% if (tauri.whitelist.open === true || tauri.whitelist.all === true) { %>
- Object.freeze(uri);
- this.invoke({
- cmd: 'open',
- uri: uri
- });
- <% } else { %>
- <% if (ctx.dev) { %>
- __whitelistWarning('open')
- <% } %>
- return __reject
- <% } %>
- },
- <% if (ctx.dev) { %>
- /**
- * @name execute
- * @description Execute a program with arguments.
- * Permissions based on the app's PID owner
- * @param {String} command
- * @param {String|Array} args
- * @returns {*|Promise<any>|Promise}
- */
- <% } %>
- execute: function execute(command, args) {
- <% if (tauri.whitelist.execute === true || tauri.whitelist.all === true) { %>
- Object.freeze(command);
- if (typeof args === 'string' || _typeof(args) === 'object') {
- Object.freeze(args);
- }
- return this.promisified({
- cmd: 'execute',
- command: command,
- args: typeof args === 'string' ? [args] : args
- });
- <% } else { %>
- <% if (ctx.dev) { %>
- __whitelistWarning('execute')
- <% } %>
- return __reject
- <% } %>
- },
- bridge: function bridge(command, payload) {
- <% if (tauri.whitelist.bridge === true || tauri.whitelist.all === true) { %>
- Object.freeze(command);
- if (typeof payload === 'string' || _typeof(payload) === 'object') {
- Object.freeze(payload);
- }
- return this.promisified({
- cmd: 'bridge',
- command: command,
- payload: _typeof(payload) === 'object' ? [payload] : payload
- });
- <% } else { %>
- <% if (ctx.dev) { %>
- __whitelistWarning('bridge')
- <% } %>
- return __reject
- <% } %>
- },
- loadAsset: function loadAsset(assetName, assetType) {
- return this.promisified({
- cmd: 'loadAsset',
- asset: assetName,
- asset_type: assetType || 'unknown'
- })
- }
- };
- // init tauri API
- try {
- window.tauri.invoke({
- cmd: 'init'
- })
- } catch (e) {
- window.addEventListener('DOMContentLoaded', function () {
- window.tauri.invoke({
- cmd: 'init'
- })
- }, true)
- }
- if (window.onTauriInit !== void 0) {
- window.onTauriInit()
- }
- document.addEventListener('error', function (e) {
- var target = e.target
- while (target != null) {
- if (target.matches ? target.matches('img') : target.msMatchesSelector('img')) {
- window.tauri.loadAsset(target.src, 'image')
- .then(img => {
- target.src = img
- })
- break
- }
- target = target.parentElement
- }
- }, true)
- window.addEventListener('DOMContentLoaded', function () {
- // open <a href="..."> links with the Tauri API
- document.querySelector('body').addEventListener('click', function (e) {
- var target = e.target
- while (target != null) {
- if (target.matches ? target.matches('a') : target.msMatchesSelector('a')) {
- window.tauri.open(target.href)
- break
- }
- target = target.parentElement
- }
- }, true)
- }, true)
|