Support for version flag
This commit is contained in:
parent
986053ad03
commit
3734bad6ef
|
@ -2,57 +2,65 @@ import { app, BrowserWindow, Menu, ipcMain, screen } from 'electron'
|
|||
import { productName } from '../../package.json'
|
||||
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,
|
||||
showSaveImageAs: true,
|
||||
showCopyImageAddress: true,
|
||||
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',
|
||||
autoload: true
|
||||
})
|
||||
})
|
||||
|
||||
// set app name
|
||||
app.setName(productName)
|
||||
// set app name
|
||||
app.setName(productName)
|
||||
|
||||
// disable electron warning
|
||||
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
|
||||
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
|
||||
|
||||
// CORS somehow gets re-enabled in Electron v9.0.4
|
||||
// This line disables it.
|
||||
// This line can possible be removed if the issue is fixed upstream
|
||||
app.commandLine.appendSwitch('disable-features', 'OutOfBlinkCors')
|
||||
// CORS somehow gets re-enabled in Electron v9.0.4
|
||||
// This line disables it.
|
||||
// This line can possible be removed if the issue is fixed upstream
|
||||
app.commandLine.appendSwitch('disable-features', 'OutOfBlinkCors')
|
||||
|
||||
app.commandLine.appendSwitch('enable-accelerated-video-decode')
|
||||
app.commandLine.appendSwitch('ignore-gpu-blacklist')
|
||||
app.commandLine.appendSwitch('enable-accelerated-video-decode')
|
||||
app.commandLine.appendSwitch('ignore-gpu-blacklist')
|
||||
|
||||
// See: https://stackoverflow.com/questions/45570589/electron-protocol-handler-not-working-on-windows
|
||||
// remove so we can register each time as we run the app.
|
||||
app.removeAsDefaultProtocolClient('freetube')
|
||||
// See: https://stackoverflow.com/questions/45570589/electron-protocol-handler-not-working-on-windows
|
||||
// remove so we can register each time as we run the app.
|
||||
app.removeAsDefaultProtocolClient('freetube')
|
||||
|
||||
// If we are running a non-packaged version of the app && on windows
|
||||
if (isDev && process.platform === 'win32') {
|
||||
// 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.
|
||||
// These two additional parameters are only available on windows.
|
||||
app.setAsDefaultProtocolClient('freetube', process.execPath, [path.resolve(process.argv[1])])
|
||||
} else {
|
||||
} else {
|
||||
app.setAsDefaultProtocolClient('freetube')
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Uncomment if needed
|
||||
// only allow single instance of application
|
||||
if (!isDev) {
|
||||
// TODO: Uncomment if needed
|
||||
// only allow single instance of application
|
||||
if (!isDev) {
|
||||
const gotTheLock = app.requestSingleInstanceLock()
|
||||
|
||||
if (gotTheLock) {
|
||||
|
@ -134,7 +142,7 @@ if (!isDev) {
|
|||
} else {
|
||||
app.quit()
|
||||
}
|
||||
} else {
|
||||
} else {
|
||||
require('electron-debug')({
|
||||
showDevTools: !(process.env.RENDERER_REMOTE_DEBUGGING === 'true')
|
||||
})
|
||||
|
@ -201,9 +209,9 @@ if (!isDev) {
|
|||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
async function installDevTools () {
|
||||
async function installDevTools () {
|
||||
try {
|
||||
/* eslint-disable */
|
||||
require('devtron').install()
|
||||
|
@ -212,9 +220,9 @@ async function installDevTools () {
|
|||
} catch (err) {
|
||||
console.log(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function createWindow (useProxy = false, proxyUrl = '') {
|
||||
function createWindow (useProxy = false, proxyUrl = '') {
|
||||
/**
|
||||
* Initial window options
|
||||
*/
|
||||
|
@ -359,9 +367,9 @@ function createWindow (useProxy = false, proxyUrl = '') {
|
|||
ipcMain.on('disableProxy', () => {
|
||||
mainWindow.webContents.session.setProxy({})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
app.on('window-all-closed', () => {
|
||||
app.on('window-all-closed', () => {
|
||||
if (process.platform !== 'darwin') {
|
||||
app.quit()
|
||||
}
|
||||
|
@ -379,18 +387,18 @@ app.on('window-all-closed', () => {
|
|||
'cachestorage'
|
||||
]
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
app.on('activate', () => {
|
||||
app.on('activate', () => {
|
||||
if (mainWindow === null) {
|
||||
createWindow()
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
/*
|
||||
/*
|
||||
* Callback when processing a freetube:// link (macOS)
|
||||
*/
|
||||
app.on('open-url', (event, url) => {
|
||||
app.on('open-url', (event, url) => {
|
||||
event.preventDefault()
|
||||
|
||||
if (mainWindow && mainWindow.webContents) {
|
||||
|
@ -398,30 +406,30 @@ app.on('open-url', (event, url) => {
|
|||
} else {
|
||||
startupUrl = baseUrl(url)
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
/*
|
||||
/*
|
||||
* Check if an argument was passed and send it over to the GUI (Linux / Windows).
|
||||
* Remove freetube:// protocol if present
|
||||
*/
|
||||
const url = getLinkUrl(process.argv)
|
||||
if (url) {
|
||||
const url = getLinkUrl(process.argv)
|
||||
if (url) {
|
||||
startupUrl = url
|
||||
}
|
||||
}
|
||||
|
||||
function baseUrl(arg) {
|
||||
function baseUrl(arg) {
|
||||
return arg.replace('freetube://', '')
|
||||
}
|
||||
}
|
||||
|
||||
function getLinkUrl(argv) {
|
||||
function getLinkUrl(argv) {
|
||||
if (argv.length > 1) {
|
||||
return baseUrl(argv[argv.length - 1])
|
||||
} else {
|
||||
return null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Auto Updater
|
||||
*
|
||||
* Uncomment the following code below and install `electron-updater` to
|
||||
|
@ -429,31 +437,31 @@ function getLinkUrl(argv) {
|
|||
* https://simulatedgreg.gitbooks.io/electron-vue/content/en/using-electron-builder.html#auto-updating
|
||||
*/
|
||||
|
||||
/*
|
||||
import { autoUpdater } from 'electron-updater'
|
||||
autoUpdater.on('update-downloaded', () => {
|
||||
/*
|
||||
import { autoUpdater } from 'electron-updater'
|
||||
autoUpdater.on('update-downloaded', () => {
|
||||
autoUpdater.quitAndInstall()
|
||||
})
|
||||
})
|
||||
|
||||
app.on('ready', () => {
|
||||
app.on('ready', () => {
|
||||
if (process.env.NODE_ENV === 'production') autoUpdater.checkForUpdates()
|
||||
})
|
||||
})
|
||||
*/
|
||||
|
||||
/* eslint-disable-next-line */
|
||||
const sendMenuEvent = async data => {
|
||||
/* eslint-disable-next-line */
|
||||
const sendMenuEvent = async data => {
|
||||
mainWindow.webContents.send('change-view', data)
|
||||
}
|
||||
}
|
||||
|
||||
const template = [{
|
||||
const template = [{
|
||||
label: 'File',
|
||||
submenu: [
|
||||
{
|
||||
role: 'quit'
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
},
|
||||
{
|
||||
label: 'Edit',
|
||||
submenu: [{
|
||||
role: 'cut'
|
||||
|
@ -478,8 +486,8 @@ const template = [{
|
|||
role: 'selectall'
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
},
|
||||
{
|
||||
label: 'View',
|
||||
submenu: [{
|
||||
role: 'reload'
|
||||
|
@ -510,8 +518,8 @@ const template = [{
|
|||
role: 'togglefullscreen'
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
},
|
||||
{
|
||||
role: 'window',
|
||||
submenu: [{
|
||||
role: 'minimize'
|
||||
|
@ -520,10 +528,10 @@ const template = [{
|
|||
role: 'close'
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
|
||||
function setMenu () {
|
||||
function setMenu () {
|
||||
if (process.platform === 'darwin') {
|
||||
template.unshift({
|
||||
label: app.getName(),
|
||||
|
@ -553,4 +561,5 @@ function setMenu () {
|
|||
|
||||
const menu = Menu.buildFromTemplate(template)
|
||||
Menu.setApplicationMenu(menu)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue