Add protocol to enable extension support
This commit is contained in:
		
							parent
							
								
									cbb1b853b5
								
							
						
					
					
						commit
						54a3810a53
					
				|  | @ -32,6 +32,14 @@ const config = { | ||||||
|   directories: { |   directories: { | ||||||
|     output: './build/', |     output: './build/', | ||||||
|   }, |   }, | ||||||
|  |   protocols: [ | ||||||
|  |     { | ||||||
|  |       name: "FreeTube", | ||||||
|  |       schemes: [ | ||||||
|  |         "freetube" | ||||||
|  |       ] | ||||||
|  |     } | ||||||
|  |   ], | ||||||
|   files: ['_icons/iconColor.*', './dist/**/*', '!./dist/web/**/*'], |   files: ['_icons/iconColor.*', './dist/**/*', '!./dist/web/**/*'], | ||||||
|   dmg: { |   dmg: { | ||||||
|     contents: [ |     contents: [ | ||||||
|  |  | ||||||
|  | @ -21,8 +21,6 @@ app.setName(productName) | ||||||
| 
 | 
 | ||||||
| // disable electron warning
 | // disable electron warning
 | ||||||
| process.env.ELECTRON_DISABLE_SECURITY_WARNINGS = 'true' | process.env.ELECTRON_DISABLE_SECURITY_WARNINGS = 'true' | ||||||
| 
 |  | ||||||
| // const gotTheLock = app.requestSingleInstanceLock()
 |  | ||||||
| const path = require('path') | const path = require('path') | ||||||
| const isDev = process.env.NODE_ENV === 'development' | const isDev = process.env.NODE_ENV === 'development' | ||||||
| const isDebug = process.argv.includes('--debug') | const isDebug = process.argv.includes('--debug') | ||||||
|  | @ -33,26 +31,55 @@ let mainWindow | ||||||
| // This line can possible be removed if the issue is fixed upstream
 | // This line can possible be removed if the issue is fixed upstream
 | ||||||
| app.commandLine.appendSwitch('disable-features', 'OutOfBlinkCors') | app.commandLine.appendSwitch('disable-features', 'OutOfBlinkCors') | ||||||
| 
 | 
 | ||||||
|  | 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) { | ||||||
| //   if (gotTheLock) {
 |   const gotTheLock = app.requestSingleInstanceLock() | ||||||
| //     app.on('second-instance', () => {
 | 
 | ||||||
| //       // Someone tried to run a second instance, we should focus our window.
 |   if (gotTheLock) { | ||||||
| //       if (mainWindow && mainWindow.isMinimized()) {
 |     app.on('second-instance', (event, commandLine, workingDirectory) => { | ||||||
| //         mainWindow.restore()
 |       // Someone tried to run a second instance, we should focus our window.
 | ||||||
| //       }
 |       if (mainWindow && typeof (commandLine) !== 'undefined') { | ||||||
| //       mainWindow.focus()
 |         if (mainWindow.isMinimized()) mainWindow.restore() | ||||||
| //     })
 |         mainWindow.focus() | ||||||
| //   } else {
 | 
 | ||||||
| //     app.quit()
 |         mainWindow.webContents.send('ping', commandLine) | ||||||
| //     process.exit(0)
 |       } | ||||||
| //   }
 |     }) | ||||||
| // } else {
 | 
 | ||||||
| //   require('electron-debug')({
 |     app.on('ready', (event, commandLine, workingDirectory) => { | ||||||
| //     showDevTools: !(process.env.RENDERER_REMOTE_DEBUGGING === 'true')
 |       createWindow() | ||||||
| //   })
 | 
 | ||||||
| // }
 |       if (isDev) { | ||||||
|  |         installDevTools() | ||||||
|  |       } | ||||||
|  | 
 | ||||||
|  |       if (isDebug) { | ||||||
|  |         mainWindow.webContents.openDevTools() | ||||||
|  |       } | ||||||
|  |     }) | ||||||
|  |   } else { | ||||||
|  |     app.quit() | ||||||
|  |   } | ||||||
|  | } else { | ||||||
|  |   require('electron-debug')({ | ||||||
|  |     showDevTools: !(process.env.RENDERER_REMOTE_DEBUGGING === 'true') | ||||||
|  |   }) | ||||||
|  | 
 | ||||||
|  |   app.on('ready', () => { | ||||||
|  |     createWindow() | ||||||
|  | 
 | ||||||
|  |     if (isDev) { | ||||||
|  |       installDevTools() | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     if (isDebug) { | ||||||
|  |       mainWindow.webContents.openDevTools() | ||||||
|  |     } | ||||||
|  |   }) | ||||||
|  | } | ||||||
| 
 | 
 | ||||||
| async function installDevTools () { | async function installDevTools () { | ||||||
|   try { |   try { | ||||||
|  | @ -172,19 +199,14 @@ function createWindow () { | ||||||
|       } |       } | ||||||
|     }) |     }) | ||||||
|   }) |   }) | ||||||
| } |  | ||||||
| 
 | 
 | ||||||
| app.on('ready', () => { |   ipcMain.on('appReady', () => { | ||||||
|   createWindow() |     const param = process.argv[1] | ||||||
| 
 |     if (typeof (param) !== 'undefined' && param !== null) { | ||||||
|   if (isDev) { |       mainWindow.webContents.send('ping', process.argv) | ||||||
|     installDevTools() |  | ||||||
|   } |  | ||||||
| 
 |  | ||||||
|   if (isDebug) { |  | ||||||
|     mainWindow.webContents.openDevTools() |  | ||||||
|     } |     } | ||||||
|   }) |   }) | ||||||
|  | } | ||||||
| 
 | 
 | ||||||
