Skip to content

Commit

Permalink
fix(os): use an internal object instead of window.__TAURI__, closes
Browse files Browse the repository at this point in the history
…#719 (#721)

fix(os): use an internal object instead of ` window.__TAURI__`, closes  #719
  • Loading branch information
amrbashir authored Nov 14, 2023
1 parent 251852c commit fc62ead
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 14 deletions.
7 changes: 7 additions & 0 deletions .changes/os-reading-undefined.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"os": "patch"
"os-js": "patch"
---

Fix `Uncaught TypeError: Cannot read properties of undefined (reading 'os')`

1 change: 1 addition & 0 deletions examples/api/src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ rust-version = { workspace = true }
license = "Apache-2.0 OR MIT"

[lib]
name = "api_lib"
crate-type = [ "staticlib", "cdylib", "rlib" ]

[build-dependencies]
Expand Down
5 changes: 0 additions & 5 deletions examples/api/src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT

#![cfg_attr(
all(not(debug_assertions), target_os = "windows"),
windows_subsystem = "windows"
)]

mod cmd;
#[cfg(desktop)]
mod tray;
Expand Down
3 changes: 1 addition & 2 deletions examples/api/src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,5 @@
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]

fn main() {
#[cfg(desktop)]
api::run();
api_lib::run();
}
6 changes: 3 additions & 3 deletions plugins/os/guest-js/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import { invoke } from "@tauri-apps/api/primitives";
/** @ignore */
declare global {
interface Window {
__TAURI__: {
os: { __eol: string };
__TAURI_OS_PLUGIN_INTERNALS__: {
eol: string;
};
}
}
Expand Down Expand Up @@ -54,7 +54,7 @@ type Arch =
* @since 2.0.0
* */
function eol() {
return window.__TAURI__.os.__eol;
return window.__TAURI_OS_PLUGIN_INTERNALS__.eol;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion plugins/os/src/api-iife.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 7 additions & 3 deletions plugins/os/src/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT

__RAW_global_os_api__;

// eslint-disable-next-line
window.__TAURI__.os.__eol = __TEMPLATE_eol__;
Object.defineProperty(window, "__TAURI_OS_PLUGIN_INTERNALS__", {
value: {
eol: __TEMPLATE_eol__,
},
});

__RAW_global_os_api__;

0 comments on commit fc62ead

Please sign in to comment.