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