123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635 |
- /* eslint-disable */
- /**
- * * THIS FILE IS GENERATED AUTOMATICALLY.
- * DO NOT EDIT.
- *
- * Please whitelist these API functions in tauri.conf.json
- *
- **/
- /**
- * @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.json
- *
- * Each binding MUST provide these interfaces in order to be compliant,
- * and also whitelist them based upon the developer's settings.
- */
- // polyfills
- if (!String.prototype.startsWith) {
- String.prototype.startsWith = function (searchString, position) {
- position = position || 0
- return this.substr(position, searchString.length) === searchString
- }
- }
- // makes the window.external.invoke API available after window.location.href changes
- switch (navigator.platform) {
- case "Macintosh":
- case "MacPPC":
- case "MacIntel":
- case "Mac68K":
- window.external = this
- invoke = function (x) {
- webkit.messageHandlers.invoke.postMessage(x);
- }
- break;
- case "Windows":
- case "WinCE":
- case "Win32":
- case "Win64":
- break;
- default:
- window.external = this
- invoke = function (x) {
- window.webkit.messageHandlers.external.postMessage(x);
- }
- break;
- }
- 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); }
- /**
- * @typedef {number} BaseDirectory
- */
- /**
- * @enum {BaseDirectory}
- */
- var Dir = {
- Audio: 1,
- Cache: 2,
- Config: 3,
- Data: 4,
- LocalData: 5,
- Desktop: 6,
- Document: 7,
- Download: 8,
- Executable: 9,
- Font: 10,
- Home: 11,
- Picture: 12,
- Public: 13,
- Runtime: 14,
- Template: 15,
- Video: 16,
- Resource: 17,
- App: 18
- }
- function camelToKebab (string) {
- return string.replace(/([a-z0-9]|(?=[A-Z]))([A-Z])/g, '$1-$2').toLowerCase()
- }
- /**
- * @name return __whitelistWarning
- * @description Present a stylish warning to the developer that their API
- * call has not been whitelisted in tauri.conf.json
- * @param {String} func - function name to warn
- * @private
- */
- var __whitelistWarning = function (func) {
- console.warn('%c[Tauri] Danger \ntauri.' + func + ' not whitelisted 💣\n%c\nAdd to tauri.conf.json: \n\ntauri: \n whitelist: { \n ' + camelToKebab(func) + ': true \n\nReference: https://github.com/tauri-apps/tauri/wiki' + func, 'background: red; color: white; font-weight: 800; padding: 2px; font-size:1.5em', ' ')
- return __reject()
- }
-
- /**
- * @name __reject
- * @description generates a 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 = function () {
- return new Promise(function (_, reject) {
- reject();
- });
- }
- window.tauri = {
- Dir: Dir,
-
- /**
- * @name invoke
- * @description Calls a Tauri Core feature, such as setTitle
- * @param {Object} args
- */
-
- invoke: function invoke(args) {
- window.external.invoke(JSON.stringify(args));
- },
-
- /**
- * @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
- });
-
- },
-
- /**
- * @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
- });
-
- },
-
- /**
- * @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 = uid();
- window[identifier] = function (result) {
- if (once) {
- delete window[identifier];
- }
- return callback && callback(result);
- };
- return identifier;
- },
-
- /**
- * @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));
- });
- },
-
- /**
- * @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
- * @param {Object} [options]
- * @param {BaseDirectory} [options.dir]
- * @returns {*|Promise<any>|Promise}
- */
-
- readTextFile: function readTextFile(path, options) {
-
- return this.promisified({
- cmd: 'readTextFile',
- path: path,
- options: options
- });
-
- },
-
- /**
- * @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
- * @param {Object} [options]
- * @param {BaseDirectory} [options.dir]
- * @returns {*|Promise<any>|Promise}
- */
-
- readBinaryFile: function readBinaryFile(path, options) {
-
- return this.promisified({
- cmd: 'readBinaryFile',
- path: path,
- options: options
- });
-
- },
-
- /**
- * @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
- * @param {Object} [options]
- * @param {BaseDirectory} [options.dir]
- */
-
- writeFile: function writeFile(cfg, options) {
-
- if (_typeof(cfg) === 'object') {
- Object.freeze(cfg);
- }
- return this.promisified({
- cmd: 'writeFile',
- file: cfg.file,
- contents: cfg.contents,
- options: options
- });
-
- },
-
- /**
- * @name readDir
- * @description Reads a directory
- * Permissions based on the app's PID owner
- * @param {String} path
- * @param {Object} [options]
- * @param {Boolean} [options.recursive]
- * @param {BaseDirectory} [options.dir]
- * @returns {*|Promise<any>|Promise}
- */
-
- readDir: function readDir(path, options) {
-
- return this.promisified({
- cmd: 'readDir',
- path: path,
- options: options
- });
-
- },
-
- /**
- * @name createDir
- * @description Creates a directory
- * Permissions based on the app's PID owner
- * @param {String} path
- * @param {Object} [options]
- * @param {Boolean} [options.recursive]
- * @param {BaseDirectory} [options.dir]
- * @returns {*|Promise<any>|Promise}
- */
-
- createDir: function createDir(path, options) {
-
- return this.promisified({
- cmd: 'createDir',
- path: path,
- options: options
- });
-
- },
-
- /**
- * @name removeDir
- * @description Removes a directory
- * Permissions based on the app's PID owner
- * @param {String} path
- * @param {Object} [options]
- * @param {Boolean} [options.recursive]
- * @param {BaseDirectory} [options.dir]
- * @returns {*|Promise<any>|Promise}
- */
-
- removeDir: function removeDir(path, options) {
-
- return this.promisified({
- cmd: 'removeDir',
- path: path,
- options: options
- });
-
- },
-
- /**
- * @name copyFile
- * @description Copy file
- * Permissions based on the app's PID owner
- * @param {String} source
- * @param {String} destination
- * @param {Object} [options]
- * @param {BaseDirectory} [options.dir]
- * @returns {*|Promise<any>|Promise}
- */
-
- copyFile: function copyFile(source, destination, options) {
-
- return this.promisified({
- cmd: 'copyFile',
- source: source,
- destination: destination,
- options: options
- });
-
- },
-
- /**
- * @name removeFile
- * @description Removes a file
- * Permissions based on the app's PID owner
- * @param {String} path
- * @param {Object} [options]
- * @param {BaseDirectory} [options.dir]
- * @returns {*|Promise<any>|Promise}
- */
-
- removeFile: function removeFile(path, options) {
-
- return this.promisified({
- cmd: 'removeFile',
- path: path,
- options: options
- });
-
- },
-
- /**
- * @name renameFile
- * @description Renames a file
- * Permissions based on the app's PID owner
- * @param {String} path
- * @param {Object} [options]
- * @param {BaseDirectory} [options.dir]
- * @returns {*|Promise<any>|Promise}
- */
-
- renameFile: function renameFile(oldPath, newPath, options) {
-
- return this.promisified({
- cmd: 'renameFile',
- oldPath: oldPath,
- newPath: newPath,
- options: options
- });
-
- },
-
- /**
- * @name setTitle
- * @description Set the application's title
- * @param {String} title
- */
-
- setTitle: function setTitle(title) {
-
- this.invoke({
- cmd: 'setTitle',
- title: title
- });
-
- },
-
- /**
- * @name open
- * @description Open an URI
- * @param {String} uri
- */
-
- open: function open(uri) {
-
- this.invoke({
- cmd: 'open',
- uri: uri
- });
-
- },
-
- /**
- * @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 (_typeof(args) === 'object') {
- Object.freeze(args);
- }
- return this.promisified({
- cmd: 'execute',
- command: command,
- args: typeof args === 'string' ? [args] : args
- });
-
- },
-
- /**
- * @name openDialog
- * @description Open a file/directory selection dialog
- * @param {String} [options]
- * @param {String} [options.filter]
- * @param {String} [options.defaultPath]
- * @param {Boolean} [options.multiple=false]
- * @param {Boolean} [options.directory=false]
- * @returns {Promise<String|String[]>} promise resolving to the select path(s)
- */
-
- openDialog: function openDialog(options) {
-
- var opts = options || {}
- if (_typeof(options) === 'object') {
- opts.default_path = opts.defaultPath
- Object.freeze(options);
- }
- return this.promisified({
- cmd: 'openDialog',
- options: opts
- });
-
- },
-
- /**
- * @name saveDialog
- * @description Open a file/directory save dialog
- * @param {String} [options]
- * @param {String} [options.filter]
- * @param {String} [options.defaultPath]
- * @returns {Promise<String>} promise resolving to the select path
- */
-
- saveDialog: function saveDialog(options) {
-
- var opts = options || {}
- if (_typeof(options) === 'object') {
- opts.default_path = opts.defaultPath
- Object.freeze(options);
- }
- return this.promisified({
- cmd: 'saveDialog',
- options: opts
- });
-
- },
-
- /**
- * @name httpRequest
- * @description Makes an HTTP request
- * @param {Object} options
- * @param {String} options.method GET, POST, PUT, DELETE, PATCH, HEAD, OPTIONS, CONNECT or TRACE
- * @param {String} options.url the request URL
- * @param {Object} [options.headers] the request headers
- * @param {Object} [options.params] the request query params
- * @param {Object|String|Binary} [options.body] the request body
- * @param {Boolean} followRedirects whether to follow redirects or not
- * @param {Number} maxRedirections max number of redirections
- * @param {Number} connectTimeout request connect timeout
- * @param {Number} readTimeout request read timeout
- * @param {Number} timeout request timeout
- * @param {Boolean} allowCompression
- * @param {Number} [responseType=1] 1 - JSON, 2 - Text, 3 - Binary
- * @param {Number} [bodyType=3] 1 - Form, 2 - File, 3 - Auto
- * @returns {Promise<any>}
- */
-
- httpRequest: function httpRequest(options) {
-
- return this.promisified({
- cmd: 'httpRequest',
- options: options
- });
-
- },
- loadAsset: function loadAsset(assetName, assetType) {
- return this.promisified({
- cmd: 'loadAsset',
- asset: assetName,
- assetType: assetType || 'unknown'
- })
- },
- cliMatches: function () {
-
- return this.promisified({
- cmd: 'cliMatches'
- })
-
-
- }
- };
- // init tauri API
- try {
- window.tauri.invoke({
- cmd: 'init'
- })
- } catch (e) {
- window.addEventListener('DOMContentLoaded', function () {
- window.tauri.invoke({
- cmd: 'init'
- })
- }, true)
- }
- 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(function (img) {
- target.src = img
- })
- break
- }
- target = target.parentElement
- }
- }, true)
- // open <a href="..."> links with the Tauri API
- function __openLinks() {
- document.querySelector('body').addEventListener('click', function (e) {
- var target = e.target
- while (target != null) {
- if (target.matches ? target.matches('a') : target.msMatchesSelector('a')) {
- if (target.href && target.href.startsWith('http') && target.target === '_blank') {
- window.tauri.open(target.href)
- e.preventDefault()
- }
- break
- }
- target = target.parentElement
- }
- }, true)
- }
- if (document.readyState === 'complete' || document.readyState === 'interactive') {
- __openLinks()
- } else {
- window.addEventListener('DOMContentLoaded', function () {
- __openLinks()
- }, true)
- }
|