Skip to content

Commit 24eafb2

Browse files
committed
Sync with core 367622c03: application-level show and hide
1 parent f775715 commit 24eafb2

12 files changed

Lines changed: 149 additions & 1 deletion

File tree

‎bindings/csharp/src/CNativeAPI/generated/Application.cs‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ public struct ExitingData
3232

3333
public static partial class Interop
3434
{
35+
[DllImport(Libraries.NativeApi, CallingConvention = CallingConvention.Cdecl)]
36+
[return: MarshalAs(UnmanagedType.I1)]
37+
public static extern bool native_application_hide();
38+
3539
[DllImport(Libraries.NativeApi, CallingConvention = CallingConvention.Cdecl)]
3640
[return: MarshalAs(UnmanagedType.I1)]
3741
public static extern bool native_application_is_running();
@@ -40,6 +44,10 @@ public static partial class Interop
4044
[return: MarshalAs(UnmanagedType.I1)]
4145
public static extern bool native_application_is_single_instance();
4246

47+
[DllImport(Libraries.NativeApi, CallingConvention = CallingConvention.Cdecl)]
48+
[return: MarshalAs(UnmanagedType.I1)]
49+
public static extern bool native_application_is_visible();
50+
4351
[DllImport(Libraries.NativeApi, CallingConvention = CallingConvention.Cdecl)]
4452
[return: MarshalAs(UnmanagedType.I1)]
4553
public static extern bool native_application_remove_listener(ulong listenerId);
@@ -68,6 +76,10 @@ public static partial class Interop
6876
[return: MarshalAs(UnmanagedType.I1)]
6977
public static extern bool native_application_set_progress_bar(double progress);
7078

79+
[DllImport(Libraries.NativeApi, CallingConvention = CallingConvention.Cdecl)]
80+
[return: MarshalAs(UnmanagedType.I1)]
81+
public static extern bool native_application_show();
82+
7183
[DllImport(Libraries.NativeApi, CallingConvention = CallingConvention.Cdecl)]
7284
public static extern int native_application_run();
7385

‎bindings/csharp/src/NativeAPI/Application.cs‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,24 @@ public bool IsSingleInstance()
7777
return rawResult;
7878
}
7979

