Fix importing @tauri-apps/api in Node.js (#3752)

Co-authored-by: Lucas Nogueira <lucas@tauri.studio>
This commit is contained in:
Kasper
2022-03-22 22:19:46 +01:00
committed by GitHub
parent 1730b1a51d
commit d36c8e0322
7 changed files with 45 additions and 23 deletions

View 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

View 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 }

View File

@@ -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 }

View File

@@ -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'
/**

View File

@@ -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.

View File

@@ -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,
{