mirror of
https://github.com/tauri-apps/tauri.git
synced 2026-04-03 10:11:15 +02:00
Fix importing @tauri-apps/api in Node.js (#3752)
Co-authored-by: Lucas Nogueira <lucas@tauri.studio>
This commit is contained in:
5
.changes/fix-nodejs-api-import.md
Normal file
5
.changes/fix-nodejs-api-import.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"api": patch
|
||||
---
|
||||
|
||||
Fix importing `@tauri-apps/api` in Node.js
|
||||
File diff suppressed because one or more lines are too long
35
tooling/api/src/helpers/env-check.ts
Normal file
35
tooling/api/src/helpers/env-check.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
// Copyright 2019-2021 Tauri Programme within The Commons Conservancy
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
/** @ignore */
|
||||
|
||||
function isBrowser(): boolean {
|
||||
return typeof window !== 'undefined'
|
||||
}
|
||||
|
||||
function isLinux(): boolean {
|
||||
if (isBrowser()) {
|
||||
return navigator.appVersion.includes('Linux')
|
||||
} else {
|
||||
return process.platform === 'linux'
|
||||
}
|
||||
}
|
||||
|
||||
function isWindows(): boolean {
|
||||
if (isBrowser()) {
|
||||
return navigator.appVersion.includes('Win')
|
||||
} else {
|
||||
return process.platform === 'win32'
|
||||
}
|
||||
}
|
||||
|
||||
function isMacOS(): boolean {
|
||||
if (isBrowser()) {
|
||||
return navigator.appVersion.includes('Mac')
|
||||
} else {
|
||||
return process.platform === 'darwin'
|
||||
}
|
||||
}
|
||||
|
||||
export { isLinux, isWindows, isMacOS, isBrowser }
|
||||
@@ -1,19 +0,0 @@
|
||||
// Copyright 2019-2021 Tauri Programme within The Commons Conservancy
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
/** @ignore */
|
||||
|
||||
function isLinux(): boolean {
|
||||
return navigator.appVersion.includes('Linux')
|
||||
}
|
||||
|
||||
function isWindows(): boolean {
|
||||
return navigator.appVersion.includes('Win')
|
||||
}
|
||||
|
||||
function isMacOS(): boolean {
|
||||
return navigator.appVersion.includes('Mac')
|
||||
}
|
||||
|
||||
export { isLinux, isWindows, isMacOS }
|
||||
@@ -24,7 +24,7 @@
|
||||
*/
|
||||
|
||||
import { LiteralUnion } from 'type-fest'
|
||||
import { isWindows } from './helpers/os-check'
|
||||
import { isWindows } from './helpers/env-check'
|
||||
import { invokeTauriCommand } from './helpers/tauri'
|
||||
|
||||
/**
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
|
||||
import { invokeTauriCommand } from './helpers/tauri'
|
||||
import { BaseDirectory } from './fs'
|
||||
import { isWindows } from './helpers/os-check'
|
||||
import { isWindows } from './helpers/env-check'
|
||||
|
||||
/**
|
||||
* Returns the path to the suggested directory for your app config files.
|
||||
|
||||
@@ -108,6 +108,7 @@
|
||||
import { invokeTauriCommand } from './helpers/tauri'
|
||||
import type { EventName, EventCallback, UnlistenFn } from './event'
|
||||
import { emit, listen, once } from './helpers/event'
|
||||
import { isBrowser } from './helpers/env-check'
|
||||
|
||||
/** Allows you to retrieve information about a given monitor. */
|
||||
interface Monitor {
|
||||
@@ -1169,7 +1170,7 @@ class WebviewWindow extends WindowManager {
|
||||
|
||||
/** The WebviewWindow for the current window. */
|
||||
let appWindow
|
||||
if ('__TAURI_METADATA__' in window) {
|
||||
if (isBrowser() && '__TAURI_METADATA__' in window) {
|
||||
appWindow = new WebviewWindow(
|
||||
window.__TAURI_METADATA__.__currentWindow.label,
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user