Merge pull request #1093 from Svallinn/946-version-flag

Support for version flag
This commit is contained in:
Luca Hohmann 2021-04-10 00:09:58 +02:00 committed by GitHub
commit 23c2cd65f7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 468 additions and 463 deletions

View File

@ -1,59 +1,63 @@
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)
// 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('enable-file-cookies')
app.commandLine.appendSwitch('ignore-gpu-blacklist')
app.commandLine.appendSwitch('enable-accelerated-video-decode')
app.commandLine.appendSwitch('enable-file-cookies')
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) {
@ -135,7 +139,7 @@ if (!isDev) {
} else {
app.quit()
}
} else {
} else {
require('electron-debug')({
showDevTools: !(process.env.RENDERER_REMOTE_DEBUGGING === 'true')
})
@ -202,9 +206,9 @@ if (!isDev) {
}
})
})
}
}
async function installDevTools () {
async function installDevTools () {
try {
/* eslint-disable */
require('devtron').install()
@ -213,9 +217,9 @@ async function installDevTools () {
} catch (err) {
console.log(err)
}
}
}
function createWindow (useProxy = false, proxyUrl = '') {
function createWindow (useProxy = false, proxyUrl = '') {
/**
* Initial window options
*/
@ -374,9 +378,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()
}
@ -394,18 +398,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) {
@ -413,30 +417,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
@ -444,31 +448,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'
@ -493,8 +497,8 @@ const template = [{
role: 'selectall'
}
]
},
{
},
{
label: 'View',
submenu: [{
role: 'reload'
@ -525,8 +529,8 @@ const template = [{
role: 'togglefullscreen'
}
]
},
{
},
{
role: 'window',
submenu: [{
role: 'minimize'
@ -535,10 +539,10 @@ const template = [{
role: 'close'
}
]
}
]
}
]
function setMenu () {
function setMenu () {
if (process.platform === 'darwin') {
template.unshift({
label: app.getName(),
@ -568,4 +572,5 @@ function setMenu () {
const menu = Menu.buildFromTemplate(template)
Menu.setApplicationMenu(menu)
}
}