2019-05-16 17:00:37 +02:00
|
|
|
/**
|
|
|
|
* A Window interface with extra properties for Electron
|
|
|
|
*/
|
|
|
|
interface ElectronWindow extends Window {
|
|
|
|
require?: any;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Determines whether the app is running from a website or an app.
|
|
|
|
* @returns Boolean of whether it is in desktop mode or not
|
|
|
|
*/
|
|
|
|
export function isDesktopApp(): boolean {
|
|
|
|
return navigator.userAgent.includes("Hyperspace" || "Electron");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Determines whether the app is the macOS application
|
|
|
|
*/
|
|
|
|
export function isDarwinApp(): boolean {
|
2019-09-18 19:52:39 +02:00
|
|
|
return isDesktopApp() && navigator.userAgent.includes("Macintosh");
|
2019-05-16 17:00:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Determine whether the system is in dark mode or not (macOS)
|
|
|
|
*/
|
|
|
|
export function isDarkMode() {
|
2019-05-16 17:32:22 +02:00
|
|
|
// Lift window to an ElectronWindow and add use require()
|
|
|
|
const eWin = window as ElectronWindow;
|
2019-09-18 19:52:39 +02:00
|
|
|
const { remote } = eWin.require("electron");
|
|
|
|
return remote.systemPreferences.isDarkMode();
|
|
|
|
}
|
2019-10-01 00:18:38 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the accent color from macOS.
|
|
|
|
*
|
|
|
|
* Note that the colors will go from left to right, starting from zero (eg.: -1 = Graphite, 0 = Red, 1 = Orange, etc.).
|
|
|
|
* Since AppleAccentColor might return an empty string for the blue color, -2 is used instead.
|
|
|
|
*
|
|
|
|
* @returns The corresponding integer for the accent color
|
|
|
|
*/
|
|
|
|
export function getDarwinAccentColor(): number {
|
|
|
|
const eWin = window as ElectronWindow;
|
|
|
|
const { remote } = eWin.require("electron");
|
|
|
|
const themeInteger = remote.systemPreferences.getUserDefault(
|
|
|
|
"AppleAccentColor",
|
|
|
|
"string"
|
|
|
|
);
|
|
|
|
return themeInteger === "" ? -2 : parseInt(themeInteger);
|
|
|
|
}
|
2019-10-04 19:08:59 +02:00
|
|
|
|
2019-10-01 22:56:57 +02:00
|
|
|
/**
|
|
|
|
* Get the app component from the desktop app
|
|
|
|
*/
|
|
|
|
export function getElectronApp() {
|
|
|
|
const eWin = window as ElectronWindow;
|
|
|
|
const { remote } = eWin.require("electron");
|
|
|
|
return remote.app;
|
|
|
|
}
|