App
Application class.
Header | #include "nativeui/app.h" |
Namespace | namespace nu |
Type | class |
This class represents current app and provides app wide APIs.
This class can not be created by user, you must create State
first and
then receive an instance of App
via App::GetCurrent
.
nu::State state;
nu::App* app = nu::App::GetCurrent();
Class methods
App* GetCurrent()
Return current app.
Return
App*
Methods
void SetName(std::string name)
Set the name of current app.
The app name should be something like "My App", it will be used in vairous places, such as folder name when storing user data, or key name when writing registry.
You should always call this API at the beginning of your app.
On macOS it is strong recommended to use the same name with the
CFBundleName
field of app bundle's Info.plist
file.
Parameters
std::string
name
std::string GetName() const
Return current app's name.
If App::SetName(name)
has never been called, this API will try to guess a
name from existing information, for example the executable's version info,
or the app bundle information, or the executable file's base name.
Return
std::string
Windows Linux
void SetID(std::string id)Set the application ID.
The application ID must be globally unique, and it is recommended to use something like "org.myself.myapp".
On macOS the application ID is the app bundle ID, and there is no way to change it at runtime.
On Linux the application ID will be used in various places, such as the
name of the .desktop
file,
or the base name of GSettings schemas.
On Windows the application ID is AppUserModelID
,
it is mainly used to recognize which app a process belongs to. For
UWP/Desktop Bridge apps, Windows will assign an AppUserModelID to the app
and this API should not be used.
Parameters
std::string
id
std::string GetID() const
Return the application ID.
On macOS if the app is bundled, the app bundle ID will be returned, otherwise empty string will be returned.
On Linux the ID set by SetID
will be returned.
On Windows the AppUserModelID
will be returned. If neither you or Windows ever assigned an ID to the
app, empty string will be returned.
Return
std::string
macOS
void SetApplicationMenu(scoped_refptr<MenuBar> menu)Set the application menu bar.
Parameters
macOS
MenuBar* GetApplicationMenu() constReturn the application menu bar.
Return
MenuBar*
macOS
void SetDockBadgeLabel(const std::string& label)Set the label
to be displayed in dock’s badging area.
Parameters
const std::string&
label
macOS
std::string GetDockBadgeLabel() constGet the label displayed in dock’s badging area.
Return
std::string
Windows
bool IsRunningAsUWP() constReturn whether app is running as UWP/Desktop Bridge.
On Windows the Win32 apps can run as UWP apps by using Desktop Bridge, which is required for submitting Win32 apps to Microsoft Store.
There are a few runtime differences when running apps as UWP, and this API can be used to detect the environment.
Return
bool
Windows
bool CreateStartMenuShortcut(const App::ShortcutOptions& options)Create a start menu shortcut for current user linking to current process.
This API will write the AppUserModelID
and ToastActivatorCLSID
to the
shortcut file, and the shortcut file's name will be the app's name, so it
is recommended to call App::SetID(id)
and
App::SetName(name)
before using this API.
Note that on Windows you should generally not write start menu shortcut automatically, by convention the file is commonly created by installers or users themselves. This API is usually used for testing purpose.
Parameters
const App::ShortcutOptions&
options
Return
bool
Windows
base::FilePath GetStartMenuShortcutPath() constReturn file path to the shortcut created by the App::CreateStartMenuShortcut(options)
API.
Return
base::FilePath
macOS
void Activate(bool force)Make current app the active app.
The force
parameter is normally set to false. When the Finder launches
an app, using a value of false for force
allows the app to become active
if the user waits for it to launch, but the app remains unobtrusive if the
user activates another app. Regardless of the setting of flag, there may
be a time lag before the app activates—you should not assume the app will
be active immediately after sending this message.
Parameters
bool
force
macOS
void Deactivate()Deactivate current app.
macOS
bool IsActive() constReturn whether current app is the active app.
Return
bool
macOS
void SetActivationPolicy(App::ActivationPolicy policy)Modify the app's activation policy.
Parameters
App::ActivationPolicy
policy
macOS
App::ActivationPolicy GetActivationPolicy() constReturn app's activation policy.
Return
App::ActivationPolicy