electron
electron copied to clipboard
Detecting electron
Apologies if this is in the documentation, I've looked through them and couldn't find the answer. What is the appropriate way of detecting that capacitor is running through electron? The best way I've found is that Capacitor.getPlatform() !== "web"
AND Device.getInfo()
(from the @capacitor/device plugin) returns an object with platform
set to "web"
which is pretty weird!
You could try window.CapacitorCustomPlatform?.name === 'electron'
.
Or you could add the following to the preload.ts
file:
import { addPlatform, setPlatform } from "@capacitor/core";
addPlatform('electron', {
name: 'electron',
isNativePlatform: () => true,
getPlatform: () => 'electron',
});
setPlatform('electron');
On the most recent version Capacitor.getPlatform() === 'electron'
should just work, but I have experienced Capacitor being a bit flaky with this.