| app.on('window-all-closed', () => { | app.on('window-all-closed', () => { | ||||||
|   if (process.platform !== 'darwin') { |   if (process.platform !== 'darwin') { | ||||||
|  | @ -222,7 +244,6 @@ app.on('activate', () => { | ||||||
| 
 | 
 | ||||||
| /* | /* | ||||||
| import { autoUpdater } from 'electron-updater' | import { autoUpdater } from 'electron-updater' | ||||||
| 
 |  | ||||||
| autoUpdater.on('update-downloaded', () => { | autoUpdater.on('update-downloaded', () => { | ||||||
|   autoUpdater.quitAndInstall() |   autoUpdater.quitAndInstall() | ||||||
| }) | }) | ||||||
|  |  | ||||||
|  | @ -1,4 +1,5 @@ | ||||||
| import Vue from 'vue' | import Vue from 'vue' | ||||||
|  | import { mapActions } from 'vuex' | ||||||
| import { ObserveVisibility } from 'vue-observe-visibility' | import { ObserveVisibility } from 'vue-observe-visibility' | ||||||
| import FtFlexBox from './components/ft-flex-box/ft-flex-box.vue' | import FtFlexBox from './components/ft-flex-box/ft-flex-box.vue' | ||||||
| import TopNav from './components/top-nav/top-nav.vue' | import TopNav from './components/top-nav/top-nav.vue' | ||||||
|  | @ -14,12 +15,14 @@ import Parser from 'rss-parser' | ||||||
| 
 | 
 | ||||||
| let useElectron | let useElectron | ||||||
| let shell | let shell | ||||||
|  | let electron | ||||||
| 
 | 
 | ||||||
| Vue.directive('observe-visibility', ObserveVisibility) | Vue.directive('observe-visibility', ObserveVisibility) | ||||||
| 
 | 
 | ||||||
| if (window && window.process && window.process.type === 'renderer') { | if (window && window.process && window.process.type === 'renderer') { | ||||||
|   /* eslint-disable-next-line */ |   /* eslint-disable-next-line */ | ||||||
|   shell = require('electron').shell |   electron = require('electron') | ||||||
|  |   shell = electron.shell | ||||||
|   useElectron = true |   useElectron = true | ||||||
| } else { | } else { | ||||||
|   useElectron = false |   useElectron = false | ||||||
|  | @ -65,6 +68,9 @@ export default Vue.extend({ | ||||||
|     }, |     }, | ||||||
|     checkForBlogPosts: function () { |     checkForBlogPosts: function () { | ||||||
|       return this.$store.getters.getCheckForBlogPosts |       return this.$store.getters.getCheckForBlogPosts | ||||||
|  |     }, | ||||||
|  |     searchSettings: function () { | ||||||
|  |       return this.$store.getters.getSearchSettings | ||||||
|     } |     } | ||||||
|   }, |   }, | ||||||
|   mounted: function () { |   mounted: function () { | ||||||
|  | @ -79,6 +85,7 @@ export default Vue.extend({ | ||||||
|       console.log('User is using Electron') |       console.log('User is using Electron') | ||||||
|       this.activateKeyboardShortcuts() |       this.activateKeyboardShortcuts() | ||||||
|       this.openAllLinksExternally() |       this.openAllLinksExternally() | ||||||
|  |       this.enableCliPing() | ||||||
|       this.setBoundsOnClose() |       this.setBoundsOnClose() | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  | @ -247,9 +254,39 @@ export default Vue.extend({ | ||||||
|       }) |       }) | ||||||
|     }, |     }, | ||||||
| 
 | 
 | ||||||
|  |     enableCliPing: function () { | ||||||
|  |       const v = this | ||||||
|  |       electron.ipcRenderer.on('ping', function (event, message) { | ||||||
|  |         console.log('ping!') | ||||||
|  |         console.log(message) | ||||||
|  |         let url = message[message.length - 1] | ||||||
|  |         if (url) { | ||||||
|  |           url = url.replace('freetube://', '') | ||||||
|  |           v.$store.dispatch('getVideoIdFromUrl', url).then((result) => { | ||||||
|  |             if (result) { | ||||||
|  |               v.$router.push({ | ||||||
|  |                 path: `/watch/${result}` | ||||||
|  |               }) | ||||||
|  |             } else { | ||||||
|  |               v.$router.push({ | ||||||
|  |                 path: `/search/${encodeURIComponent(url)}`, | ||||||
|  |                 query: { | ||||||
|  |                   sortBy: v.searchSettings.sortBy, | ||||||
|  |                   time: v.searchSettings.time, | ||||||
|  |                   type: v.searchSettings.type, | ||||||
|  |                   duration: v.searchSettings.duration | ||||||
|  |                 } | ||||||
|  |               }) | ||||||
|  |             } | ||||||
|  |           }) | ||||||
|  |         } | ||||||
|  |       }) | ||||||
|  | 
 | ||||||
|  |       electron.ipcRenderer.send('appReady') | ||||||
|  |     }, | ||||||
|  | 
 | ||||||
|     setBoundsOnClose: function () { |     setBoundsOnClose: function () { | ||||||
|       window.onbeforeunload = (e) => { |       window.onbeforeunload = (e) => { | ||||||
|         const electron = require('electron') |  | ||||||
|         electron.ipcRenderer.send('setBounds') |         electron.ipcRenderer.send('setBounds') | ||||||
|       } |       } | ||||||
|     } |     } | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue