2016-03-24 13:15:04 -07:00
'use strict'
2016-03-10 11:54:17 -08:00
2016-06-22 15:21:45 -07:00
const bindings = process . atomBinding ( 'app' )
2019-01-07 16:48:27 +01:00
const commandLine = process . atomBinding ( 'command_line' )
2018-05-07 23:15:31 -07:00
const path = require ( 'path' )
2018-09-14 02:10:51 +10:00
const { app , App } = bindings
2016-06-22 15:21:45 -07:00
// Only one app object permitted.
module . exports = app
2016-06-01 14:57:35 +09:00
const electron = require ( 'electron' )
2018-09-14 02:10:51 +10:00
const { deprecate , Menu } = electron
const { EventEmitter } = require ( 'events' )
2016-01-11 18:40:23 -08:00
2018-02-27 15:15:06 +09:00
let dockMenu = null
2017-11-01 23:05:27 -05:00
// App is an EventEmitter.
2016-08-02 20:38:35 +09:00
Object . setPrototypeOf ( App . prototype , EventEmitter . prototype )
2017-11-01 23:05:27 -05:00
EventEmitter . call ( app )
2016-01-11 18:40:23 -08:00
2016-05-14 11:17:46 -04:00
Object . assign ( app , {
2016-05-14 11:31:08 -04:00
setApplicationMenu ( menu ) {
2016-05-14 11:17:46 -04:00
return Menu . setApplicationMenu ( menu )
} ,
2016-05-14 11:31:08 -04:00
getApplicationMenu ( ) {
2016-05-14 11:17:46 -04:00
return Menu . getApplicationMenu ( )
} ,
commandLine : {
2019-01-07 16:48:27 +01:00
hasSwitch : ( ... args ) => commandLine . hasSwitch ( ... args . map ( String ) ) ,
getSwitchValue : ( ... args ) => commandLine . getSwitchValue ( ... args . map ( String ) ) ,
appendSwitch : ( ... args ) => commandLine . appendSwitch ( ... args . map ( String ) ) ,
appendArgument : ( ... args ) => commandLine . appendArgument ( ... args . map ( String ) )
2019-01-22 10:44:28 -08:00
} ,
enableMixedSandbox ( ) {
deprecate . log ( ` 'enableMixedSandbox' is deprecated. Mixed-sandbox mode is now enabled by default. You can safely remove the call to enableMixedSandbox(). ` )
2016-05-14 11:17:46 -04:00
}
} )
2016-01-11 18:40:23 -08:00
2019-01-25 14:23:24 -08:00
app . getFileIcon = deprecate . promisify ( app . getFileIcon )
2018-12-05 08:50:12 -08:00
const nativeAppMetrics = app . getAppMetrics
2018-06-26 23:47:01 -07:00
app . getAppMetrics = ( ) => {
2018-12-05 08:50:12 -08:00
const metrics = nativeAppMetrics . call ( app )
2018-07-22 00:35:41 +10:00
for ( const metric of metrics ) {
2018-09-12 17:13:22 -05:00
if ( 'memory' in metric ) {
deprecate . removeProperty ( metric , 'memory' )
}
2018-09-11 11:16:49 -07:00
}
return metrics
2018-06-26 23:47:01 -07:00
}
2018-05-07 23:15:31 -07:00
app . isPackaged = ( ( ) => {
const execFile = path . basename ( process . execPath ) . toLowerCase ( )
if ( process . platform === 'win32' ) {
return execFile !== 'electron.exe'
}
return execFile !== 'electron'
} ) ( )
2016-01-11 18:40:23 -08:00
if ( process . platform === 'darwin' ) {
app . dock = {
2016-05-14 11:17:46 -04:00
bounce ( type = 'informational' ) {
2016-03-24 13:15:04 -07:00
return bindings . dockBounce ( type )
2016-01-11 18:40:23 -08:00
} ,
cancelBounce : bindings . dockCancelBounce ,
2016-05-10 15:02:56 -04:00
downloadFinished : bindings . dockDownloadFinished ,
2016-01-11 18:40:23 -08:00
setBadge : bindings . dockSetBadgeText ,
getBadge : bindings . dockGetBadgeText ,
hide : bindings . dockHide ,
show : bindings . dockShow ,
2016-08-01 15:22:37 -07:00
isVisible : bindings . dockIsVisible ,
2018-02-27 15:15:06 +09:00
setMenu ( menu ) {
dockMenu = menu
bindings . dockSetMenu ( menu )
} ,
getMenu ( ) {
return dockMenu
} ,
2016-01-24 08:30:14 +09:00
setIcon : bindings . dockSetIcon
2016-03-24 13:15:04 -07:00
}
2016-01-11 18:40:23 -08:00
}
2016-06-26 11:48:58 +02:00
if ( process . platform === 'linux' ) {
app . launcher = {
2016-06-26 01:55:24 +02:00
setBadgeCount : bindings . unityLauncherSetBadgeCount ,
2016-06-26 11:48:58 +02:00
getBadgeCount : bindings . unityLauncherGetBadgeCount ,
2016-06-29 19:23:56 +02:00
isCounterBadgeAvailable : bindings . unityLauncherAvailable ,
isUnityRunning : bindings . unityLauncherAvailable
2016-06-26 02:00:41 +02:00
}
2016-06-26 01:55:24 +02:00
}
2016-05-23 10:59:55 +05:30
app . allowNTLMCredentialsForAllDomains = function ( allow ) {
2018-12-05 10:34:09 +01:00
deprecate . warn ( 'app.allowNTLMCredentialsForAllDomains' , 'session.allowNTLMCredentialsForDomains' )
2018-10-02 03:56:31 +02:00
const domains = allow ? '*' : ''
2016-05-23 10:59:55 +05:30
if ( ! this . isReady ( ) ) {
this . commandLine . appendSwitch ( 'auth-server-whitelist' , domains )
} else {
2016-06-01 14:57:35 +09:00
electron . session . defaultSession . allowNTLMCredentialsForDomains ( domains )
2016-05-23 10:59:55 +05:30
}
}
2016-01-14 10:35:29 -08:00
// Routes the events to webContents.
2016-05-14 11:17:46 -04:00
const events = [ 'login' , 'certificate-error' , 'select-client-certificate' ]
2018-10-02 03:56:31 +02:00
for ( const name of events ) {
2016-05-14 11:17:46 -04:00
app . on ( name , ( event , webContents , ... args ) => {
2016-12-01 14:37:03 -08:00
webContents . emit ( name , event , ... args )
2016-03-24 13:15:04 -07:00
} )
}
2016-01-11 18:40:23 -08:00
2016-01-14 10:35:29 -08:00
// Wrappers for native classes.
2018-09-14 02:10:51 +10:00
const { DownloadItem } = process . atomBinding ( 'download_item' )
2016-08-02 20:38:35 +09:00
Object . setPrototypeOf ( DownloadItem . prototype , EventEmitter . prototype )