|
@@ -0,0 +1,347 @@
|
|
|
+<!DOCTYPE html><html><head><meta http-equiv="Content-Security-Policy" content="default-src blob: data: filesystem: ws: http: https: 'unsafe-eval' 'unsafe-inline'"></head><body><script>/* 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); }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+var __reject = function () {
|
|
|
+ return new Promise(function (_, reject) {
|
|
|
+ reject();
|
|
|
+ });
|
|
|
+}
|
|
|
+
|
|
|
+window.tauri = {
|
|
|
+
|
|
|
+ invoke: function invoke(args) {
|
|
|
+ window.external.invoke(JSON.stringify(args));
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
+ 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
|
|
|
+ });
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
+ emit: function emit(evt, payload) {
|
|
|
+
|
|
|
+ this.invoke({
|
|
|
+ cmd: 'emit',
|
|
|
+ event: evt,
|
|
|
+ payload: payload || ''
|
|
|
+ });
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
+ 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;
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
+ 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));
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
+ readTextFile: function readTextFile(path) {
|
|
|
+
|
|
|
+ return this.promisified({
|
|
|
+ cmd: 'readTextFile',
|
|
|
+ path: path
|
|
|
+ });
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
+ readBinaryFile: function readBinaryFile(path) {
|
|
|
+
|
|
|
+ return this.promisified({
|
|
|
+ cmd: 'readBinaryFile',
|
|
|
+ path: path
|
|
|
+ });
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
+ writeFile: function writeFile(cfg) {
|
|
|
+
|
|
|
+ if (_typeof(cfg) === 'object') {
|
|
|
+ Object.freeze(cfg);
|
|
|
+ }
|
|
|
+ this.invoke({
|
|
|
+ cmd: 'writeFile',
|
|
|
+ file: cfg.file,
|
|
|
+ contents: cfg.contents
|
|
|
+ });
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
+ listFiles: function listFiles(path) {
|
|
|
+
|
|
|
+ return this.promisified({
|
|
|
+ cmd: 'listFiles',
|
|
|
+ path: path
|
|
|
+ });
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
+ listDirs: function listDirs(path) {
|
|
|
+
|
|
|
+ return this.promisified({
|
|
|
+ cmd: 'listDirs',
|
|
|
+ path: path
|
|
|
+ });
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
+ setTitle: function setTitle(title) {
|
|
|
+
|
|
|
+ this.invoke({
|
|
|
+ cmd: 'setTitle',
|
|
|
+ title: title
|
|
|
+ });
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
+ open: function open(uri) {
|
|
|
+
|
|
|
+ this.invoke({
|
|
|
+ cmd: 'open',
|
|
|
+ uri: uri
|
|
|
+ });
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
+ 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
|
|
|
+ });
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+bridge: function bridge(command, payload) {
|
|
|
+
|
|
|
+
|
|
|
+ if (_typeof(payload) === 'object') {
|
|
|
+ Object.freeze(payload);
|
|
|
+ }
|
|
|
+
|
|
|
+ return this.promisified({
|
|
|
+ cmd: 'bridge',
|
|
|
+ command: command,
|
|
|
+ payload: _typeof(payload) === 'object' ? [payload] : payload
|
|
|
+ });
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+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)
|
|
|
+}
|
|
|
+
|
|
|
+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)
|
|
|
+}
|
|
|
+</script>
|
|
|
+ <div>
|
|
|
+ <button id="log">Call Log API</button>
|
|
|
+ <button id="request">Call Request (async) API</button>
|
|
|
+ <button id="event">Send event to Rust</button>
|
|
|
+ <div id="response"></div>
|
|
|
+ </div>
|
|
|
+ <script>
|
|
|
+ window.onTauriInit = function () {
|
|
|
+ window.tauri.listen('rust-event', function (res) {
|
|
|
+ document.getElementById('response').innerHTML = JSON.stringify(res)
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ document.getElementById('log').addEventListener('click', function () {
|
|
|
+ window.tauri.invoke({
|
|
|
+ cmd: 'logOperation',
|
|
|
+ event: 'tauri-click',
|
|
|
+ payload: 'this payload is optional because we used Option in Rust'
|
|
|
+ })
|
|
|
+ })
|
|
|
+
|
|
|
+ document.getElementById('request').addEventListener('click', function () {
|
|
|
+ window.tauri.promisified({
|
|
|
+ cmd: 'performRequest',
|
|
|
+ endpoint: 'dummy endpoint arg',
|
|
|
+ body: {
|
|
|
+ id: 5,
|
|
|
+ name: 'test'
|
|
|
+ }
|
|
|
+ }).then(function (response) {
|
|
|
+ document.getElementById('response').innerHTML = JSON.stringify(response)
|
|
|
+ })
|
|
|
+ })
|
|
|
+
|
|
|
+ document.getElementById('event').addEventListener('click', function () {
|
|
|
+ window.tauri.emit('js-event', 'this is the payload string')
|
|
|
+ })
|
|
|
+ </script>
|
|
|
+
|
|
|
+</body></html>
|