80+
public bool Show()
81+
{
82+
var rawResult = Interop.native_application_show();
83+
return rawResult;
84+
}
85+
86+
public bool Hide()
87+
{
88+
var rawResult = Interop.native_application_hide();
89+
return rawResult;
90+
}
91+
92+
public bool IsVisible()
93+
{
94+
var rawResult = Interop.native_application_is_visible();
95+
return rawResult;
96+
}
97+
8098
public bool SetIcon(string iconPath)
8199
{
82100
var rawResult = Interop.native_application_set_icon(iconPath);

‎bindings/dart/cnativeapi/lib/src/bindings_generated.dart‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,18 @@ external native_window_list_t native_application_get_all_windows();
8787
@ffi.Native<native_window_t Function()>()
8888
external int native_application_get_primary_window();
8989

90+
@ffi.Native<ffi.Bool Function()>()
91+
external bool native_application_hide();
92+
9093
@ffi.Native<ffi.Bool Function()>()
9194
external bool native_application_is_running();
9295

9396
@ffi.Native<ffi.Bool Function()>()
9497
external bool native_application_is_single_instance();
9598

99+
@ffi.Native<ffi.Bool Function()>()
100+
external bool native_application_is_visible();
101+
96102
@ffi.Native<ffi.Void Function(ffi.Int)>()
97103
external void native_application_quit(int exit_code);
98104

@@ -133,6 +139,9 @@ external void native_application_set_primary_window(int window);
133139
@ffi.Native<ffi.Bool Function(ffi.Double)>()
134140
external bool native_application_set_progress_bar(double progress);
135141

142+
@ffi.Native<ffi.Bool Function()>()
143+
external bool native_application_show();
144+
136145
/// Creates a Button instance; release it with native_button_free().
137146
@ffi.Native<native_button_t Function(ffi.Pointer<ffi.Char>)>()
138147
external int native_button_create(ffi.Pointer<ffi.Char> text);

‎bindings/dart/nativeapi/CHANGELOG.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717
on Windows and Linux as well, and ends the process on Linux, as documented.
1818
On Windows it destroys the windows before the loop ends, so a Flutter app's
1919
engine shuts down cleanly instead of crashing in its teardown.
20+
* `Application.show()`, `Application.hide()` and `Application.isVisible()`:
21+
application-level hiding on macOS (`-[NSApplication hide:]`), which the Dock
22+
understands, unlike hiding every window. They return false on other
23+
platforms.
2024
* `WindowEnteredFullScreenEvent` and `WindowExitedFullScreenEvent`, on macOS
2125
and Linux whoever changes the state, on Windows for `Window.isFullScreen`.
2226
* Windows: setting `Window.titleBarStyle` on a full-screen window no longer

‎bindings/dart/nativeapi/lib/src/application.dart‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,18 @@ class Application {
127127
return c.native_application_is_single_instance();
128128
}
129129

130+
bool show() {
131+
return c.native_application_show();
132+
}
133+
134+
bool hide() {
135+
return c.native_application_hide();
136+
}
137+
138+
bool isVisible() {
139+
return c.native_application_is_visible();
140+
}
141+
130142
bool setIcon(String iconPath) {
131143
final iconPathNative = iconPath.toNativeUtf8().cast<ffi.Char>();
132144
final result = c.native_application_set_icon(iconPathNative);

‎bindings/js/lib/application.ts‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,18 @@ export class Application {
4545
return native.native_application_is_single_instance();
4646
}
4747

48+
static show(): boolean {
49+
return native.native_application_show();
50+
}
51+
52+
static hide(): boolean {
53+
return native.native_application_hide();
54+
}
55+
56+
static isVisible(): boolean {
57+
return native.native_application_is_visible();
58+
}
59+
4860
static setIcon(iconPath: string): boolean {
4961
return native.native_application_set_icon(iconPath);
5062
}

‎bindings/js/src/generated/application.cc‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,39 @@ napi_value Js_native_application_is_single_instance(napi_env env, napi_callback_
6969
return Value::Bool(result).ToJs(env);
7070
}
7171

72+
napi_value Js_native_application_show(napi_env env, napi_callback_info info) {
73+
Args args(env, info);
74+
if (!args.ok()) {
75+
return nullptr;
76+
}
77+
Arena arena;
78+
(void)arena;
79+
auto result = OnMainThread([&] { return native_application_show(); });
80+
return Value::Bool(result).ToJs(env);
81+
}
82+
83+
napi_value Js_native_application_hide(napi_env env, napi_callback_info info) {
84+
Args args(env, info);
85+
if (!args.ok()) {
86+
return nullptr;
87+
}
88+
Arena arena;
89+
(void)arena;
90+
auto result = OnMainThread([&] { return native_application_hide(); });
91+
return Value::Bool(result).ToJs(env);
92+
}
93+
94+
napi_value Js_native_application_is_visible(napi_env env, napi_callback_info info) {
95+
Args args(env, info);
96+
if (!args.ok()) {
97+
return nullptr;
98+
}
99+
Arena arena;
100+
(void)arena;
101+
auto result = OnMainThread([&] { return native_application_is_visible(); });
102+
return Value::Bool(result).ToJs(env);
103+
}
104+
72105
napi_value Js_native_application_set_icon(napi_env env, napi_callback_info info) {
73106
Args args(env, info);
74107
if (!args.ok()) {
@@ -242,6 +275,9 @@ void RegisterApplication(napi_env env, napi_value exports) {
242275
Export(env, exports, "native_application_quit", Js_native_application_quit);
243276
Export(env, exports, "native_application_is_running", Js_native_application_is_running);
244277
Export(env, exports, "native_application_is_single_instance", Js_native_application_is_single_instance);
278+
Export(env, exports, "native_application_show", Js_native_application_show);
279+
Export(env, exports, "native_application_hide", Js_native_application_hide);
280+
Export(env, exports, "native_application_is_visible", Js_native_application_is_visible);
245281
Export(env, exports, "native_application_set_icon", Js_native_application_set_icon);
246282
Export(env, exports, "native_application_set_dock_icon_visible", Js_native_application_set_dock_icon_visible);
247283
Export(env, exports, "native_application_set_progress_bar", Js_native_application_set_progress_bar);

‎bindings/python/nativeapi/_capi.py‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3635,6 +3635,9 @@ class native_window_list_t(Structure):
36353635
[
36363636
],
36373637
)
3638+
native_application_show = function("native_application_show", c_bool, [])
3639+
native_application_hide = function("native_application_hide", c_bool, [])
3640+
native_application_is_visible = function("native_application_is_visible", c_bool, [])
36383641
native_application_set_icon = function(
36393642
"native_application_set_icon",
36403643
c_bool,

‎bindings/python/nativeapi/application.py‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,21 @@ def is_single_instance() -> bool:
106106
raw = _C.native_application_is_single_instance()
107107
return raw
108108

109+
@staticmethod
110+
def show() -> bool:
111+
raw = _C.native_application_show()
112+
return raw
113+
114+
@staticmethod
115+
def hide() -> bool:
116+
raw = _C.native_application_hide()
117+
return raw
118+
119+
@staticmethod
120+
def is_visible() -> bool:
121+
raw = _C.native_application_is_visible()
122+
return raw
123+
109124
@staticmethod
110125
def set_icon(icon_path: str) -> bool:
111126
raw = _C.native_application_set_icon(_rt.encode(icon_path))

‎bindings/rust/cnativeapi/src/bindings.rs‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1638,6 +1638,15 @@ unsafe extern "C" {
16381638
unsafe extern "C" {
16391639
pub fn native_application_is_single_instance() -> bool;
16401640
}
1641+
unsafe extern "C" {
1642+
pub fn native_application_show() -> bool;
1643+
}
1644+
unsafe extern "C" {
1645+
pub fn native_application_hide() -> bool;
1646+
}
1647+
unsafe extern "C" {
1648+
pub fn native_application_is_visible() -> bool;
1649+
}
16411650
unsafe extern "C" {
16421651
pub fn native_application_set_icon(icon_path: *const ::std::os::raw::c_char) -> bool;
16431652
}

0 commit comments

Comments
 (0)