Skip to content

Commit 2c72824

Browse files
committed
Sync with core 6cfb84ae3 (expose Application log APIs)
1 parent dad97a6 commit 2c72824

19 files changed

Lines changed: 987 additions & 11 deletions

File tree

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@ public static partial class Interop
9898
[return: MarshalAs(UnmanagedType.I1)]
9999
public static extern bool native_application_set_icon([MarshalAs(UnmanagedType.LPUTF8Str)] string? iconPath);
100100

101+
[DllImport(Libraries.NativeApi, CallingConvention = CallingConvention.Cdecl)]
102+
[return: MarshalAs(UnmanagedType.I1)]
103+
public static extern bool native_application_set_log_file([MarshalAs(UnmanagedType.LPUTF8Str)] string? path);
104+
101105
[DllImport(Libraries.NativeApi, CallingConvention = CallingConvention.Cdecl)]
102106
[return: MarshalAs(UnmanagedType.I1)]
103107
public static extern bool native_application_set_menu_bar(ulong menu);
@@ -110,6 +114,12 @@ public static partial class Interop
110114
[return: MarshalAs(UnmanagedType.I1)]
111115
public static extern bool native_application_show();
112116

117+
[DllImport(Libraries.NativeApi, CallingConvention = CallingConvention.Cdecl)]
118+
public static extern IntPtr native_application_get_log_file();
119+
120+
[DllImport(Libraries.NativeApi, CallingConvention = CallingConvention.Cdecl)]
121+
public static extern int native_application_get_log_level();
122+
113123
[DllImport(Libraries.NativeApi, CallingConvention = CallingConvention.Cdecl)]
114124
public static extern int native_application_get_system_brightness();
115125

@@ -134,6 +144,9 @@ public static partial class Interop
134144
[DllImport(Libraries.NativeApi, CallingConvention = CallingConvention.Cdecl)]
135145
public static extern void native_application_release_single_instance_lock();
136146

147+
[DllImport(Libraries.NativeApi, CallingConvention = CallingConvention.Cdecl)]
148+
public static extern void native_application_set_log_level(int level);
149+
137150
[DllImport(Libraries.NativeApi, CallingConvention = CallingConvention.Cdecl)]
138151
public static extern void native_application_set_primary_window(ulong window);
139152
}

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

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,16 @@ public enum Brightness
1616
Dark = 2,
1717
}
1818

19+
public enum LogLevel
20+
{
21+
Off = 0,
22+
Error = 1,
23+
Warning = 2,
24+
Info = 3,
25+
Debug = 4,
26+
Trace = 5,
27+
}
28+
1929
/// <summary>One ApplicationEvent, in its concrete form.</summary>
2030
public abstract record ApplicationEvent
2131
{
@@ -188,6 +198,29 @@ public Window[] GetAllWindows()
188198
return items;
189199
}
190200

