nsIAppStartup 编辑

toolkit/components/startup/public/nsIAppStartup.idlScriptable This interface is intended to be used as application startup service. It also helps in quitting applications as well. 1.0 66 Introduced Gecko 1.8 Inherits from: nsISupports Last changed in Gecko 9.0 (Firefox 9.0 / Thunderbird 9.0 / SeaMonkey 2.6)

Implemented by: @mozilla.org/toolkit/app-startup;1. To use the service:

var appStartup = Components.classes["@mozilla.org/toolkit/app-startup;1"]
                 .getService(Components.interfaces.nsIAppStartup);

Method overview

void createHiddenWindow();
boolean createStartupState(in long aWindowWidth, in long aWindowHeight); Obsolete since Gecko 1.9.1
void destroyHiddenWindow();
void doProfileStartup(in nsICmdLineService aCmdLineService, in boolean canInteract); Obsolete since Gecko 1.9.1
void ensure1Window(in nsICmdLineService aCmdLineService); Obsolete since Gecko 1.9.1
void enterLastWindowClosingSurvivalArea();
void exitLastWindowClosingSurvivalArea();
void getStartupInfo();
void hideSplashScreen(); Obsolete since Gecko 1.9.1
void initialize(in nsISupports nativeAppSupportOrSplashScreen); Obsolete since Gecko 1.9.1
void quit(in PRUint32 aMode);
void restartInSafeMode(in PRUint32 aQuitMode);
void run();

Attributes

AttributeTypeDescription
interruptedbooleantrue if the startup process was interrupted by an interactive prompt. This can be used, for example, when doing performance testing of the startup process to discount numbers for tests that were interrupted by a user prompt.
nativeAppSupportnsINativeAppSupportGetter for "native application support." Read only. Obsolete since Gecko 1.9.1

Constants

The following flags may be passed as the aMode parameter to the quit() method. One and only one of the "Quit" flags must be specified. The eRestart flag may be bit-wise combined with one of the "Quit" flags to cause the application to restart after it quits.

ConstantValueDescription
eConsiderQuit0x01Attempt to quit if all windows are closed.
eAttemptQuit0x02Try to close all windows, then quit if successful.
eForceQuit0x03Force all windows to close, then quit.
eRestart0x10Restart the application after quitting. The application will be restarted with the same profile and an empty command line.
eRestartNotSameProfile0x100Restart the application after quitting. The application will be restarted with an empty command line and the normal profile selection process will take place on startup.

Methods

createHiddenWindow()

Create the hidden window.

void createHiddenWindow();
Parameters

None.

createStartupState()

Obsolete since Gecko 1.9.1 (Firefox 3.5 / Thunderbird 3.0 / SeaMonkey 2.0)

Creates the initial state of the application by launching tasks specfied by "general.startup.*" prefs.

Note: SIZE_TO_CONTENT may be used for width or height.
boolean createStartupState(
  in long aWindowWidth,
  in long aWindowHeight
);
Parameters
aWindowWidth
The width to make the initial window(s) opened.
aWindowHeight
The height to make the initial window(s) opened.
Return value

TRUE if a window was opened.

destroyHiddenWindow()

Destroys the hidden window. This will have no effect if the hidden window has not yet been created.

void destroyHiddenWindow();
Parameters

None.

doProfileStartup()

Obsolete since Gecko 1.9.1 (Firefox 3.5 / Thunderbird 3.0 / SeaMonkey 2.0)

Starts up the profile manager with the given arguments.

void doProfileStartup(
  in nsICmdLineService aCmdLineService,
  in boolean canInteract
);
Parameters
aCmdLineService
The arguments given to the program.
canInteract
If FALSE and UI is needed, will fail.

ensure1Window()

Obsolete since Gecko 1.9.1 (Firefox 3.5 / Thunderbird 3.0 / SeaMonkey 2.0)

Ensures that at least one window exists after creating the startup state. If one has not been made, this will create a browser window.

void ensure1Window(
  in nsICmdLineService aCmdLineService
);
Parameters
aCmdLineService
The command line from which startup args can be read.

enterLastWindowClosingSurvivalArea()

Serves for situations when all application windows will be closed but we don't want to take this as a signal to quit the application. Bracket the code where the last window could close with these.

void enterLastWindowClosingSurvivalArea();
Parameters

None.

exitLastWindowClosingSurvivalArea()

This method serves for situations when all application windows will be closed but we don't want to take this as a signal to quit the application. Bracket the code where the last window could close with these.

void exitLastWindowClosingSurvivalArea();
Parameters

None.

getStartupInfo()

Returns a JavaScript object with events from startup and the timestamps indicating when they occurred.

Parameters

None.

Return value

A JavaScript object with the following fields. Keys are the event names and their values are the times. Events that didn't occur are not in the object.

Event identifier (key)Description
main

Time at which main application core was loaded.

Note: Only available with libxul builds.
firstPaint

Time  the first paint occurred.

Note: Only available with libxul builds.
sessionRestoredTime  session restore finished.
Example

This example logs startup time information to the console.

var aConsoleService = Components.classes["@mozilla.org/consoleservice;1"]
                      .getService(Components.interfaces.nsIConsoleService);
var startupInfo = Components.classes["@mozilla.org/toolkit/app-startup;1"]
                      .getService(Ci.nsIAppStartup_MOZILLA_2_0).getStartupInfo();

var keys = Object.keys(startupInfo);

keys.sort(function(a, b) { return startupInfo[a] - startupInfo[b]; });

for each (var name in keys) {
  aConsoleService.logStringMessage(name + ": " + startupInfo[name]);
}

To calculate how long startup took, compute the difference between the event's timestamp and the timestamp of the process event.

hideSplashScreen()

Obsolete since Gecko 1.9.1 (Firefox 3.5 / Thunderbird 3.0 / SeaMonkey 2.0)

Remove the splash screen (if visible). This need be called only once per application session.

void hideSplashScreen();
Parameters

None.

initialize()

Obsolete since Gecko 1.9.1 (Firefox 3.5 / Thunderbird 3.0 / SeaMonkey 2.0)

Required initialization routine.

void initialize(
  in nsISupports nativeAppSupportOrSplashScreen
);
Parameters
nativeAppSupportOrSplashScreen
Is an object that can be QI'd to either an nsINativeAppSupport or nsISplashScreen; this object will be used to implement HideSplashScreen.

quit()

Exit the event loop, and shut down the application.

void quit(
  in PRUint32 aMode
);
Parameters
aMode
This parameter modifies how the application is shutdown, and it is constructed from the constants defined above.

restartInSafeMode()

Restart the application in safe mode.

void quit(
  in PRUint32 aQuitMode
);
Parameters
aQuitMode
This parameter modifies how the app is shutdown.

run()

Runs an application event loop: normally the main event pump which defines the lifetime of the application. If there are no windows open and no outstanding calls to enterLastWindowClosingSurvivalArea() this method will exit immediately.

void run();
Parameters

None.

Return value

Returns NS_SUCCESS_RESTART_APP code. This return code indicates that the application should be restarted because quit was called with the eRestart flag.

See also

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:102 次

字数:14244

最后编辑:7年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文