snapshot of https://github.com/tauri-apps/tauri.git (dev, 2026-09-23; blobs > 131072B omitted)
Some checks failed
Audit / audit-js (push) Failing after 0s
bench / bench (map[os:ubuntu-latest runner:xvfb-run --auto-servernum target:x86_64-unknown-linux-gnu], nightly) (push) Failing after 0s
covector version or publish / run-integration-tests (ubuntu-latest) (push) Failing after 0s
Audit / audit-rust (push) Failing after 0s
test `@tauri-apps/cli` / test (ubuntu-latest) (push) Failing after 0s
test `tauri-cli` / test (map[os:ubuntu-latest target:x86_64-unknown-linux-gnu]) (push) Failing after 0s
test core / test (map[args:--all-features key:all], map[cargo:cargo command:test os:ubuntu-latest target:x86_64-unknown-linux-gnu toolchain:1.90]) (push) Failing after 0s
test core / test (map[args:--no-default-features key:no-default], map[cargo:cargo command:test os:ubuntu-latest target:x86_64-unknown-linux-gnu toolchain:1.90]) (push) Failing after 0s
test core / test (map[args:--no-default-features key:no-default], map[cargo:cross command:build os:ubuntu-latest target:aarch64-linux-android toolchain:1.90]) (push) Failing after 0s
deploy schema worker / deploy (push) Failing after 0s
lint rust / clippy (map[cargo:cargo include: os:ubuntu-latest target:x86_64-unknown-linux-gnu]) (push) Failing after 0s
lint rust / clippy (map[cargo:cross include:--package api os:ubuntu-latest target:aarch64-linux-android]) (push) Failing after 0s
supply chain health status / check rust dependencies with cargo vet (push) Failing after 0s
test `@tauri-apps/api` e2e (mobile) / android (push) Failing after 0s
test `@tauri-apps/api` e2e / test (map[name:Linux os:ubuntu-latest]) (push) Failing after 0s
test core / test (map[args:--all-features key:all], map[cargo:cross command:build os:ubuntu-latest target:aarch64-linux-android toolchain:1.90]) (push) Failing after 0s
Udeps / changes (push) Failing after 0s
Udeps / setup (push) Has been skipped
Udeps / udeps (push) Has been skipped
bench / bench (map[os:macos-latest runner: target:aarch64-apple-darwin], nightly) (push) Has been cancelled
bench / bench (map[os:windows-latest runner: target:x86_64-pc-windows-msvc], nightly) (push) Has been cancelled
covector version or publish / run-integration-tests (macos-latest) (push) Has been cancelled
covector version or publish / run-integration-tests (windows-latest) (push) Has been cancelled
covector version or publish / version-or-publish (push) Has been cancelled
test `@tauri-apps/cli` / test (macos-latest) (push) Has been cancelled
test `tauri-cli` / test (map[args:--no-default-features --features native-tls-vendored os:windows-latest restore-only:true target:aarch64-pc-windows-msvc]) (push) Has been cancelled
test `tauri-cli` / test (map[os:macos-latest target:x86_64-apple-darwin]) (push) Has been cancelled
test `tauri-cli` / test (map[os:windows-latest target:x86_64-pc-windows-msvc]) (push) Has been cancelled
test core / test (map[args:--all-features key:all], map[cargo:cargo command:build os:macos-latest target:aarch64-apple-ios toolchain:1.90]) (push) Has been cancelled
test core / test (map[args:--all-features key:all], map[cargo:cargo command:test os:macos-14 target:aarch64-apple-darwin toolchain:1.90]) (push) Has been cancelled
lint rust / clippy (map[cargo:cargo include: os:macos-latest target:aarch64-apple-darwin]) (push) Has been cancelled
lint rust / clippy (map[cargo:cargo include: os:windows-latest target:x86_64-pc-windows-msvc]) (push) Has been cancelled
lint rust / clippy (map[cargo:cargo include:--package api os:macos-latest target:aarch64-apple-ios]) (push) Has been cancelled
test `@tauri-apps/api` e2e (mobile) / ios (push) Has been cancelled
test `@tauri-apps/api` e2e / test (map[name:Windows os:windows-latest]) (push) Has been cancelled
test `@tauri-apps/api` e2e / test (map[name:macOS os:macos-latest]) (push) Has been cancelled
test `@tauri-apps/cli` / test (windows-latest) (push) Has been cancelled
test core / test (map[args:--all-features key:all], map[cargo:cargo command:test os:windows-latest target:x86_64-pc-windows-msvc toolchain:1.90]) (push) Has been cancelled
test core / test (map[args:--no-default-features key:no-default], map[cargo:cargo command:build os:macos-latest target:aarch64-apple-ios toolchain:1.90]) (push) Has been cancelled
test core / test (map[args:--no-default-features key:no-default], map[cargo:cargo command:test os:macos-14 target:aarch64-apple-darwin toolchain:1.90]) (push) Has been cancelled
test core / test (map[args:--no-default-features key:no-default], map[cargo:cargo command:test os:windows-latest target:x86_64-pc-windows-msvc toolchain:1.90]) (push) Has been cancelled
Some checks failed
Audit / audit-js (push) Failing after 0s
bench / bench (map[os:ubuntu-latest runner:xvfb-run --auto-servernum target:x86_64-unknown-linux-gnu], nightly) (push) Failing after 0s
covector version or publish / run-integration-tests (ubuntu-latest) (push) Failing after 0s
Audit / audit-rust (push) Failing after 0s
test `@tauri-apps/cli` / test (ubuntu-latest) (push) Failing after 0s
test `tauri-cli` / test (map[os:ubuntu-latest target:x86_64-unknown-linux-gnu]) (push) Failing after 0s
test core / test (map[args:--all-features key:all], map[cargo:cargo command:test os:ubuntu-latest target:x86_64-unknown-linux-gnu toolchain:1.90]) (push) Failing after 0s
test core / test (map[args:--no-default-features key:no-default], map[cargo:cargo command:test os:ubuntu-latest target:x86_64-unknown-linux-gnu toolchain:1.90]) (push) Failing after 0s
test core / test (map[args:--no-default-features key:no-default], map[cargo:cross command:build os:ubuntu-latest target:aarch64-linux-android toolchain:1.90]) (push) Failing after 0s
deploy schema worker / deploy (push) Failing after 0s
lint rust / clippy (map[cargo:cargo include: os:ubuntu-latest target:x86_64-unknown-linux-gnu]) (push) Failing after 0s
lint rust / clippy (map[cargo:cross include:--package api os:ubuntu-latest target:aarch64-linux-android]) (push) Failing after 0s
supply chain health status / check rust dependencies with cargo vet (push) Failing after 0s
test `@tauri-apps/api` e2e (mobile) / android (push) Failing after 0s
test `@tauri-apps/api` e2e / test (map[name:Linux os:ubuntu-latest]) (push) Failing after 0s
test core / test (map[args:--all-features key:all], map[cargo:cross command:build os:ubuntu-latest target:aarch64-linux-android toolchain:1.90]) (push) Failing after 0s
Udeps / changes (push) Failing after 0s
Udeps / setup (push) Has been skipped
Udeps / udeps (push) Has been skipped
bench / bench (map[os:macos-latest runner: target:aarch64-apple-darwin], nightly) (push) Has been cancelled
bench / bench (map[os:windows-latest runner: target:x86_64-pc-windows-msvc], nightly) (push) Has been cancelled
covector version or publish / run-integration-tests (macos-latest) (push) Has been cancelled
covector version or publish / run-integration-tests (windows-latest) (push) Has been cancelled
covector version or publish / version-or-publish (push) Has been cancelled
test `@tauri-apps/cli` / test (macos-latest) (push) Has been cancelled
test `tauri-cli` / test (map[args:--no-default-features --features native-tls-vendored os:windows-latest restore-only:true target:aarch64-pc-windows-msvc]) (push) Has been cancelled
test `tauri-cli` / test (map[os:macos-latest target:x86_64-apple-darwin]) (push) Has been cancelled
test `tauri-cli` / test (map[os:windows-latest target:x86_64-pc-windows-msvc]) (push) Has been cancelled
test core / test (map[args:--all-features key:all], map[cargo:cargo command:build os:macos-latest target:aarch64-apple-ios toolchain:1.90]) (push) Has been cancelled
test core / test (map[args:--all-features key:all], map[cargo:cargo command:test os:macos-14 target:aarch64-apple-darwin toolchain:1.90]) (push) Has been cancelled
lint rust / clippy (map[cargo:cargo include: os:macos-latest target:aarch64-apple-darwin]) (push) Has been cancelled
lint rust / clippy (map[cargo:cargo include: os:windows-latest target:x86_64-pc-windows-msvc]) (push) Has been cancelled
lint rust / clippy (map[cargo:cargo include:--package api os:macos-latest target:aarch64-apple-ios]) (push) Has been cancelled
test `@tauri-apps/api` e2e (mobile) / ios (push) Has been cancelled
test `@tauri-apps/api` e2e / test (map[name:Windows os:windows-latest]) (push) Has been cancelled
test `@tauri-apps/api` e2e / test (map[name:macOS os:macos-latest]) (push) Has been cancelled
test `@tauri-apps/cli` / test (windows-latest) (push) Has been cancelled
test core / test (map[args:--all-features key:all], map[cargo:cargo command:test os:windows-latest target:x86_64-pc-windows-msvc toolchain:1.90]) (push) Has been cancelled
test core / test (map[args:--no-default-features key:no-default], map[cargo:cargo command:build os:macos-latest target:aarch64-apple-ios toolchain:1.90]) (push) Has been cancelled
test core / test (map[args:--no-default-features key:no-default], map[cargo:cargo command:test os:macos-14 target:aarch64-apple-darwin toolchain:1.90]) (push) Has been cancelled
test core / test (map[args:--no-default-features key:no-default], map[cargo:cargo command:test os:windows-latest target:x86_64-pc-windows-msvc toolchain:1.90]) (push) Has been cancelled
This commit is contained in:
1
crates/tauri/scripts/bundle.global.js
Normal file
1
crates/tauri/scripts/bundle.global.js
Normal file
File diff suppressed because one or more lines are too long
114
crates/tauri/scripts/core.js
Normal file
114
crates/tauri/scripts/core.js
Normal file
@@ -0,0 +1,114 @@
|
||||
// Copyright 2019-2024 Tauri Programme within The Commons Conservancy
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
;(function () {
|
||||
function uid() {
|
||||
return window.crypto.getRandomValues(new Uint32Array(1))[0]
|
||||
}
|
||||
|
||||
const osName = __TEMPLATE_os_name__
|
||||
const protocolScheme = __TEMPLATE_protocol_scheme__
|
||||
|
||||
Object.defineProperty(window.__TAURI_INTERNALS__, 'convertFileSrc', {
|
||||
value: function (filePath, protocol = 'asset') {
|
||||
const path = encodeURIComponent(filePath)
|
||||
return osName === 'windows' || osName === 'android'
|
||||
? `${protocolScheme}://${protocol}.localhost/${path}`
|
||||
: `${protocol}://localhost/${path}`
|
||||
}
|
||||
})
|
||||
|
||||
const callbacks = new Map()
|
||||
|
||||
function registerCallback(callback, once) {
|
||||
const identifier = uid()
|
||||
callbacks.set(identifier, (data) => {
|
||||
if (once) {
|
||||
unregisterCallback(identifier)
|
||||
}
|
||||
return callback && callback(data)
|
||||
})
|
||||
return identifier
|
||||
}
|
||||
|
||||
function unregisterCallback(id) {
|
||||
callbacks.delete(id)
|
||||
}
|
||||
|
||||
function runCallback(id, data) {
|
||||
const callback = callbacks.get(id)
|
||||
if (callback) {
|
||||
callback(data)
|
||||
} else {
|
||||
console.warn(
|
||||
`[TAURI] Couldn't find callback id ${id}. This might happen when the app is reloaded while Rust is running an asynchronous operation.`
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// Maybe let's rename it to `registerCallback`?
|
||||
Object.defineProperty(window.__TAURI_INTERNALS__, 'transformCallback', {
|
||||
value: registerCallback
|
||||
})
|
||||
|
||||
Object.defineProperty(window.__TAURI_INTERNALS__, 'unregisterCallback', {
|
||||
value: unregisterCallback
|
||||
})
|
||||
|
||||
Object.defineProperty(window.__TAURI_INTERNALS__, 'runCallback', {
|
||||
value: runCallback
|
||||
})
|
||||
|
||||
// This is just for the debugging purposes
|
||||
Object.defineProperty(window.__TAURI_INTERNALS__, 'callbacks', {
|
||||
value: callbacks
|
||||
})
|
||||
|
||||
const ipcQueue = []
|
||||
let isWaitingForIpc = false
|
||||
|
||||
function waitForIpc() {
|
||||
if ('ipc' in window.__TAURI_INTERNALS__) {
|
||||
for (const action of ipcQueue) {
|
||||
action()
|
||||
}
|
||||
} else {
|
||||
setTimeout(waitForIpc, 50)
|
||||
}
|
||||
}
|
||||
|
||||
Object.defineProperty(window.__TAURI_INTERNALS__, 'invoke', {
|
||||
value: function (cmd, payload = {}, options) {
|
||||
return new Promise(function (resolve, reject) {
|
||||
const callback = registerCallback((r) => {
|
||||
resolve(r)
|
||||
unregisterCallback(error)
|
||||
}, true)
|
||||
const error = registerCallback((e) => {
|
||||
reject(e)
|
||||
unregisterCallback(callback)
|
||||
}, true)
|
||||
|
||||
const action = () => {
|
||||
window.__TAURI_INTERNALS__.ipc({
|
||||
cmd,
|
||||
callback,
|
||||
error,
|
||||
payload,
|
||||
options
|
||||
})
|
||||
}
|
||||
if ('ipc' in window.__TAURI_INTERNALS__) {
|
||||
action()
|
||||
} else {
|
||||
ipcQueue.push(action)
|
||||
if (!isWaitingForIpc) {
|
||||
waitForIpc()
|
||||
isWaitingForIpc = true
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
})()
|
||||
5
crates/tauri/scripts/freeze_prototype.js
Normal file
5
crates/tauri/scripts/freeze_prototype.js
Normal file
@@ -0,0 +1,5 @@
|
||||
// Copyright 2019-2024 Tauri Programme within The Commons Conservancy
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
Object.freeze(Object.prototype)
|
||||
15
crates/tauri/scripts/init.js
Normal file
15
crates/tauri/scripts/init.js
Normal file
@@ -0,0 +1,15 @@
|
||||
// Copyright 2019-2024 Tauri Programme within The Commons Conservancy
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
;(function () {
|
||||
__RAW_freeze_prototype__
|
||||
|
||||
__RAW_pattern_script__
|
||||
|
||||
__RAW_ipc_script__
|
||||
|
||||
__RAW_core_script__
|
||||
|
||||
__RAW_event_initialization_script__
|
||||
})()
|
||||
91
crates/tauri/scripts/ipc-protocol.js
Normal file
91
crates/tauri/scripts/ipc-protocol.js
Normal file
@@ -0,0 +1,91 @@
|
||||
// Copyright 2019-2024 Tauri Programme within The Commons Conservancy
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
;(function () {
|
||||
/**
|
||||
* A runtime generated key to ensure an IPC call comes from an initialized frame.
|
||||
*
|
||||
* This is declared outside the `window.__TAURI_INVOKE__` definition to prevent
|
||||
* the key from being leaked by `window.__TAURI_INVOKE__.toString()`.
|
||||
*/
|
||||
const __TAURI_INVOKE_KEY__ = __TEMPLATE_invoke_key__
|
||||
|
||||
const processIpcMessage = __RAW_process_ipc_message_fn__
|
||||
const osName = __TEMPLATE_os_name__
|
||||
const fetchChannelDataCommand = __TEMPLATE_fetch_channel_data_command__
|
||||
let customProtocolIpcFailed = false
|
||||
|
||||
// on Android we never use it because Android does not have support to reading the request body
|
||||
const canUseCustomProtocol = osName !== 'android'
|
||||
|
||||
function sendIpcMessage(message) {
|
||||
const { cmd, callback, error, payload, options } = message
|
||||
|
||||
if (
|
||||
!customProtocolIpcFailed
|
||||
&& (canUseCustomProtocol || cmd === fetchChannelDataCommand)
|
||||
) {
|
||||
const { contentType, data } = processIpcMessage(payload)
|
||||
|
||||
const headers = new Headers((options && options.headers) || {})
|
||||
headers.set('Content-Type', contentType)
|
||||
headers.set('Tauri-Callback', callback)
|
||||
headers.set('Tauri-Error', error)
|
||||
headers.set('Tauri-Invoke-Key', __TAURI_INVOKE_KEY__)
|
||||
|
||||
fetch(window.__TAURI_INTERNALS__.convertFileSrc(cmd, 'ipc'), {
|
||||
method: 'POST',
|
||||
body: data,
|
||||
headers
|
||||
})
|
||||
.then((response) => {
|
||||
const callbackId =
|
||||
response.headers.get('Tauri-Response') === 'ok' ? callback : error
|
||||
// we need to split here because on Android the content-type gets duplicated
|
||||
switch ((response.headers.get('content-type') || '').split(',')[0]) {
|
||||
case 'application/json':
|
||||
return response.json().then((r) => [callbackId, r])
|
||||
case 'text/plain':
|
||||
return response.text().then((r) => [callbackId, r])
|
||||
default:
|
||||
return response.arrayBuffer().then((r) => [callbackId, r])
|
||||
}
|
||||
})
|
||||
.then(
|
||||
([callbackId, data]) => {
|
||||
window.__TAURI_INTERNALS__.runCallback(callbackId, data)
|
||||
},
|
||||
(e) => {
|
||||
console.warn(
|
||||
'IPC custom protocol failed, Tauri will now use the postMessage interface instead',
|
||||
e
|
||||
)
|
||||
// failed to use the custom protocol IPC (either the webview blocked a custom protocol or it was a CSP error)
|
||||
// so we need to fallback to the postMessage interface
|
||||
customProtocolIpcFailed = true
|
||||
sendIpcMessage(message)
|
||||
}
|
||||
)
|
||||
} else {
|
||||
// otherwise use the postMessage interface
|
||||
const { data } = processIpcMessage({
|
||||
cmd,
|
||||
callback,
|
||||
error,
|
||||
options: {
|
||||
...options,
|
||||
customProtocolIpcBlocked: customProtocolIpcFailed
|
||||
},
|
||||
payload,
|
||||
__TAURI_INVOKE_KEY__
|
||||
})
|
||||
// `window.ipc.postMessage` came from `tauri-runtime-wry` > `wry` [`with_ipc_handler`](https://github.com/tauri-apps/wry/blob/a0403b9e2f1ff9d73be7dce1184f058afcaa1d82/src/lib.rs#L1130)
|
||||
window.ipc.postMessage(data)
|
||||
}
|
||||
}
|
||||
|
||||
Object.defineProperty(window.__TAURI_INTERNALS__, 'postMessage', {
|
||||
value: sendIpcMessage
|
||||
})
|
||||
})()
|
||||
210
crates/tauri/scripts/ipc.js
Normal file
210
crates/tauri/scripts/ipc.js
Normal file
@@ -0,0 +1,210 @@
|
||||
// Copyright 2019-2024 Tauri Programme within The Commons Conservancy
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
/**
|
||||
* @typedef {{callback: string, error: string, data: *}} IsolationPayload - a valid isolation payload
|
||||
*/
|
||||
|
||||
;(function () {
|
||||
/**
|
||||
* @type {string}
|
||||
*/
|
||||
const pattern = window.__TAURI_INTERNALS__.__TAURI_PATTERN__.pattern
|
||||
|
||||
/**
|
||||
* @type {string}
|
||||
*/
|
||||
const isolationOrigin = __TEMPLATE_isolation_origin__
|
||||
|
||||
/**
|
||||
* @type {{queue: object[], ready: boolean, frame: HTMLElement | null}}
|
||||
*/
|
||||
const isolation = Object.create(null)
|
||||
isolation.queue = []
|
||||
isolation.ready = false
|
||||
isolation.frame = null
|
||||
|
||||
/**
|
||||
* Detects if a message event is a valid isolation message.
|
||||
*
|
||||
* @param {MessageEvent<object>} event - a message event that is expected to be an isolation message
|
||||
* @return {boolean} - if the event was a valid isolation message
|
||||
*/
|
||||
function isIsolationMessage(event) {
|
||||
if (
|
||||
typeof event.data === 'object'
|
||||
&& typeof event.data.payload === 'object'
|
||||
) {
|
||||
const keys = Object.keys(event.data.payload || {})
|
||||
return (
|
||||
keys.length > 0
|
||||
&& keys.every(
|
||||
(key) => key === 'contentType' || key === 'nonce' || key === 'payload'
|
||||
)
|
||||
)
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
/**
|
||||
* Detects if data is able to transform into an isolation payload.
|
||||
*
|
||||
* @param {object} data - object that is expected to contain at least a callback and error identifier
|
||||
* @return {boolean} - if the data is able to transform into an isolation payload
|
||||
*/
|
||||
function isIsolationPayload(data) {
|
||||
return (
|
||||
typeof data === 'object'
|
||||
&& 'callback' in data
|
||||
&& 'error' in data
|
||||
&& !isIsolationMessage(data)
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a properly formatted message to the isolation frame.
|
||||
*
|
||||
* @param {IsolationPayload} data - data that has been validated to be an isolation payload
|
||||
*/
|
||||
function sendIsolationMessage(data) {
|
||||
// set the frame dom element if it's not been set before
|
||||
if (!isolation.frame) {
|
||||
const frame = document.querySelector('iframe#__tauri_isolation__')
|
||||
if (frame.src.startsWith(isolationOrigin)) {
|
||||
isolation.frame = frame
|
||||
} else {
|
||||
console.error(
|
||||
'Tauri IPC found an isolation iframe, but it had the wrong origin'
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// ensure we have the target to send the message to
|
||||
if (!isolation.frame || !isolation.frame.contentWindow) {
|
||||
console.error(
|
||||
'Tauri "Isolation" Pattern could not find the Isolation iframe window'
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
// `postMessage` uses `structuredClone` to serialize the data before sending it
|
||||
// unlike `JSON.stringify`, we can't extend a type with a method similar to `toJSON`
|
||||
// so that `structuredClone` would use, so until https://github.com/whatwg/html/issues/7428
|
||||
// we manually call `toIPC`
|
||||
function serializeIpcPayload(data) {
|
||||
// if this value changes, make sure to update it in:
|
||||
// 1. process-ipc-message-fn.js
|
||||
// 2. core.ts
|
||||
const SERIALIZE_TO_IPC_FN = '__TAURI_TO_IPC_KEY__'
|
||||
|
||||
if (
|
||||
typeof data === 'object'
|
||||
&& data !== null
|
||||
&& 'constructor' in data
|
||||
&& data.constructor === Array
|
||||
) {
|
||||
return data.map((v) => serializeIpcPayload(v))
|
||||
}
|
||||
|
||||
if (
|
||||
typeof data === 'object'
|
||||
&& data !== null
|
||||
&& SERIALIZE_TO_IPC_FN in data
|
||||
) {
|
||||
return data[SERIALIZE_TO_IPC_FN]()
|
||||
}
|
||||
|
||||
if (
|
||||
typeof data === 'object'
|
||||
&& data !== null
|
||||
&& 'constructor' in data
|
||||
&& data.constructor === Object
|
||||
) {
|
||||
const acc = {}
|
||||
Object.entries(data).forEach(([k, v]) => {
|
||||
acc[k] = serializeIpcPayload(v)
|
||||
})
|
||||
return acc
|
||||
}
|
||||
|
||||
return data
|
||||
}
|
||||
|
||||
data.payload = serializeIpcPayload(data.payload)
|
||||
|
||||
isolation.frame.contentWindow.postMessage(
|
||||
data,
|
||||
'*' /* todo: set this to the secure origin */
|
||||
)
|
||||
}
|
||||
|
||||
Object.defineProperty(window.__TAURI_INTERNALS__, 'ipc', {
|
||||
// todo: JSDoc this function
|
||||
value: Object.freeze((message) => {
|
||||
switch (pattern) {
|
||||
case 'brownfield':
|
||||
window.__TAURI_INTERNALS__.postMessage(message)
|
||||
break
|
||||
|
||||
case 'isolation':
|
||||
if (!isIsolationPayload(message)) {
|
||||
console.error(
|
||||
'Tauri "Isolation" Pattern found an invalid isolation message payload',
|
||||
message
|
||||
)
|
||||
break
|
||||
}
|
||||
|
||||
if (isolation.ready) {
|
||||
sendIsolationMessage(message)
|
||||
} else {
|
||||
isolation.queue.push(message)
|
||||
}
|
||||
|
||||
break
|
||||
|
||||
case 'error':
|
||||
console.error(
|
||||
'Tauri IPC found a Tauri Pattern, but it was an error. Check for other log messages to find the cause.'
|
||||
)
|
||||
break
|
||||
|
||||
default:
|
||||
console.error(
|
||||
'Tauri IPC did not find a Tauri Pattern that it understood.'
|
||||
)
|
||||
break
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
/**
|
||||
* IMPORTANT: See isolation_secure.js for the isolation frame implementation.
|
||||
* main frame -> isolation frame = isolation payload
|
||||
* isolation frame -> main frame = isolation message
|
||||
*/
|
||||
if (pattern === 'isolation') {
|
||||
window.addEventListener(
|
||||
'message',
|
||||
(event) => {
|
||||
// watch for the isolation frame being ready and flush any queued messages
|
||||
if (event.data === '__TAURI_ISOLATION_READY__') {
|
||||
isolation.ready = true
|
||||
|
||||
for (const message of isolation.queue) {
|
||||
sendIsolationMessage(message)
|
||||
}
|
||||
|
||||
isolation.queue = []
|
||||
return
|
||||
}
|
||||
|
||||
if (isIsolationMessage(event)) {
|
||||
window.__TAURI_INTERNALS__.postMessage(event.data)
|
||||
}
|
||||
},
|
||||
false
|
||||
)
|
||||
}
|
||||
})()
|
||||
17
crates/tauri/scripts/isolation.js
Normal file
17
crates/tauri/scripts/isolation.js
Normal file
@@ -0,0 +1,17 @@
|
||||
// Copyright 2019-2024 Tauri Programme within The Commons Conservancy
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
if (location.href !== __TEMPLATE_isolation_src__) {
|
||||
window.addEventListener('DOMContentLoaded', () => {
|
||||
let style = document.createElement('style')
|
||||
style.textContent = __TEMPLATE_style__
|
||||
document.head.append(style)
|
||||
|
||||
let iframe = document.createElement('iframe')
|
||||
iframe.id = '__tauri_isolation__'
|
||||
iframe.sandbox.add('allow-scripts')
|
||||
iframe.src = __TEMPLATE_isolation_src__
|
||||
document.body.append(iframe)
|
||||
})
|
||||
}
|
||||
21
crates/tauri/scripts/pattern.js
Normal file
21
crates/tauri/scripts/pattern.js
Normal file
@@ -0,0 +1,21 @@
|
||||
// Copyright 2019-2024 Tauri Programme within The Commons Conservancy
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
;(function () {
|
||||
function __tauriDeepFreeze(object) {
|
||||
const props = Object.getOwnPropertyNames(object)
|
||||
|
||||
for (const prop of props) {
|
||||
if (typeof object[prop] === 'object') {
|
||||
__tauriDeepFreeze(object[prop])
|
||||
}
|
||||
}
|
||||
|
||||
return Object.freeze(object)
|
||||
}
|
||||
|
||||
Object.defineProperty(window.__TAURI_INTERNALS__, '__TAURI_PATTERN__', {
|
||||
value: __tauriDeepFreeze(__TEMPLATE_pattern__)
|
||||
})
|
||||
})()
|
||||
46
crates/tauri/scripts/process-ipc-message-fn.js
Normal file
46
crates/tauri/scripts/process-ipc-message-fn.js
Normal file
@@ -0,0 +1,46 @@
|
||||
// Copyright 2019-2024 Tauri Programme within The Commons Conservancy
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
// this is a function and not an iife so use it carefully
|
||||
|
||||
(function (message) {
|
||||
if (
|
||||
message instanceof ArrayBuffer
|
||||
|| ArrayBuffer.isView(message)
|
||||
|| Array.isArray(message)
|
||||
) {
|
||||
return {
|
||||
contentType: 'application/octet-stream',
|
||||
data: message
|
||||
}
|
||||
} else {
|
||||
const data = JSON.stringify(message, (_k, val) => {
|
||||
// if this value changes, make sure to update it in:
|
||||
// 1. ipc.js
|
||||
// 2. core.ts
|
||||
const SERIALIZE_TO_IPC_FN = '__TAURI_TO_IPC_KEY__'
|
||||
|
||||
if (val instanceof Map) {
|
||||
return Object.fromEntries(val.entries())
|
||||
} else if (val instanceof Uint8Array) {
|
||||
return Array.from(val)
|
||||
} else if (val instanceof ArrayBuffer) {
|
||||
return Array.from(new Uint8Array(val))
|
||||
} else if (
|
||||
typeof val === 'object'
|
||||
&& val !== null
|
||||
&& SERIALIZE_TO_IPC_FN in val
|
||||
) {
|
||||
return val[SERIALIZE_TO_IPC_FN]()
|
||||
} else {
|
||||
return val
|
||||
}
|
||||
})
|
||||
|
||||
return {
|
||||
contentType: 'application/json',
|
||||
data
|
||||
}
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user