Forked from LucaBlackDragon/electron-protocol-registration.js
Created
June 11, 2019 20:52
-
-
Save r3sult/c97a65e9c655e079981e0549e43f078b to your computer and use it in GitHub Desktop.
Start Electron application through registered protocol/app schema (e.g. "my-app://some/thing?param=2")
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { app } from 'electron'; | |
| /** | |
| * Startup protocol/app schema registration | |
| * | |
| * @param {string} protocol Startup protocol/app schema to register ("://" must not be included) | |
| * | |
| * process.argv[1] will contain the full protocol/app schema through which the app has been started; | |
| * data can be sent to renderer windows through webContents.send() and ipcRenderer or other means. | |
| * | |
| * Useful links: | |
| * {@link https://electronjs.org/docs/api/app#appsetasdefaultprotocolclientprotocol-path-args-macos-windows} | |
| * {@link https://electronjs.org/docs/api/web-contents#contentssendchannel-arg1-arg2-} | |
| * {@link https://electronjs.org/docs/api/ipc-main} | |
| * | |
| * @example | |
| * setAppProtocol('my-app') // loading "my-app://some/thing?param=2" will start the app | |
| */ | |
| export default function setAppProtocol(protocol) { | |
| app.setAsDefaultProtocolClient(protocol); | |
| const showProcessArgv = () => console.log('Process args: %o', process.argv); | |
| if (app.isReady()) showProcessArgv(); | |
| else app.on('ready', showProcessArgv); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment