mirror of
https://github.com/streetwriters/notesnook.git
synced 2026-02-23 19:49:56 +01:00
desktop: make window.os a function
This commit is contained in:
@@ -22,9 +22,10 @@ import { ELECTRON_TRPC_CHANNEL } from "electron-trpc/main";
|
||||
import { type RendererGlobalElectronTRPC } from "electron-trpc/src/types";
|
||||
import type { NNCrypto } from "@notesnook/crypto";
|
||||
import { ipcRenderer } from "electron";
|
||||
import { platform } from "os";
|
||||
|
||||
declare global {
|
||||
var os: string;
|
||||
var os: () => "mas" | ReturnType<typeof platform>;
|
||||
var electronTRPC: RendererGlobalElectronTRPC;
|
||||
var NativeNNCrypto: (new () => NNCrypto) | undefined;
|
||||
}
|
||||
@@ -47,4 +48,4 @@ globalThis.NativeNNCrypto =
|
||||
? undefined
|
||||
: require("@notesnook/crypto").NNCrypto;
|
||||
|
||||
globalThis.os = MAC_APP_STORE ? "mas" : process.platform;
|
||||
globalThis.os = () => (MAC_APP_STORE ? "mas" : platform());
|
||||
|
||||
2
apps/web/src/global.d.ts
vendored
2
apps/web/src/global.d.ts
vendored
@@ -22,7 +22,7 @@ import "vite-plugin-svgr/client";
|
||||
|
||||
declare global {
|
||||
interface Window {
|
||||
os?: NodeJS.Platform | "mas";
|
||||
os?: () => NodeJS.Platform | "mas";
|
||||
NativeNNCrypto?: new () => import("@notesnook/crypto").NNCrypto;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,7 +81,7 @@ export { useStore, store };
|
||||
export const allowedPlatforms = [
|
||||
"all",
|
||||
import.meta.env.REACT_APP_PLATFORM,
|
||||
window.os
|
||||
...(window.os ? [window.os()] : [])
|
||||
];
|
||||
|
||||
async function shouldShowAnnouncement(announcement) {
|
||||
|
||||
@@ -18,7 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
export function getPlatform() {
|
||||
if (window.os) return window.os;
|
||||
if (window.os) return window.os();
|
||||
|
||||
const userAgent = window.navigator.userAgent,
|
||||
platform = window.navigator.platform,
|
||||
@@ -123,15 +123,17 @@ export function getDownloadLink(platform: string) {
|
||||
}
|
||||
|
||||
export function isDesktop() {
|
||||
return "os" in window;
|
||||
return "os" in window || import.meta.env.REACT_APP_PLATFORM === "desktop";
|
||||
}
|
||||
|
||||
export function isMac() {
|
||||
return getPlatform() === "macOS" || window.os === "darwin" || isMacStoreApp();
|
||||
return (
|
||||
getPlatform() === "macOS" || getPlatform() === "darwin" || isMacStoreApp()
|
||||
);
|
||||
}
|
||||
|
||||
export function isMacStoreApp() {
|
||||
return window.os === "mas";
|
||||
return window.os && window.os() === "mas";
|
||||
}
|
||||
|
||||
export function isTesting() {
|
||||
|
||||
Reference in New Issue
Block a user