Skip to content

Commit fc62ead

Browse files
authored
fix(os): use an internal object instead of window.__TAURI__, closes tauri-apps#719 (tauri-apps#721)
fix(os): use an internal object instead of ` window.__TAURI__`, closes tauri-apps#719
1 parent 251852c commit fc62ead

File tree

7 files changed

+20
-14
lines changed

7 files changed

+20
-14
lines changed

Diff for: .changes/os-reading-undefined.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"os": "patch"
3+
"os-js": "patch"
4+
---
5+
6+
Fix `Uncaught TypeError: Cannot read properties of undefined (reading 'os')`
7+

Diff for: examples/api/src-tauri/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ rust-version = { workspace = true }
88
license = "Apache-2.0 OR MIT"
99

1010
[lib]
11+
name = "api_lib"
1112
crate-type = [ "staticlib", "cdylib", "rlib" ]
1213

1314
[build-dependencies]

Diff for: examples/api/src-tauri/src/lib.rs

-5
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,6 @@
22
// SPDX-License-Identifier: Apache-2.0
33
// SPDX-License-Identifier: MIT
44

5-
#![cfg_attr(
6-
all(not(debug_assertions), target_os = "windows"),
7-
windows_subsystem = "windows"
8-
)]
9-
105
mod cmd;
116
#[cfg(desktop)]
127
mod tray;

Diff for: examples/api/src-tauri/src/main.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,5 @@
66
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
77

88
fn main() {
9-
#[cfg(desktop)]
10-
api::run();
9+
api_lib::run();
1110
}

Diff for: plugins/os/guest-js/index.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ import { invoke } from "@tauri-apps/api/primitives";
1313
/** @ignore */
1414
declare global {
1515
interface Window {
16-
__TAURI__: {
17-
os: { __eol: string };
16+
__TAURI_OS_PLUGIN_INTERNALS__: {
17+
eol: string;
1818
};
1919
}
2020
}
@@ -54,7 +54,7 @@ type Arch =
5454
* @since 2.0.0
5555
* */
5656
function eol() {
57-
return window.__TAURI__.os.__eol;
57+
return window.__TAURI_OS_PLUGIN_INTERNALS__.eol;
5858
}
5959

6060
/**

Diff for: plugins/os/src/api-iife.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: plugins/os/src/init.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22
// SPDX-License-Identifier: Apache-2.0
33
// SPDX-License-Identifier: MIT
44

5-
__RAW_global_os_api__;
6-
75
// eslint-disable-next-line
8-
window.__TAURI__.os.__eol = __TEMPLATE_eol__;
6+
Object.defineProperty(window, "__TAURI_OS_PLUGIN_INTERNALS__", {
7+
value: {
8+
eol: __TEMPLATE_eol__,
9+
},
10+
});
11+
12+
__RAW_global_os_api__;

0 commit comments

Comments
 (0)