desktop: make window.os a function

This commit is contained in:
Abdullah Atta
2023-06-23 19:04:34 +05:00
parent f5c2962951
commit 533884e534
4 changed files with 11 additions and 8 deletions

View File

@@ -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());

View File

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

View File

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

View File

@@ -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() {