201+
public void SetLogLevel(LogLevel level)
202+
{
203+
Interop.native_application_set_log_level((int)level);
204+
}
205+
206+
public LogLevel GetLogLevel()
207+
{
208+
var rawResult = Interop.native_application_get_log_level();
209+
return (LogLevel)rawResult;
210+
}
211+
212+
public bool SetLogFile(string path)
213+
{
214+
var rawResult = Interop.native_application_set_log_file(path);
215+
return rawResult;
216+
}
217+
218+
public string? GetLogFile()
219+
{
220+
var rawResult = Interop.native_application_get_log_file();
221+
return Interop.ConsumeString(rawResult);
222+
}
223+
191224
/// <summary>Registers <paramref name="callback"/> for every ApplicationEvent this Application emits.</summary>
192225
/// <remarks>
193226
/// The delegate is kept alive until the listener is removed or its emitter

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

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,19 @@ external int native_application_add_listener_async(
9999
@ffi.Native<native_window_list_t Function()>()
100100
external native_window_list_t native_application_get_all_windows();
101101

102+
/// Caller owns the returned string; free it with free_c_str().
103+
@ffi.Native<ffi.Pointer<ffi.Char> Function()>()
104+
external ffi.Pointer<ffi.Char> native_application_get_log_file();
105+
106+
@ffi.Native<ffi.UnsignedInt Function()>(
107+
symbol: 'native_application_get_log_level',
108+
)
109+
external int _native_application_get_log_level();
110+
111+
native_log_level_t native_application_get_log_level() {
112+
return native_log_level_t.fromValue(_native_application_get_log_level());
113+
}
114+
102115
/// Caller owns the returned handle; release it with native_window_free().
103116
@ffi.Native<native_window_t Function()>()
104117
external int native_application_get_primary_window();
@@ -169,6 +182,18 @@ external bool native_application_set_dock_icon_visible(bool visible);
169182
@ffi.Native<ffi.Bool Function(ffi.Pointer<ffi.Char>)>()
170183
external bool native_application_set_icon(ffi.Pointer<ffi.Char> icon_path);
171184

185+
@ffi.Native<ffi.Bool Function(ffi.Pointer<ffi.Char>)>()
186+
external bool native_application_set_log_file(ffi.Pointer<ffi.Char> path);
187+
188+
@ffi.Native<ffi.Void Function(ffi.UnsignedInt)>(
189+
symbol: 'native_application_set_log_level',
190+
)
191+
external void _native_application_set_log_level(int level);
192+
193+
void native_application_set_log_level(native_log_level_t level) {
194+
return _native_application_set_log_level(level.value);
195+
}
196+
172197
@ffi.Native<ffi.Bool Function(native_menu_t)>()
173198
external bool native_application_set_menu_bar(int menu);
174199

@@ -5858,6 +5883,28 @@ typedef Dartnative_launch_at_login_t = int;
58585883
typedef native_listener_id_t = ffi.Uint64;
58595884
typedef Dartnative_listener_id_t = int;
58605885

5886+
enum native_log_level_t {
5887+
NATIVE_LOG_LEVEL_OFF(0),
5888+
NATIVE_LOG_LEVEL_ERROR(1),
5889+
NATIVE_LOG_LEVEL_WARNING(2),
5890+
NATIVE_LOG_LEVEL_INFO(3),
5891+
NATIVE_LOG_LEVEL_DEBUG(4),
5892+
NATIVE_LOG_LEVEL_TRACE(5);
5893+
5894+
final int value;
5895+
const native_log_level_t(this.value);
5896+
5897+
static native_log_level_t fromValue(int value) => switch (value) {
5898+
0 => NATIVE_LOG_LEVEL_OFF,
5899+
1 => NATIVE_LOG_LEVEL_ERROR,
5900+
2 => NATIVE_LOG_LEVEL_WARNING,
5901+
3 => NATIVE_LOG_LEVEL_INFO,
5902+
4 => NATIVE_LOG_LEVEL_DEBUG,
5903+
5 => NATIVE_LOG_LEVEL_TRACE,
5904+
_ => throw ArgumentError('Unknown value for native_log_level_t: $value'),
5905+
};
5906+
}
5907+
58615908
enum native_menu_backend_t {
58625909
NATIVE_MENU_BACKEND_NATIVE(0),
58635910
NATIVE_MENU_BACKEND_WIN_UI3(1);

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

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,30 @@ enum Brightness {
3535
c.native_brightness_t get raw => c.native_brightness_t.fromValue(value);
3636
}
3737

38+
enum LogLevel {
39+
off(0),
40+
error(1),
41+
warning(2),
42+
info(3),
43+
debug(4),
44+
trace(5);
45+
46+
const LogLevel(this.value);
47+
final int value;
48+
49+
static LogLevel fromValue(int value) => switch (value) {
50+
0 => LogLevel.off,
51+
1 => LogLevel.error,
52+
2 => LogLevel.warning,
53+
3 => LogLevel.info,
54+
4 => LogLevel.debug,
55+
5 => LogLevel.trace,
56+
_ => LogLevel.off,
57+
};
58+
59+
c.native_log_level_t get raw => c.native_log_level_t.fromValue(value);
60+
}
61+
3862
/// One `ApplicationEvent`, in its concrete form.
3963
sealed class ApplicationEvent {
4064
const ApplicationEvent();
@@ -284,6 +308,30 @@ class Application {
284308
return items;
285309
}
286310

311+
void setLogLevel(LogLevel level) {
312+
c.native_application_set_log_level(level.raw);
313+
}
314+
315+
LogLevel getLogLevel() {
316+
final raw = c.native_application_get_log_level();
317+
return LogLevel.fromValue(raw.value);
318+
}
319+
320+
bool setLogFile(String path) {
321+
final pathNative = path.toNativeUtf8().cast<ffi.Char>();
322+
final result = c.native_application_set_log_file(pathNative);
323+
pkg_ffi.calloc.free(pathNative);
324+
return result;
325+
}
326+
327+
String? getLogFile() {
328+
final resultPointer = c.native_application_get_log_file();
329+
if (resultPointer == ffi.nullptr) return null;
330+
final result = resultPointer.cast<pkg_ffi.Utf8>().toDartString();
331+
c.free_c_str(resultPointer);
332+
return result;
333+
}
334+
287335
/// Registers [callback] for every `ApplicationEvent` this `Application` emits.
288336
///
289337
/// Delivered on the registering isolate, including events from native UI threads.

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,28 @@ enum Brightness {
2727
};
2828
}
2929

30+
enum LogLevel {
31+
off(0),
32+
error(1),
33+
warning(2),
34+
info(3),
35+
debug(4),
36+
trace(5);
37+
38+
const LogLevel(this.value);
39+
final int value;
40+
41+
static LogLevel fromValue(int value) => switch (value) {
42+
0 => LogLevel.off,
43+
1 => LogLevel.error,
44+
2 => LogLevel.warning,
45+
3 => LogLevel.info,
46+
4 => LogLevel.debug,
47+
5 => LogLevel.trace,
48+
_ => LogLevel.off,
49+
};
50+
}
51+
3052
/// One `ApplicationEvent`, in its concrete form.
3153
sealed class ApplicationEvent {
3254
const ApplicationEvent();
@@ -120,6 +142,14 @@ class Application {
120142

121143
List<Window> getAllWindows() => unsupported();
122144

145+
void setLogLevel(LogLevel level) => unsupported();
146+
147+
LogLevel getLogLevel() => unsupported();
148+
149+
bool setLogFile(String path) => unsupported();
150+
151+
String? getLogFile() => unsupported();
152+
123153
ListenerId addListener(FutureOr<void> Function(ApplicationEvent) callback) =>
124154
unsupported();
125155

‎bindings/go/nativeapi.gen.go‎

Lines changed: 42 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎bindings/js/lib/application.ts‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,16 @@ export const Brightness = {
1313
} as const;
1414
export type Brightness = (typeof Brightness)[keyof typeof Brightness];
1515

16+
export const LogLevel = {
17+
Off: 0,
18+
Error: 1,
19+
Warning: 2,
20+
Info: 3,
21+
Debug: 4,
22+
Trace: 5,
23+
} as const;
24+
export type LogLevel = (typeof LogLevel)[keyof typeof LogLevel];
25+
1626
export type ApplicationEvent =
1727
| { type: "started" }
1828
| { type: "exiting"; exitCode: number }
@@ -112,6 +122,22 @@ export class Application {
112122
return (native.native_application_get_all_windows() as bigint[]).map((handle) => new Window(handle));
113123
}
114124

125+
static setLogLevel(level: LogLevel): void {
126+
native.native_application_set_log_level(level);
127+
}
128+
129+
static getLogLevel(): LogLevel {
130+
return native.native_application_get_log_level();
131+
}
132+
133+
static setLogFile(path: string): boolean {
134+
return native.native_application_set_log_file(path);
135+
}
136+
137+
static getLogFile(): string {
138+
return native.native_application_get_log_file();
139+
}
140+
115141
/** Receives events on the JS thread. Borrowed objects stay valid until the returned Promise settles. */
116142
static addListener(listener: (event: ApplicationEvent) => void | Promise<void>): number {
117143
return native.native_application_add_listener((event: Record<string, unknown>, delivery: bigint) =>

0 commit comments

Comments
 (0)