2019-10-01 13:49:56 +00:00
"use strict" ;
Object . defineProperty ( exports , "__esModule" , { value : true } ) ;
const path = require ( "path" ) ;
const electron = require ( "electron" ) ;
const events _1 = require ( "events" ) ;
const bindings = process . electronBinding ( 'app' ) ;
const commandLine = process . electronBinding ( 'command_line' ) ;
const { app , App } = bindings ;
2019-01-17 18:22:05 +00:00
// Only one app object permitted.
2019-10-01 13:49:56 +00:00
exports . default = app ;
const { deprecate , Menu } = electron ;
let dockMenu = null ;
2019-01-17 18:22:05 +00:00
// App is an EventEmitter.
2019-10-01 13:49:56 +00:00
Object . setPrototypeOf ( App . prototype , events _1 . EventEmitter . prototype ) ;
events _1 . EventEmitter . call ( app ) ;
2019-01-17 18:22:05 +00:00
Object . assign ( app , {
2019-10-01 13:49:56 +00:00
// TODO(codebytere): remove in 7.0
setApplicationMenu ( menu ) {
return Menu . setApplicationMenu ( menu ) ;
2019-01-17 18:22:05 +00:00
} ,
2019-10-01 13:49:56 +00:00
// TODO(codebytere): remove in 7.0
getApplicationMenu ( ) {
return Menu . getApplicationMenu ( ) ;
} ,
commandLine : {
hasSwitch : ( theSwitch ) => commandLine . hasSwitch ( String ( theSwitch ) ) ,
getSwitchValue : ( theSwitch ) => commandLine . getSwitchValue ( String ( theSwitch ) ) ,
appendSwitch : ( theSwitch , value ) => commandLine . appendSwitch ( String ( theSwitch ) , typeof value === 'undefined' ? value : String ( value ) ) ,
appendArgument : ( arg ) => commandLine . appendArgument ( String ( arg ) )
} ,
enableMixedSandbox ( ) {
deprecate . log ( ` 'enableMixedSandbox' is deprecated. Mixed-sandbox mode is now enabled by default. You can safely remove the call to enableMixedSandbox(). ` ) ;
2019-01-17 18:22:05 +00:00
}
2019-10-01 13:49:56 +00:00
} ) ;
// we define this here because it'd be overly complicated to
// do in native land
Object . defineProperty ( app , 'applicationMenu' , {
get ( ) {
return Menu . getApplicationMenu ( ) ;
} ,
set ( menu ) {
return Menu . setApplicationMenu ( menu ) ;
2019-01-17 18:22:05 +00:00
}
2019-10-01 13:49:56 +00:00
} ) ;
2019-01-17 18:22:05 +00:00
app . isPackaged = ( ( ) => {
2019-10-01 13:49:56 +00:00
const execFile = path . basename ( process . execPath ) . toLowerCase ( ) ;
if ( process . platform === 'win32' ) {
return execFile !== 'electron.exe' ;
}
return execFile !== 'electron' ;
} ) ( ) ;
app . _setDefaultAppPaths = ( packagePath ) => {
// Set the user path according to application's name.
app . setPath ( 'userData' , path . join ( app . getPath ( 'appData' ) , app . getName ( ) ) ) ;
app . setPath ( 'userCache' , path . join ( app . getPath ( 'cache' ) , app . getName ( ) ) ) ;
app . setAppPath ( packagePath ) ;
// Add support for --user-data-dir=
const userDataDirFlag = '--user-data-dir=' ;
const userDataArg = process . argv . find ( arg => arg . startsWith ( userDataDirFlag ) ) ;
if ( userDataArg ) {
const userDataDir = userDataArg . substr ( userDataDirFlag . length ) ;
if ( path . isAbsolute ( userDataDir ) )
app . setPath ( 'userData' , userDataDir ) ;
}
} ;
2019-01-17 18:22:05 +00:00
if ( process . platform === 'darwin' ) {
2019-10-01 13:49:56 +00:00
const setDockMenu = app . dock . setMenu ;
app . dock . setMenu = ( menu ) => {
dockMenu = menu ;
setDockMenu ( menu ) ;
} ;
app . dock . getMenu = ( ) => dockMenu ;
2019-01-17 18:22:05 +00:00
}
// Routes the events to webContents.
2019-10-01 13:49:56 +00:00
const events = [ 'login' , 'certificate-error' , 'select-client-certificate' ] ;
2019-01-17 18:22:05 +00:00
for ( const name of events ) {
2019-10-01 13:49:56 +00:00
app . on ( name , ( event , webContents , ... args ) => {
webContents . emit ( name , event , ... args ) ;
} ) ;
2019-01-17 18:22:05 +00:00
}
2019-10-01 13:49:56 +00:00
// Function Deprecations
app . getFileIcon = deprecate . promisify ( app . getFileIcon ) ;
// Property Deprecations
deprecate . fnToProperty ( app , 'accessibilitySupportEnabled' , '_isAccessibilitySupportEnabled' , '_setAccessibilitySupportEnabled' ) ;
2019-01-17 18:22:05 +00:00
// Wrappers for native classes.
2019-10-01 13:49:56 +00:00
const { DownloadItem } = process . electronBinding ( 'download_item' ) ;
Object . setPrototypeOf ( DownloadItem . prototype , events _1 . EventEmitter . prototype ) ;