| 2 | |
| 3 | const uid = () => window.crypto.getRandomValues(new Uint32Array(1))[0]; |
| 4 | function transformCallback(callback = () => {}, once = false) { |
| 5 | const identifier = uid(); |
| 6 | const prop = `_${identifier}`; |
| 7 | Object.defineProperty(window, prop, { |
| 8 | value: (result) => { |
| 9 | if (once) { |
| 10 | Reflect.deleteProperty(window, prop); |
| 11 | } |
| 12 | return callback(result) |
| 13 | }, |
| 14 | writable: false, |
| 15 | configurable: true, |
| 16 | }) |
| 17 | return identifier; |
| 18 | } |
| 19 | async function invoke(cmd, args) { |
| 20 | return new Promise((resolve, reject) => { |
| 21 | if (!window.__TAURI_POST_MESSAGE__) reject('__TAURI_POST_MESSAGE__ does not exist!'); |