Merge pull request #1093 from Svallinn/946-version-flag
Support for version flag
This commit is contained in:
		
						commit
						23c2cd65f7
					
				|  | @ -1,59 +1,63 @@ | ||||||
| import { app, BrowserWindow, Menu, ipcMain, screen } from 'electron' | import { app, BrowserWindow, Menu, ipcMain, screen } from 'electron' | ||||||
| import { productName } from '../../package.json' |  | ||||||
| import Datastore from 'nedb' | import Datastore from 'nedb' | ||||||
| 
 | 
 | ||||||
| require('@electron/remote/main').initialize() | if (process.argv.includes('--version')) { | ||||||
|  |   console.log(`v${app.getVersion()}`) | ||||||
|  |   app.exit(0) | ||||||
|  | } else { | ||||||
|  |   runApp() | ||||||
|  | } | ||||||
| 
 | 
 | ||||||
| require('electron-context-menu')({ | function runApp() { | ||||||
|  |   require('@electron/remote/main').initialize() | ||||||
|  | 
 | ||||||
|  |   require('electron-context-menu')({ | ||||||
|     showSearchWithGoogle: false, |     showSearchWithGoogle: false, | ||||||
|     showSaveImageAs: true, |     showSaveImageAs: true, | ||||||
|     showCopyImageAddress: true, |     showCopyImageAddress: true, | ||||||
|     prepend: (params, browserWindow) => [] |     prepend: (params, browserWindow) => [] | ||||||
| }) |   }) | ||||||
| 
 | 
 | ||||||
| const localDataStorage = app.getPath('userData') // Grabs the userdata directory based on the user's OS
 |   const localDataStorage = app.getPath('userData') // Grabs the userdata directory based on the user's OS
 | ||||||
| 
 | 
 | ||||||
| const settingsDb = new Datastore({ |   const settingsDb = new Datastore({ | ||||||
|     filename: localDataStorage + '/settings.db', |     filename: localDataStorage + '/settings.db', | ||||||
|     autoload: true |     autoload: true | ||||||
| }) |   }) | ||||||
| 
 | 
 | ||||||
| // set app name
 |   // disable electron warning
 | ||||||
| app.setName(productName) |   process.env.ELECTRON_DISABLE_SECURITY_WARNINGS = 'true' | ||||||
|  |   const path = require('path') | ||||||
|  |   const isDev = process.env.NODE_ENV === 'development' | ||||||
|  |   const isDebug = process.argv.includes('--debug') | ||||||
|  |   let mainWindow | ||||||
|  |   let startupUrl | ||||||
| 
 | 
 | ||||||
| // disable electron warning
 |   // CORS somehow gets re-enabled in Electron v9.0.4
 | ||||||
| process.env.ELECTRON_DISABLE_SECURITY_WARNINGS = 'true' |   // This line disables it.
 | ||||||
| const path = require('path') |   // This line can possible be removed if the issue is fixed upstream
 | ||||||
| const isDev = process.env.NODE_ENV === 'development' |   app.commandLine.appendSwitch('disable-features', 'OutOfBlinkCors') | ||||||
| const isDebug = process.argv.includes('--debug') |  | ||||||
| let mainWindow |  | ||||||
| let startupUrl |  | ||||||
| 
 | 
 | ||||||
| // CORS somehow gets re-enabled in Electron v9.0.4
 |   app.commandLine.appendSwitch('enable-accelerated-video-decode') | ||||||
| // This line disables it.
 |   app.commandLine.appendSwitch('enable-file-cookies') | ||||||
| // This line can possible be removed if the issue is fixed upstream
 |   app.commandLine.appendSwitch('ignore-gpu-blacklist') | ||||||
| app.commandLine.appendSwitch('disable-features', 'OutOfBlinkCors') |  | ||||||
| 
 | 
 | ||||||
| app.commandLine.appendSwitch('enable-accelerated-video-decode') |   // See: https://stackoverflow.com/questions/45570589/electron-protocol-handler-not-working-on-windows
 | ||||||
| app.commandLine.appendSwitch('enable-file-cookies') |   // remove so we can register each time as we run the app.
 | ||||||
| app.commandLine.appendSwitch('ignore-gpu-blacklist') |   app.removeAsDefaultProtocolClient('freetube') | ||||||
| 
 | 
 | ||||||
| // See: https://stackoverflow.com/questions/45570589/electron-protocol-handler-not-working-on-windows
 |   // If we are running a non-packaged version of the app && on windows
 | ||||||
| // remove so we can register each time as we run the app.
 |   if (isDev && process.platform === 'win32') { | ||||||
| app.removeAsDefaultProtocolClient('freetube') |  | ||||||
| 
 |  | ||||||
| // If we are running a non-packaged version of the app && on windows
 |  | ||||||
| if (isDev && process.platform === 'win32') { |  | ||||||
|     // Set the path of electron.exe and your app.
 |     // Set the path of electron.exe and your app.
 | ||||||
|     // These two additional parameters are only available on windows.
 |     // These two additional parameters are only available on windows.
 | ||||||
|     app.setAsDefaultProtocolClient('freetube', process.execPath, [path.resolve(process.argv[1])]) |     app.setAsDefaultProtocolClient('freetube', process.execPath, [path.resolve(process.argv[1])]) | ||||||
| } else { |   } else { | ||||||
|     app.setAsDefaultProtocolClient('freetube') |     app.setAsDefaultProtocolClient('freetube') | ||||||
| } |   } | ||||||
| 
 | 
 | ||||||
| // TODO: Uncomment if needed
 |   // TODO: Uncomment if needed
 | ||||||
| // only allow single instance of application
 |   // only allow single instance of application
 | ||||||
| if (!isDev) { |   if (!isDev) { | ||||||
|     const gotTheLock = app.requestSingleInstanceLock() |     const gotTheLock = app.requestSingleInstanceLock() | ||||||
| 
 | 
 | ||||||
|     if (gotTheLock) { |     if (gotTheLock) { | ||||||
|  | @ -135,7 +139,7 @@ if (!isDev) { | ||||||
|     } else { |     } else { | ||||||
|       app.quit() |       app.quit() | ||||||
|     } |     } | ||||||
| } else { |   } else { | ||||||
|     require('electron-debug')({ |     require('electron-debug')({ | ||||||
|       showDevTools: !(process.env.RENDERER_REMOTE_DEBUGGING === 'true') |       showDevTools: !(process.env.RENDERER_REMOTE_DEBUGGING === 'true') | ||||||
|     }) |     }) | ||||||
|  | @ -202,9 +206,9 @@ if (!isDev) { | ||||||
|         } |         } | ||||||
|       }) |       }) | ||||||
|     }) |     }) | ||||||
| } |   } | ||||||
| 
 | 
 | ||||||
