tauri.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. /* eslint-disable */
  2. /**
  3. * * THIS FILE IS GENERATED AUTOMATICALLY.
  4. * DO NOT EDIT.
  5. *
  6. * Please whitelist these API functions in tauri.conf.js
  7. *
  8. **/
  9. // open <a href="..."> links with the Tauri API
  10. /**
  11. * @module tauri
  12. * @description This API interface makes powerful interactions available
  13. * to be run on client side applications. They are opt-in features, and
  14. * must be enabled in tauri.conf.js
  15. *
  16. * Each binding MUST provide these interfaces in order to be compliant,
  17. * and also whitelist them based upon the developer's settings.
  18. */
  19. function s4() {
  20. return Math.floor((1 + Math.random()) * 0x10000)
  21. .toString(16)
  22. .substring(1)
  23. }
  24. const uid = function () {
  25. return s4() + s4() + '-' + s4() + '-' + s4() + '-' +
  26. s4() + '-' + s4() + s4() + s4()
  27. }
  28. 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; }
  29. 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; }
  30. 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; }
  31. 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); }
  32. var __reject = new Promise(function (reject) {
  33. reject;
  34. });
  35. window.tauri = {
  36. invoke: function invoke(args) {
  37. Object.freeze(args);
  38. window.external.invoke(JSON.stringify(args));
  39. },
  40. listen: function listen(event, handler) {
  41. var once = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
  42. this.invoke({
  43. cmd: 'listen',
  44. event: event,
  45. handler: this.transformCallback(handler, once),
  46. once: once
  47. });
  48. },
  49. emit: function emit(evt, payload) {
  50. this.invoke({
  51. cmd: 'emit',
  52. event: evt,
  53. payload: payload
  54. });
  55. },
  56. transformCallback: function transformCallback(callback) {
  57. var once = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
  58. var identifier = Object.freeze(uid());
  59. window[identifier] = function (result) {
  60. if (once) {
  61. delete window[identifier];
  62. }
  63. return callback && callback(result);
  64. };
  65. return identifier;
  66. },
  67. promisified: function promisified(args) {
  68. var _this = this;
  69. return new Promise(function (resolve, reject) {
  70. _this.invoke(_objectSpread({
  71. callback: _this.transformCallback(resolve),
  72. error: _this.transformCallback(reject)
  73. }, args));
  74. });
  75. },
  76. readTextFile: function readTextFile(path) {
  77. Object.freeze(path);
  78. return this.promisified({
  79. cmd: 'readTextFile',
  80. path: path
  81. });
  82. },
  83. readBinaryFile: function readBinaryFile(path) {
  84. Object.freeze(path);
  85. return this.promisified({
  86. cmd: 'readBinaryFile',
  87. path: path
  88. });
  89. },
  90. writeFile: function writeFile(cfg) {
  91. Object.freeze(cfg);
  92. this.invoke({
  93. cmd: 'writeFile',
  94. file: cfg.file,
  95. contents: cfg.contents
  96. });
  97. },
  98. listFiles: function listFiles(path) {
  99. Object.freeze(path);
  100. return this.promisified({
  101. cmd: 'listFiles',
  102. path: path
  103. });
  104. },
  105. listDirs: function listDirs(path) {
  106. Object.freeze(path);
  107. return this.promisified({
  108. cmd: 'listDirs',
  109. path: path
  110. });
  111. },
  112. setTitle: function setTitle(title) {
  113. Object.freeze(title);
  114. this.invoke({
  115. cmd: 'setTitle',
  116. title: title
  117. });
  118. },
  119. open: function open(uri) {
  120. Object.freeze(uri);
  121. this.invoke({
  122. cmd: 'open',
  123. uri: uri
  124. });
  125. },
  126. execute: function execute(command, args) {
  127. Object.freeze(command);
  128. if (typeof args === 'string' || _typeof(args) === 'object') {
  129. Object.freeze(args);
  130. }
  131. return this.promisified({
  132. cmd: 'execute',
  133. command: command,
  134. args: typeof args === 'string' ? [args] : args
  135. });
  136. },
  137. bridge: function bridge(command, payload) {
  138. Object.freeze(command);
  139. if (typeof payload === 'string' || _typeof(payload) === 'object') {
  140. Object.freeze(payload);
  141. }
  142. return this.promisified({
  143. cmd: 'bridge',
  144. command: command,
  145. payload: _typeof(payload) === 'object' ? [payload] : payload
  146. });
  147. },
  148. setup: function setup() {
  149. document.querySelector('body').addEventListener('click', function (e) {
  150. var target = e.target;
  151. while (target != null) {
  152. if (target.matches ? target.matches('a') : target.msMatchesSelector('a')) {
  153. tauri.open(target.href);
  154. break;
  155. }
  156. target = target.parentElement;
  157. }
  158. }, true);
  159. window.tauri.invoke({
  160. cmd: 'init'
  161. });
  162. }
  163. };