Skip to content

Commit

Permalink
script fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfernog committed Oct 3, 2023
1 parent 6b47f48 commit df01c3c
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 18 deletions.
6 changes: 3 additions & 3 deletions core/tauri/scripts/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

const osName = __TEMPLATE_os_name__

Object.defineProperties(window.__TAURI__.__INTERNALS__, 'convertFileSrc', {
Object.defineProperty(window.__TAURI__.__INTERNALS__, 'convertFileSrc', {
value: function (filePath, protocol = 'asset') {
const path = encodeURIComponent(filePath)
return osName === 'windows' || osName === 'android'
Expand All @@ -18,7 +18,7 @@
}
})

Object.defineProperties(window.__TAURI__.__INTERNALS__, 'transformCallback', {
Object.defineProperty(window.__TAURI__.__INTERNALS__, 'transformCallback', {
value: function transformCallback(callback, once) {
var identifier = uid()
var prop = `_${identifier}`
Expand Down Expand Up @@ -52,7 +52,7 @@
}
}

Object.defineProperties(window.__TAURI__.__INTERNALS__, 'invoke', {
Object.defineProperty(window.__TAURI__.__INTERNALS__, 'invoke', {
value: function (cmd, payload = {}, options) {
return new Promise(function (resolve, reject) {
const callback = window.__TAURI__.__INTERNALS__.transformCallback(
Expand Down
14 changes: 0 additions & 14 deletions core/tauri/scripts/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,6 @@
// SPDX-License-Identifier: MIT

;(function () {
if (!window.__TAURI__) {
Object.defineProperty(window, '__TAURI__', {
value: {}
})
}

if (!window.__TAURI__.__INTERNALS__) {
Object.defineProperty(window.__TAURI__, '__INTERNALS__', {
value: {
plugins: {}
}
})
}

__RAW_freeze_prototype__

__RAW_pattern_script__
Expand Down
2 changes: 1 addition & 1 deletion core/tauri/scripts/process-ipc-message-fn.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

// this is a function and not an iife so use it carefully

;(function (message) {
(function (message) {
if (
message instanceof ArrayBuffer ||
ArrayBuffer.isView(message) ||
Expand Down
17 changes: 17 additions & 0 deletions core/tauri/src/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,23 @@ impl<R: Runtime> WindowManager<R> {
window_labels.push(l);
}
webview_attributes = webview_attributes
.initialization_script(
r#"
if (!window.__TAURI__) {
Object.defineProperty(window, '__TAURI__', {
value: {}
})
}
if (!window.__TAURI__.__INTERNALS__) {
Object.defineProperty(window.__TAURI__, '__INTERNALS__', {
value: {
plugins: {}
}
})
}
"#,
)
.initialization_script(&self.inner.invoke_initialization_script)
.initialization_script(&format!(
r#"
Expand Down

0 comments on commit df01c3c

Please sign in to comment.