2021-05-21 23:49:48 +00:00
|
|
|
import {
|
2021-06-16 03:50:30 +00:00
|
|
|
app, BrowserWindow, dialog, Menu, ipcMain,
|
|
|
|
powerSaveBlocker, screen, session, shell
|
2021-05-21 23:49:48 +00:00
|
|
|
} from 'electron'
|
2021-06-17 03:16:52 +00:00
|
|
|
import Datastore from 'nedb-promises'
|
2021-06-07 00:38:06 +00:00
|
|
|
import path from 'path'
|
2021-06-13 15:31:43 +00:00
|
|
|
import cp from 'child_process'
|
2020-02-16 18:30:00 +00:00
|
|
|
|
2021-03-07 16:07:09 +00:00
|
|
|
if (process.argv.includes('--version')) {
|
|
|
|
console.log(`v${app.getVersion()}`)
|
2021-06-07 00:38:06 +00:00
|
|
|
app.exit()
|
2020-10-15 13:33:25 +00:00
|
|
|
} else {
|
2021-03-07 16:07:09 +00:00
|
|
|
runApp()
|
2020-10-15 13:33:25 +00:00
|
|
|
}
|
2020-10-04 20:31:07 +00:00
|
|
|
|
2021-03-07 16:07:09 +00:00
|
|
|
function runApp() {
|
|
|
|
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
|
|
|
|
|
2021-06-17 03:16:52 +00:00
|
|
|
const settingsDb = Datastore.create({
|
2021-03-07 16:07:09 +00:00
|
|
|
filename: localDataStorage + '/settings.db',
|
|
|
|
autoload: true
|
|
|
|
})
|
|
|
|
|
|
|
|
// disable electron warning
|
|
|
|
process.env.ELECTRON_DISABLE_SECURITY_WARNINGS = 'true'
|
|
|
|
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')
|
|
|
|
|
|
|
|
app.commandLine.appendSwitch('enable-accelerated-video-decode')
|
2021-04-08 03:07:15 +00:00
|
|
|
app.commandLine.appendSwitch('enable-file-cookies')
|
2021-03-07 16:07:09 +00:00
|
|
|
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')
|
|
|
|
|
|
|
|
// 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 {
|
|
|
|
app.setAsDefaultProtocolClient('freetube')
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!isDev) {
|
2021-06-07 00:38:06 +00:00
|
|
|
// Only allow single instance of the application
|
2021-03-07 16:07:09 +00:00
|
|
|
const gotTheLock = app.requestSingleInstanceLock()
|
2021-06-07 00:38:06 +00:00
|
|
|
if (!gotTheLock) {
|
|
|
|
app.quit()
|
|
|
|
}
|
2021-03-07 16:07:09 +00:00
|
|
|
|
2021-06-07 00:38:06 +00:00
|
|
|
app.on('second-instance', (_, commandLine, __) => {
|
|
|
|
// Someone tried to run a second instance, we should focus our window
|
|
|
|
if (mainWindow && typeof commandLine !== 'undefined') {
|
|
|
|
if (mainWindow.isMinimized()) mainWindow.restore()
|
|
|
|
mainWindow.focus()
|
2021-03-07 16:07:09 +00:00
|
|
|
|
2021-06-07 00:38:06 +00:00
|
|
|
const url = getLinkUrl(commandLine)
|
|
|
|
if (url) {
|
|
|
|
mainWindow.webContents.send('openUrl', url)
|
2020-10-15 13:33:25 +00:00
|
|
|
}
|
2021-06-07 00:38:06 +00:00
|
|
|
}
|
|
|
|
})
|
2021-03-07 16:07:09 +00:00
|
|
|
} else {
|
|
|
|
require('electron-debug')({
|
|
|
|
showDevTools: !(process.env.RENDERER_REMOTE_DEBUGGING === 'true')
|
2020-10-04 20:31:07 +00:00
|
|
|
})
|
2021-06-07 00:38:06 +00:00
|
|
|
}
|
2020-10-04 20:31:07 +00:00
|
|
|
|
2021-06-17 03:16:52 +00:00
|
|
|
app.on('ready', async (_, __) => {
|
|
|
|
let docArray
|
|
|
|
try {
|
|
|
|
docArray = await settingsDb.find({
|
|
|
|
$or: [
|
|
|
|
{ _id: 'disableSmoothScrolling' },
|
|
|
|
{ _id: 'useProxy' },
|
|
|
|
{ _id: 'proxyProtocol' },
|
|
|
|
{ _id: 'proxyHostname' },
|
|
|
|
{ _id: 'proxyPort' }
|
|
|
|
]
|
|
|
|
})
|
|
|
|
} catch (err) {
|
|
|
|
console.error(err)
|
|
|
|
app.exit()
|
|
|
|
return
|
|
|
|
}
|
2020-10-07 13:57:22 +00:00
|
|
|
|
2021-06-17 03:16:52 +00:00
|
|
|
let disableSmoothScrolling = false
|
|
|
|
let useProxy = false
|
|
|
|
let proxyProtocol = 'socks5'
|
|
|
|
let proxyHostname = '127.0.0.1'
|
|
|
|
let proxyPort = '9050'
|
|
|
|
|
|
|
|
if (docArray?.length > 0) {
|
|
|
|
docArray.forEach((doc) => {
|
|
|
|
switch (doc._id) {
|
|
|
|
case 'disableSmoothScrolling':
|
|
|
|
disableSmoothScrolling = doc.value
|
|
|
|
break
|
|
|
|
case 'useProxy':
|
|
|
|
useProxy = doc.value
|
|
|
|
break
|
|
|
|
case 'proxyProtocol':
|
|
|
|
proxyProtocol = doc.value
|
|
|
|
break
|
|
|
|
case 'proxyHostname':
|
|
|
|
proxyHostname = doc.value
|
|
|
|
break
|
|
|
|
case 'proxyPort':
|
|
|
|
proxyPort = doc.value
|
|
|
|
break
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2021-01-14 18:51:33 +00:00
|
|
|
|
2021-06-17 03:16:52 +00:00
|
|
|
if (disableSmoothScrolling) {
|
|
|
|
app.commandLine.appendSwitch('disable-smooth-scrolling')
|
|
|
|
} else {
|
|
|
|
app.commandLine.appendSwitch('enable-smooth-scrolling')
|
|
|
|
}
|
2020-10-07 13:57:22 +00:00
|
|
|
|
2021-06-17 03:16:52 +00:00
|
|
|
if (useProxy) {
|
|
|
|
session.defaultSession.setProxy({
|
|
|
|
proxyRules: `${proxyProtocol}://${proxyHostname}:${proxyPort}`
|
|
|
|
})
|
|
|
|
}
|
2021-01-14 18:51:33 +00:00
|
|
|
|
2021-06-17 03:16:52 +00:00
|
|
|
// Set CONSENT cookie on reasonable domains
|
|
|
|
const consentCookieDomains = [
|
|
|
|
'http://www.youtube.com',
|
|
|
|
'https://www.youtube.com',
|
|
|
|
'http://youtube.com',
|
|
|
|
'https://youtube.com'
|
|
|
|
]
|
|
|
|
consentCookieDomains.forEach(url => {
|
|
|
|
session.defaultSession.cookies.set({
|
|
|
|
url: url,
|
|
|
|
name: 'CONSENT',
|
|
|
|
value: 'YES+'
|
2021-06-16 04:03:46 +00:00
|
|
|
})
|
2021-06-17 03:16:52 +00:00
|
|
|
})
|
2021-06-16 04:03:46 +00:00
|
|
|
|
2021-06-17 03:16:52 +00:00
|
|
|
await createWindow()
|
2020-10-07 13:57:22 +00:00
|
|
|
|
2021-06-17 03:16:52 +00:00
|
|
|
if (isDev) {
|
|
|
|
installDevTools()
|
|
|
|
}
|
2020-10-07 13:57:22 +00:00
|
|
|
|
2021-06-17 03:16:52 +00:00
|
|
|
if (isDebug) {
|
|
|
|
mainWindow.webContents.openDevTools()
|
|
|
|
}
|
2021-06-07 00:38:06 +00:00
|
|
|
})
|
2020-10-04 20:31:07 +00:00
|
|
|
|
2021-06-07 00:38:06 +00:00
|
|
|
async function installDevTools() {
|
2021-03-07 16:07:09 +00:00
|
|
|
try {
|
|
|
|
/* eslint-disable */
|
|
|
|
require('vue-devtools').install()
|
|
|
|
/* eslint-enable */
|
|
|
|
} catch (err) {
|
|
|
|
console.log(err)
|
|
|
|
}
|
|
|
|
}
|
2020-10-04 20:31:07 +00:00
|
|
|
|
2021-06-17 03:16:52 +00:00
|
|
|
async function createWindow(replaceMainWindow = true) {
|
2021-03-07 16:07:09 +00:00
|
|
|
/**
|
|
|
|
* Initial window options
|
|
|
|
*/
|
2021-04-15 18:28:35 +00:00
|
|
|
const newWindow = new BrowserWindow({
|
2021-03-07 16:07:09 +00:00
|
|
|
backgroundColor: '#fff',
|
|
|
|
icon: isDev
|
|
|
|
? path.join(__dirname, '../../_icons/iconColor.png')
|
|
|
|
/* eslint-disable-next-line */
|
|
|
|
: `${__dirname}/_icons/iconColor.png`,
|
|
|
|
autoHideMenuBar: true,
|
|
|
|
// useContentSize: true,
|
|
|
|
webPreferences: {
|
|
|
|
nodeIntegration: true,
|
|
|
|
nodeIntegrationInWorker: false,
|
|
|
|
webSecurity: false,
|
|
|
|
backgroundThrottling: false,
|
|
|
|
contextIsolation: false
|
|
|
|
},
|
|
|
|
show: false
|
|
|
|
})
|
2021-07-03 02:38:41 +00:00
|
|
|
|
2021-04-15 18:28:35 +00:00
|
|
|
if (replaceMainWindow) {
|
|
|
|
mainWindow = newWindow
|
|
|
|
}
|
2021-01-14 18:51:33 +00:00
|
|
|
|
2021-04-15 18:28:35 +00:00
|
|
|
newWindow.setBounds({
|
2021-03-07 16:07:09 +00:00
|
|
|
width: 1200,
|
|
|
|
height: 800
|
|
|
|
})
|
2020-10-04 20:31:07 +00:00
|
|
|
|
2021-06-17 03:16:52 +00:00
|
|
|
const boundsDoc = await settingsDb.findOne({ _id: 'bounds' })
|
|
|
|
if (typeof boundsDoc?.value === 'object') {
|
|
|
|
const { maximized, ...bounds } = boundsDoc.value
|
2021-03-07 16:07:09 +00:00
|
|
|
const allDisplaysSummaryWidth = screen
|
|
|
|
.getAllDisplays()
|
|
|
|
.reduce((accumulator, { size: { width } }) => accumulator + width, 0)
|
|
|
|
|
|
|
|
if (allDisplaysSummaryWidth >= bounds.x) {
|
2021-04-15 18:28:35 +00:00
|
|
|
newWindow.setBounds({
|
2021-03-07 16:07:09 +00:00
|
|
|
x: bounds.x,
|
|
|
|
y: bounds.y,
|
|
|
|
width: bounds.width,
|
|
|
|
height: bounds.height
|
|
|
|
})
|
|
|
|
}
|
|
|
|
if (maximized) {
|
2021-04-15 18:28:35 +00:00
|
|
|
newWindow.maximize()
|
2020-10-07 13:57:22 +00:00
|
|
|
}
|
2021-06-17 03:16:52 +00:00
|
|
|
}
|
2020-02-16 18:30:00 +00:00
|
|
|
|
2021-04-15 18:28:35 +00:00
|
|
|
// If called multiple times
|
|
|
|
// Duplicate menu items will be added
|
|
|
|
if (replaceMainWindow) {
|
|
|
|
// eslint-disable-next-line
|
|
|
|
setMenu()
|
|
|
|
}
|
2020-02-16 18:30:00 +00:00
|
|
|
|
2021-03-07 16:07:09 +00:00
|
|
|
// load root file/url
|
|
|
|
if (isDev) {
|
2021-04-15 18:28:35 +00:00
|
|
|
newWindow.loadURL('http://localhost:9080')
|
2021-03-07 16:07:09 +00:00
|
|
|
} else {
|
2020-10-27 17:47:40 +00:00
|
|
|
/* eslint-disable-next-line */
|
2021-04-15 18:28:35 +00:00
|
|
|
newWindow.loadFile(`${__dirname}/index.html`)
|
2020-02-16 18:30:00 +00:00
|
|
|
|
2021-03-07 16:07:09 +00:00
|
|
|
global.__static = path
|
|
|
|
.join(__dirname, '/static')
|
|
|
|
.replace(/\\/g, '\\\\')
|
|
|
|
}
|
2020-09-20 18:54:23 +00:00
|
|
|
|
2021-03-07 16:07:09 +00:00
|
|
|
// Show when loaded
|
2021-07-03 02:44:23 +00:00
|
|
|
newWindow.once('ready-to-show', () => {
|
2021-04-15 18:28:35 +00:00
|
|
|
newWindow.show()
|
|
|
|
newWindow.focus()
|
2021-01-14 18:51:33 +00:00
|
|
|
})
|
|
|
|
|
2021-07-03 02:43:49 +00:00
|
|
|
newWindow.once('close', async () => {
|
|
|
|
if (BrowserWindow.getAllWindows().length !== 1) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
const value = {
|
|
|
|
...newWindow.getNormalBounds(),
|
|
|
|
maximized: newWindow.isMaximized()
|
|
|
|
}
|
|
|
|
|
|
|
|
await settingsDb.update(
|
|
|
|
{ _id: 'bounds' },
|
|
|
|
{ _id: 'bounds', value },
|
|
|
|
{ upsert: true }
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
2021-07-03 02:38:41 +00:00
|
|
|
newWindow.once('closed', () => {
|
|
|
|
const allWindows = BrowserWindow.getAllWindows()
|
|
|
|
if (allWindows.length !== 0 && newWindow === mainWindow) {
|
2021-04-15 18:28:35 +00:00
|
|
|
// Replace mainWindow to avoid accessing `mainWindow.webContents`
|
|
|
|
// Which raises "Object has been destroyed" error
|
2021-07-03 02:38:41 +00:00
|
|
|
mainWindow = allWindows[0]
|
2021-04-15 18:28:35 +00:00
|
|
|
}
|
|
|
|
|
2021-03-07 16:07:09 +00:00
|
|
|
console.log('closed')
|
|
|
|
})
|
2021-04-15 18:28:35 +00:00
|
|
|
}
|
2020-09-20 18:54:23 +00:00
|
|
|
|
2021-07-03 02:44:23 +00:00
|
|
|
ipcMain.once('appReady', () => {
|
2021-04-15 18:28:35 +00:00
|
|
|
if (startupUrl) {
|
|
|
|
mainWindow.webContents.send('openUrl', startupUrl)
|
|
|
|
}
|
|
|
|
})
|
2020-02-16 18:30:00 +00:00
|
|
|
|
2021-07-03 02:44:23 +00:00
|
|
|
ipcMain.once('relaunchRequest', () => {
|
2021-06-16 04:30:01 +00:00
|
|
|
if (isDev) {
|
|
|
|
app.exit(parseInt(process.env.FREETUBE_RELAUNCH_EXIT_CODE))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// The AppImage and Windows portable formats must be accounted for
|
|
|
|
// because `process.execPath` points at the temporarily extracted
|
|
|
|
// executables, not the executables themselves
|
|
|
|
//
|
|
|
|
// It's possible to detect these formats and identify their
|
|
|
|
// executables' paths by checking the environmental variables
|
|
|
|
const { env: { APPIMAGE, PORTABLE_EXECUTABLE_FILE } } = process
|
|
|
|
|
|
|
|
if (!APPIMAGE) {
|
|
|
|
// If it's a Windows portable, PORTABLE_EXECUTABLE_FILE will
|
|
|
|
// hold a value.
|
|
|
|
// Otherwise, `process.execPath` should be used instead.
|
|
|
|
app.relaunch({
|
|
|
|
args: process.argv.slice(1),
|
|
|
|
execPath: PORTABLE_EXECUTABLE_FILE || process.execPath
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
// If it's an AppImage, things must be done the "hard way"
|
|
|
|
// `app.relaunch` doesn't work because of FUSE limitations
|
|
|
|
// Spawn a new process using the APPIMAGE env variable
|
|
|
|
cp.spawn(APPIMAGE, { detached: true, stdio: 'ignore' })
|
|
|
|
}
|
2020-02-16 18:30:00 +00:00
|
|
|
|
2021-06-16 04:30:01 +00:00
|
|
|
app.quit()
|
2021-04-15 18:28:35 +00:00
|
|
|
})
|
2020-02-16 18:30:00 +00:00
|
|
|
|
2021-06-16 03:50:30 +00:00
|
|
|
ipcMain.on('enableProxy', (_, url) => {
|
2021-04-15 18:28:35 +00:00
|
|
|
console.log(url)
|
2021-06-16 03:50:30 +00:00
|
|
|
session.defaultSession.setProxy({
|
2021-04-15 18:28:35 +00:00
|
|
|
proxyRules: url
|
2021-03-07 16:07:09 +00:00
|
|
|
})
|
2021-04-15 18:28:35 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
ipcMain.on('disableProxy', () => {
|
2021-06-16 03:50:30 +00:00
|
|
|
session.defaultSession.setProxy({})
|
2021-04-15 18:28:35 +00:00
|
|
|
})
|
|
|
|
|
2021-05-21 23:49:48 +00:00
|
|
|
ipcMain.on('openExternalLink', (_, url) => {
|
|
|
|
if (typeof url === 'string') shell.openExternal(url)
|
|
|
|
})
|
|
|
|
|
2021-06-20 01:42:11 +00:00
|
|
|
ipcMain.handle('getSystemLocale', () => {
|
2021-05-21 23:49:48 +00:00
|
|
|
return app.getLocale()
|
|
|
|
})
|
|
|
|
|
|
|
|
ipcMain.handle('getUserDataPath', () => {
|
|
|
|
return app.getPath('userData')
|
|
|
|
})
|
|
|
|
|
|
|
|
ipcMain.on('getUserDataPathSync', (event) => {
|
|
|
|
event.returnValue = app.getPath('userData')
|
|
|
|
})
|
|
|
|
|
|
|
|
ipcMain.handle('showOpenDialog', async (_, options) => {
|
|
|
|
return await dialog.showOpenDialog(options)
|
|
|
|
})
|
|
|
|
|
|
|
|
ipcMain.handle('showSaveDialog', async (_, options) => {
|
|
|
|
return await dialog.showSaveDialog(options)
|
|
|
|
})
|
|
|
|
|
|
|
|
ipcMain.on('stopPowerSaveBlocker', (_, id) => {
|
|
|
|
powerSaveBlocker.stop(id)
|
|
|
|
})
|
|
|
|
|
|
|
|
ipcMain.handle('startPowerSaveBlocker', (_, type) => {
|
|
|
|
return powerSaveBlocker.start(type)
|
|
|
|
})
|
|
|
|
|
2021-04-15 18:28:35 +00:00
|
|
|
ipcMain.on('createNewWindow', () => {
|
2021-06-16 04:03:46 +00:00
|
|
|
createWindow(false)
|
2021-04-15 18:28:35 +00:00
|
|
|
})
|
2020-09-20 18:54:23 +00:00
|
|
|
|
2021-06-20 18:34:11 +00:00
|
|
|
ipcMain.on('syncWindows', (event, payload) => {
|
2021-07-03 02:38:41 +00:00
|
|
|
const otherWindows = BrowserWindow.getAllWindows().filter(
|
|
|
|
(window) => {
|
|
|
|
return window.webContents.id !== event.sender.id
|
|
|
|
}
|
|
|
|
)
|
2021-06-09 04:57:35 +00:00
|
|
|
|
|
|
|
for (const window of otherWindows) {
|
2021-06-20 18:34:11 +00:00
|
|
|
window.webContents.send('syncWindows', payload)
|
2021-06-09 04:57:35 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2021-06-13 15:31:43 +00:00
|
|
|
ipcMain.on('openInExternalPlayer', (_, payload) => {
|
|
|
|
const child = cp.spawn(payload.executable, payload.args, { detached: true, stdio: 'ignore' })
|
|
|
|
child.unref()
|
|
|
|
})
|
|
|
|
|
2021-07-03 02:44:23 +00:00
|
|
|
app.once('window-all-closed', () => {
|
2021-06-16 04:08:48 +00:00
|
|
|
// Clear cache and storage if it's the last window
|
|
|
|
session.defaultSession.clearCache()
|
|
|
|
session.defaultSession.clearStorageData({
|
|
|
|
storages: [
|
|
|
|
'appcache',
|
|
|
|
'cookies',
|
|
|
|
'filesystem',
|
|
|
|
'indexdb',
|
|
|
|
'shadercache',
|
|
|
|
'websql',
|
|
|
|
'serviceworkers',
|
|
|
|
'cachestorage'
|
|
|
|
]
|
|
|
|
})
|
|
|
|
|
2021-03-07 16:07:09 +00:00
|
|
|
if (process.platform !== 'darwin') {
|
|
|
|
app.quit()
|
2020-09-20 18:54:23 +00:00
|
|
|
}
|
|
|
|
})
|
2020-02-16 18:30:00 +00:00
|
|
|
|
2021-03-07 16:07:09 +00:00
|
|
|
app.on('activate', () => {
|
2021-07-03 02:44:23 +00:00
|
|
|
if (BrowserWindow.getAllWindows().length === 0) {
|
2021-03-07 16:07:09 +00:00
|
|
|
createWindow()
|
2020-10-04 20:31:07 +00:00
|
|
|
}
|
|
|
|
})
|
2020-10-07 13:57:22 +00:00
|
|
|
|
2021-03-07 16:07:09 +00:00
|
|
|
/*
|
|
|
|
* Callback when processing a freetube:// link (macOS)
|
|
|
|
*/
|
|
|
|
app.on('open-url', (event, url) => {
|
|
|
|
event.preventDefault()
|
2021-01-14 18:51:33 +00:00
|
|
|
|
2021-03-07 16:07:09 +00:00
|
|
|
if (mainWindow && mainWindow.webContents) {
|
|
|
|
mainWindow.webContents.send('openUrl', baseUrl(url))
|
|
|
|
} else {
|
|
|
|
startupUrl = baseUrl(url)
|
|
|
|
}
|
2021-01-14 18:51:33 +00:00
|
|
|
})
|
2020-02-16 18:30:00 +00:00
|
|
|
|
2021-03-07 16:07:09 +00:00
|
|
|
/*
|
|
|
|
* 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) {
|
|
|
|
startupUrl = url
|
2020-02-16 18:30:00 +00:00
|
|
|
}
|
2020-08-21 01:20:22 +00:00
|
|
|
|
2021-03-07 16:07:09 +00:00
|
|
|
function baseUrl(arg) {
|
|
|
|
return arg.replace('freetube://', '')
|
2020-02-16 18:30:00 +00:00
|
|
|
}
|
2020-10-15 13:33:25 +00:00
|
|
|
|
2021-03-07 16:07:09 +00:00
|
|
|
function getLinkUrl(argv) {
|
|
|
|
if (argv.length > 1) {
|
|
|
|
return baseUrl(argv[argv.length - 1])
|
|
|
|
} else {
|
|
|
|
return null
|
|
|
|
}
|
2020-10-15 13:33:25 +00:00
|
|
|
}
|
|
|
|
|
2021-03-07 16:07:09 +00:00
|
|
|
/**
|
|
|
|
* Auto Updater
|
|
|
|
*
|
|
|
|
* Uncomment the following code below and install `electron-updater` to
|
|
|
|
* support auto updating. Code Signing with a valid certificate is required.
|
|
|
|
* https://simulatedgreg.gitbooks.io/electron-vue/content/en/using-electron-builder.html#auto-updating
|
|
|
|
*/
|
2020-10-15 13:33:25 +00:00
|
|
|
|
2021-03-07 16:07:09 +00:00
|
|
|
/*
|
|
|
|
import { autoUpdater } from 'electron-updater'
|
|
|
|
autoUpdater.on('update-downloaded', () => {
|
|
|
|
autoUpdater.quitAndInstall()
|
|
|
|
})
|
2020-10-15 13:33:25 +00:00
|
|
|
|
2021-03-07 16:07:09 +00:00
|
|
|
app.on('ready', () => {
|
|
|
|
if (process.env.NODE_ENV === 'production') autoUpdater.checkForUpdates()
|
|
|
|
})
|
|
|
|
*/
|
2020-02-16 18:30:00 +00:00
|
|
|
|
2021-03-07 16:07:09 +00:00
|
|
|
/* eslint-disable-next-line */
|
|
|
|
const sendMenuEvent = async data => {
|
|
|
|
mainWindow.webContents.send('change-view', data)
|
2020-02-16 18:30:00 +00:00
|
|
|
}
|
2021-03-07 16:07:09 +00:00
|
|
|
|
2021-06-07 00:38:06 +00:00
|
|
|
function setMenu() {
|
|
|
|
const template = [
|
|
|
|
{
|
|
|
|
label: 'File',
|
|
|
|
submenu: [{ role: 'quit' }]
|
|
|
|
},
|
2021-03-07 16:07:09 +00:00
|
|
|
{
|
2021-06-07 00:38:06 +00:00
|
|
|
label: 'Edit',
|
|
|
|
submenu: [
|
|
|
|
{ role: 'cut' },
|
|
|
|
{
|
|
|
|
role: 'copy',
|
|
|
|
accelerator: 'CmdOrCtrl+C',
|
|
|
|
selector: 'copy:'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
role: 'paste',
|
|
|
|
accelerator: 'CmdOrCtrl+V',
|
|
|
|
selector: 'paste:'
|
|
|
|
},
|
|
|
|
{ role: 'pasteandmatchstyle' },
|
|
|
|
{ role: 'delete' },
|
|
|
|
{ role: 'selectall' }
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: 'View',
|
|
|
|
submenu: [
|
|
|
|
{ role: 'reload' },
|
|
|
|
{
|
|
|
|
role: 'forcereload',
|
|
|
|
accelerator: 'CmdOrCtrl+Shift+R'
|
|
|
|
},
|
|
|
|
{ role: 'toggledevtools' },
|
|
|
|
{ type: 'separator' },
|
|
|
|
{ role: 'resetzoom' },
|
|
|
|
{ role: 'zoomin' },
|
|
|
|
{ role: 'zoomout' },
|
|
|
|
{ type: 'separator' },
|
|
|
|
{ role: 'togglefullscreen' }
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
role: 'window',
|
|
|
|
submenu: [
|
|
|
|
{ role: 'minimize' },
|
|
|
|
{ role: 'close' }
|
|
|
|
]
|
2021-03-07 16:07:09 +00:00
|
|
|
}
|
|
|
|
]
|
2020-02-16 18:30:00 +00:00
|
|
|
|
2021-03-07 16:07:09 +00:00
|
|
|
if (process.platform === 'darwin') {
|
|
|
|
template.unshift({
|
|
|
|
label: app.getName(),
|
|
|
|
submenu: [
|
|
|
|
{ role: 'about' },
|
|
|
|
{ type: 'separator' },
|
|
|
|
{ role: 'services' },
|
|
|
|
{ type: 'separator' },
|
|
|
|
{ role: 'hide' },
|
|
|
|
{ role: 'hideothers' },
|
|
|
|
{ role: 'unhide' },
|
|
|
|
{ type: 'separator' },
|
|
|
|
{ role: 'quit' }
|
|
|
|
]
|
|
|
|
})
|
2020-02-16 18:30:00 +00:00
|
|
|
|
2021-06-07 00:38:06 +00:00
|
|
|
template.push(
|
|
|
|
{ role: 'window' },
|
|
|
|
{ role: 'help' },
|
|
|
|
{ role: 'services' }
|
|
|
|
)
|
2021-03-07 16:07:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const menu = Menu.buildFromTemplate(template)
|
|
|
|
Menu.setApplicationMenu(menu)
|
|
|
|
}
|
2020-02-16 18:30:00 +00:00
|
|
|
}
|