- 
      
- 
        Save jochemstoel/f892a92c60546975507a50ac16153be2 to your computer and use it in GitHub Desktop. 
    electron-win-url
  
        
  
    
      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
    
  
  
    
  | //chat://function/?param=bar | |
| const { app, BrowserWindow } = require('electron'); | |
| const path = require('path'); | |
| const url = require('url'); | |
| let mainWindow = null; | |
| let yourURL; | |
| // Force Single Instance Application | |
| const shouldQuit = app.makeSingleInstance((argv, workingDirectory) => { | |
| // Protocol handler for win | |
| if (process.platform == 'win32') { | |
| yourURL = argv.slice(1); | |
| } | |
| logEverywhere(yourURL); | |
| if (win) { | |
| if (win.isMinimized()) win.restore(); | |
| win.focus(); | |
| } | |
| }); | |
| if (shouldQuit) { | |
| app.quit(); | |
| return; | |
| } | |
| function createWindow() { | |
| mainWindow = new BrowserWindow({ | |
| width: 800, | |
| height: 600 | |
| }); | |
| mainWindow.loadURL( | |
| url.format({ | |
| pathname: path.join(__dirname, 'index.html'), | |
| protocol: 'file:', | |
| slashes: true | |
| }) | |
| ); | |
| mainWindow.webContents.openDevTools(); | |
| // Protocol handler for win | |
| if (process.platform == 'win32') { | |
| yourURL = process.argv.slice(1); | |
| } | |
| logEverywhere(yourURL); | |
| handleURL(yourURL); | |
| mainWindow.on('closed', function() { | |
| mainWindow = null; | |
| }); | |
| } | |
| app.on('ready', createWindow); | |
| app.on('window-all-closed', function() { | |
| if (process.platform !== 'darwin') { | |
| app.quit(); | |
| } | |
| }); | |
| app.on('activate', function() { | |
| if (mainWindow === null) { | |
| createWindow(); | |
| } | |
| }); | |
| app.setAsDefaultProtocolClient('chat'); | |
| // Protocol handler for osx | |
| app.on('open-url', function(ev, url) { | |
| ev.preventDefault(); | |
| yourURL = url; | |
| logEverywhere(yourURL); | |
| }); | |
| function handleURL(url) { | |
| if (win && win.webContents) { | |
| win.webContents.executeJavaScript(handleIntent(`${url}`)); | |
| } | |
| if (url.indexOf('messagenius_dev') != -1) { | |
| win.webContents.openDevTools(); | |
| } | |
| if (url.indexOf('messagenius_fullscreen') != -1) { | |
| win.setFullScreen(true); | |
| } | |
| } | |
| function logEverywhere(s) { | |
| console.log(s); | |
| if (mainWindow && mainWindow.webContents) { | |
| mainWindow.webContents.executeJavaScript(`console.log("${s}")`); | |
| } | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment