Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

desktop: make window.os a function

Abdullah Atta533884e534d3
diff --git a/apps/desktop/src/preload.ts b/apps/desktop/src/preload.ts
index 31f2b39f1..c4bd47dd7 100644
--- a/apps/desktop/src/preload.ts
+++ b/apps/desktop/src/preload.ts
@@ -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());
diff --git a/apps/web/src/global.d.ts b/apps/web/src/global.d.ts
index ed4253846..1a673d9df 100644
--- a/apps/web/src/global.d.ts
+++ b/apps/web/src/global.d.ts
@@ -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;
}
}
diff --git a/apps/web/src/stores/announcement-store.js b/apps/web/src/stores/announcement-store.js
index 3e28f62e0..88bf88acf 100644
--- a/apps/web/src/stores/announcement-store.js
+++ b/apps/web/src/stores/announcement-store.js
@@ -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) {
diff --git a/apps/web/src/utils/platform.ts b/apps/web/src/utils/platform.ts
index 57e4bb854..f1f0e9635 100644
--- a/apps/web/src/utils/platform.ts
+++ b/apps/web/src/utils/platform.ts
@@ -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() {