| | |
| | const electron = require( 'electron' ); |
| | const BrowserWindow = electron.BrowserWindow; |
| | const app = electron.app; |
| | const { getPath } = require( '../../lib/assets' ); |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | let screen; |
| | app.on( 'ready', () => { |
| | if ( process.platform === 'win32' ) { |
| | |
| | app.setAppUserModelId( 'com.automattic.wordpress' ); |
| | } |
| | screen = electron.screen; |
| | } ); |
| |
|
| | const Config = require( '../../lib/config' ); |
| |
|
| | |
| | |
| | |
| | const windows = { |
| | about: { |
| | file: getPath( 'about.html' ), |
| | config: 'aboutWindow', |
| | handle: null, |
| | preload: getPath( 'preload_about.js' ), |
| | }, |
| | preferences: { |
| | file: getPath( 'preferences.html' ), |
| | config: 'preferencesWindow', |
| | handle: null, |
| | preload: getPath( 'preload_preferences.js' ), |
| | }, |
| | secret: { |
| | file: getPath( 'secret.html' ), |
| | config: 'secretWindow', |
| | handle: null, |
| | preload: null, |
| | }, |
| | wapuu: { |
| | file: getPath( 'wapuu.html' ), |
| | config: 'secretWindow', |
| | full: true, |
| | handle: null, |
| | preload: null, |
| | }, |
| | }; |
| |
|
| | function setDimensions( config ) { |
| | const full = screen.getPrimaryDisplay(); |
| |
|
| | if ( config.width === 'full' ) { |
| | config.width = full.bounds.width; |
| | } |
| |
|
| | if ( config.height === 'full' ) { |
| | config.height = full.bounds.height; |
| | } |
| |
|
| | return config; |
| | } |
| |
|
| | async function openWindow( windowName ) { |
| | if ( windows[ windowName ] ) { |
| | const settings = windows[ windowName ]; |
| |
|
| | if ( settings.handle === null ) { |
| | let config = Config[ settings.config ]; |
| | config = setDimensions( config ); |
| |
|
| | const webPreferences = Object.assign( {}, config.webPreferences, { |
| | preload: windows[ windowName ].preload, |
| | contextIsolation: true, |
| | enableRemoteModule: false, |
| | nodeIntegration: false, |
| | } ); |
| | config.webPreferences = webPreferences; |
| |
|
| | windows[ windowName ].handle = new BrowserWindow( config ); |
| | windows[ windowName ].handle.setMenuBarVisibility( false ); |
| | await windows[ windowName ].handle.webContents.session.setProxy( { |
| | proxyRules: 'direct://', |
| | } ); |
| | windows[ windowName ].handle.loadURL( `file://${ settings.file }` ); |
| |
|
| | windows[ windowName ].handle.on( 'closed', function () { |
| | windows[ windowName ].handle = null; |
| | } ); |
| |
|
| | |
| | |
| | if ( config.wpDragAndDropDisabled ) { |
| | windows[ windowName ].handle.webContents.on( 'will-navigate', function ( event ) { |
| | event.preventDefault(); |
| | return false; |
| | } ); |
| | } |
| | } else { |
| | settings.handle.show(); |
| | } |
| | } |
| | } |
| |
|
| | module.exports = { |
| | openPreferences: function () { |
| | openWindow( 'preferences' ); |
| | }, |
| | openAbout: function () { |
| | openWindow( 'about' ); |
| | }, |
| | openSecret: function () { |
| | openWindow( 'secret' ); |
| | }, |
| | openWapuu: function () { |
| | openWindow( 'wapuu' ); |
| | }, |
| | }; |
| |
|