| async function installDevTools () { |   async function installDevTools () { | ||||||
|     try { |     try { | ||||||
|       /* eslint-disable */ |       /* eslint-disable */ | ||||||
|       require('devtron').install() |       require('devtron').install() | ||||||
|  | @ -213,9 +217,9 @@ async function installDevTools () { | ||||||
|     } catch (err) { |     } catch (err) { | ||||||
|       console.log(err) |       console.log(err) | ||||||
|     } |     } | ||||||
| } |   } | ||||||
| 
 | 
 | ||||||
| function createWindow (useProxy = false, proxyUrl = '') { |   function createWindow (useProxy = false, proxyUrl = '') { | ||||||
|     /** |     /** | ||||||
|      * Initial window options |      * Initial window options | ||||||
|      */ |      */ | ||||||
|  | @ -374,9 +378,9 @@ function createWindow (useProxy = false, proxyUrl = '') { | ||||||
|     ipcMain.on('disableProxy', () => { |     ipcMain.on('disableProxy', () => { | ||||||
|       mainWindow.webContents.session.setProxy({}) |       mainWindow.webContents.session.setProxy({}) | ||||||
|     }) |     }) | ||||||
| } |   } | ||||||
| 
 | 
 | ||||||
| app.on('window-all-closed', () => { |   app.on('window-all-closed', () => { | ||||||
|     if (process.platform !== 'darwin') { |     if (process.platform !== 'darwin') { | ||||||
|       app.quit() |       app.quit() | ||||||
|     } |     } | ||||||
|  | @ -394,18 +398,18 @@ app.on('window-all-closed', () => { | ||||||
|         'cachestorage' |         'cachestorage' | ||||||
|       ] |       ] | ||||||
|     }) |     }) | ||||||
| }) |   }) | ||||||
| 
 | 
 | ||||||
| app.on('activate', () => { |   app.on('activate', () => { | ||||||
|     if (mainWindow === null) { |     if (mainWindow === null) { | ||||||
|       createWindow() |       createWindow() | ||||||
|     } |     } | ||||||
| }) |   }) | ||||||
| 
 | 
 | ||||||
