Skip to content

Commit 215d14d

Browse files
bluthenrogerwang
authored andcommitted
Improve kiosk mode in OSX by setting app presentation options
Fix nwjs#7201
1 parent 8279c31 commit 215d14d

File tree

3 files changed

+43
-2
lines changed

3 files changed

+43
-2
lines changed

src/api/nw_window_api.cc

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -772,11 +772,17 @@ ExtensionFunction::ResponseAction
772772
NwCurrentWindowInternalEnterKioskModeFunction::Run() {
773773
AppWindow* window = getAppWindow(this);
774774
window->ForcedFullscreen();
775+
#if defined(OS_MACOSX)
776+
NWSetNSAppKioskOptions();
777+
#endif
775778
return RespondNow(NoArguments());
776779
}
777780

778781
ExtensionFunction::ResponseAction
779782
NwCurrentWindowInternalLeaveKioskModeFunction::Run() {
783+
#if defined(OS_MACOSX)
784+
NWRestoreNSAppKioskOptions();
785+
#endif
780786
AppWindow* window = getAppWindow(this);
781787
window->Restore();
782788
return RespondNow(NoArguments());
@@ -785,10 +791,17 @@ NwCurrentWindowInternalLeaveKioskModeFunction::Run() {
785791
ExtensionFunction::ResponseAction
786792
NwCurrentWindowInternalToggleKioskModeFunction::Run() {
787793
AppWindow* window = getAppWindow(this);
788-
if (window->IsFullscreen() || window->IsForcedFullscreen())
794+
if (window->IsFullscreen() || window->IsForcedFullscreen()) {
795+
#if defined(OS_MACOSX)
796+
NWRestoreNSAppKioskOptions();
797+
#endif
789798
window->Restore();
790-
else
799+
} else {
791800
window->ForcedFullscreen();
801+
#if defined(OS_MACOSX)
802+
NWSetNSAppKioskOptions();
803+
#endif
804+
}
792805
return RespondNow(NoArguments());
793806
}
794807

src/nw_content_mac.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,6 @@ class NativeAppWindow;
1313

1414
std::unique_ptr<base::ListValue> NWChangeAppMenu(nw::Menu* menu);
1515
void NWSetNSWindowShowInTaskbar(extensions::NativeAppWindow* win, bool show);
16+
void NWSetNSAppKioskOptions(void);
17+
void NWRestoreNSAppKioskOptions(void);
1618
#endif

src/nw_content_mac.mm

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,29 @@ void NWSetNSWindowShowInTaskbar(extensions::NativeAppWindow* win, bool show) {
5454
gfx::SetNSWindowShowInTaskbar(nswin, show);
5555
}
5656

57+
58+
static NSApplicationPresentationOptions previousOptions = 0;
59+
static bool kiosked = false;
60+
61+
void NWSetNSAppKioskOptions(void) {
62+
if(!kiosked) {
63+
kiosked = true;
64+
previousOptions = [NSApp currentSystemPresentationOptions];
65+
}
66+
NSApplicationPresentationOptions options = NSApplicationPresentationHideDock | NSApplicationPresentationHideMenuBar | NSApplicationPresentationDisableProcessSwitching | NSApplicationPresentationDisableForceQuit | NSApplicationPresentationDisableSessionTermination | NSApplicationPresentationDisableHideApplication | NSFullScreenWindowMask | NSApplicationPresentationDisableAppleMenu;
67+
[NSApp setPresentationOptions:options];
68+
NSWindow *window = [NSApp keyWindow];
69+
[window setLevel:NSStatusWindowLevel+1];
70+
[NSApp activateIgnoringOtherApps:YES];
71+
}
72+
73+
void NWRestoreNSAppKioskOptions(void) {
74+
if (kiosked) {
75+
kiosked = false;
76+
// Or should we just use NSApplicationPresentationDefault?
77+
[NSApp setPresentationOptions:previousOptions];
78+
NSWindow *window = [NSApp keyWindow];
79+
[window setLevel:NSNormalWindowLevel];
80+
[NSApp activateIgnoringOtherApps:NO];
81+
}
82+
}

0 commit comments

Comments
 (0)