| /* |   /* | ||||||
|    * Callback when processing a freetube:// link (macOS)
 |    * Callback when processing a freetube:// link (macOS)
 | ||||||
|    */ |    */ | ||||||
| app.on('open-url', (event, url) => { |   app.on('open-url', (event, url) => { | ||||||
|     event.preventDefault() |     event.preventDefault() | ||||||
| 
 | 
 | ||||||
|     if (mainWindow && mainWindow.webContents) { |     if (mainWindow && mainWindow.webContents) { | ||||||
|  | @ -413,30 +417,30 @@ app.on('open-url', (event, url) => { | ||||||
|     } else { |     } else { | ||||||
|       startupUrl = baseUrl(url) |       startupUrl = baseUrl(url) | ||||||
|     } |     } | ||||||
| }) |   }) | ||||||
| 
 | 
 | ||||||
| /* |   /* | ||||||
|    * Check if an argument was passed and send it over to the GUI (Linux / Windows). |    * Check if an argument was passed and send it over to the GUI (Linux / Windows). | ||||||
|    * Remove freetube:// protocol if present
 |    * Remove freetube:// protocol if present
 | ||||||
|    */ |    */ | ||||||
| const url = getLinkUrl(process.argv) |   const url = getLinkUrl(process.argv) | ||||||
| if (url) { |   if (url) { | ||||||
|     startupUrl = url |     startupUrl = url | ||||||
| } |   } | ||||||
| 
 | 
 | ||||||
| function baseUrl(arg) { |   function baseUrl(arg) { | ||||||
|     return arg.replace('freetube://', '') |     return arg.replace('freetube://', '') | ||||||
| } |   } | ||||||
| 
 | 
 | ||||||
| function getLinkUrl(argv) { |   function getLinkUrl(argv) { | ||||||
|     if (argv.length > 1) { |     if (argv.length > 1) { | ||||||
|       return baseUrl(argv[argv.length - 1]) |       return baseUrl(argv[argv.length - 1]) | ||||||
|     } else { |     } else { | ||||||
|       return null |       return null | ||||||
|     } |     } | ||||||
| } |   } | ||||||
| 
 | 
 | ||||||
| /** |   /** | ||||||
|    * Auto Updater |    * Auto Updater | ||||||
|    * |    * | ||||||
|    * Uncomment the following code below and install `electron-updater` to |    * Uncomment the following code below and install `electron-updater` to | ||||||
|  | @ -444,31 +448,31 @@ function getLinkUrl(argv) { | ||||||
|    * https://simulatedgreg.gitbooks.io/electron-vue/content/en/using-electron-builder.html#auto-updating
 |    * https://simulatedgreg.gitbooks.io/electron-vue/content/en/using-electron-builder.html#auto-updating
 | ||||||
|    */ |    */ | ||||||
| 
 | 
 | ||||||
| /* |   /* | ||||||
| import { autoUpdater } from 'electron-updater' |   import { autoUpdater } from 'electron-updater' | ||||||
| autoUpdater.on('update-downloaded', () => { |   autoUpdater.on('update-downloaded', () => { | ||||||
|     autoUpdater.quitAndInstall() |     autoUpdater.quitAndInstall() | ||||||
| }) |   }) | ||||||
| 
 | 
 | ||||||
| app.on('ready', () => { |   app.on('ready', () => { | ||||||
|     if (process.env.NODE_ENV === 'production') autoUpdater.checkForUpdates() |     if (process.env.NODE_ENV === 'production') autoUpdater.checkForUpdates() | ||||||
| }) |   }) | ||||||
|    */ |    */ | ||||||
| 
 | 
 | ||||||
| /* eslint-disable-next-line */ |   /* eslint-disable-next-line */ | ||||||
| const sendMenuEvent = async data => { |   const sendMenuEvent = async data => { | ||||||
|     mainWindow.webContents.send('change-view', data) |     mainWindow.webContents.send('change-view', data) | ||||||
| } |   } | ||||||
| 
 | 
 | ||||||
| const template = [{ |   const template = [{ | ||||||
|     label: 'File', |     label: 'File', | ||||||
|     submenu: [ |     submenu: [ | ||||||
|       { |       { | ||||||
|         role: 'quit' |         role: 'quit' | ||||||
|       } |       } | ||||||
|     ] |     ] | ||||||
| }, |   }, | ||||||
| { |   { | ||||||
|     label: 'Edit', |     label: 'Edit', | ||||||
|     submenu: [{ |     submenu: [{ | ||||||
|       role: 'cut' |       role: 'cut' | ||||||
|  | @ -493,8 +497,8 @@ const template = [{ | ||||||
|       role: 'selectall' |       role: 'selectall' | ||||||
|     } |     } | ||||||
|     ] |     ] | ||||||
| }, |   }, | ||||||
| { |   { | ||||||
|     label: 'View', |     label: 'View', | ||||||
|     submenu: [{ |     submenu: [{ | ||||||
|       role: 'reload' |       role: 'reload' | ||||||
|  | @ -525,8 +529,8 @@ const template = [{ | ||||||
|       role: 'togglefullscreen' |       role: 'togglefullscreen' | ||||||
|     } |     } | ||||||
|     ] |     ] | ||||||
| }, |   }, | ||||||
| { |   { | ||||||
|     role: 'window', |     role: 'window', | ||||||
|     submenu: [{ |     submenu: [{ | ||||||
|       role: 'minimize' |       role: 'minimize' | ||||||
|  | @ -535,10 +539,10 @@ const template = [{ | ||||||
|       role: 'close' |       role: 'close' | ||||||
|     } |     } | ||||||
|     ] |     ] | ||||||
| } |   } | ||||||
| ] |   ] | ||||||
| 
 | 
 | ||||||
| function setMenu () { |   function setMenu () { | ||||||
|     if (process.platform === 'darwin') { |     if (process.platform === 'darwin') { | ||||||
|       template.unshift({ |       template.unshift({ | ||||||
|         label: app.getName(), |         label: app.getName(), | ||||||
|  | @ -568,4 +572,5 @@ function setMenu () { | ||||||
| 
 | 
 | ||||||
|     const menu = Menu.buildFromTemplate(template) |     const menu = Menu.buildFromTemplate(template) | ||||||
|     Menu.setApplicationMenu(menu) |     Menu.setApplicationMenu(menu) | ||||||
|  |   } | ||||||
| } | } | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue