Skip to content

Commit ce649a2

Browse files
committed
Let apps that also target the web depend on nativeapi
dart:ffi does not exist on the web, and importing it fails the whole build, so depending on nativeapi (or tray_manager on top of it) broke an unrelated flutter build web (leanflutter/tray_manager#108). The Dart generator now also emits lib/src/web/: a pure-Dart mirror of every module with the same classes, enums, value types and events, minus the members that expose the C form. Its platform calls throw UnsupportedError. lib/nativeapi.dart exports it if (dart.library.js_interop), keeping the FFI modules as the default the analyzer and native builds resolve.
1 parent e939b41 commit ce649a2

43 files changed

Lines changed: 3130 additions & 94 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎bindings/dart/nativeapi/CHANGELOG.md‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
## 0.4.1
22

3+
* Apps that also target the web can depend on nativeapi again
4+
(leanflutter/tray_manager#108). On the web `package:nativeapi` resolves to a
5+
pure-Dart mirror without `dart:ffi`: the same classes, enums, value types and
6+
events, minus the members that expose the C form (`raw`, `fromNative`,
7+
`allocNative`, `nativeObject`, raw pointers). Every platform call there
8+
throws `UnsupportedError`, so guard it with `kIsWeb`.
9+
310
* Event listeners run on their registering isolate, including native events
411
from foreign UI threads. Callbacks may return a Future; event payloads and
512
borrowed handles remain valid until completion. Removing a listener skips

‎bindings/dart/nativeapi/lib/nativeapi.dart‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,14 @@ library;
22

33
// Every generated module. The list itself is generated too, so adding a header
44
// upstream does not need an edit here.
5-
export 'src/generated.dart';
5+
//
6+
// `dart:ffi` does not exist on the web, and importing it fails the whole
7+
// build. There the same API comes from a pure-Dart mirror whose platform
8+
// calls throw `UnsupportedError`, so an app that also targets the web can
9+
// still depend on nativeapi and guard its calls with `kIsWeb`.
10+
export 'src/generated.dart'
11+
if (dart.library.js_interop) 'src/web/generated.dart';
612

713
// Hand-written.
8-
export 'src/run_native_app.dart';
14+
export 'src/run_native_app.dart'
15+
if (dart.library.js_interop) 'src/run_native_app_web.dart';
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// Hand-written: `runNativeApp` where there is no platform event loop to run.
2+
3+
import 'web/unsupported.dart';
4+
5+
/// Runs a desktop app from a plain Dart program; unavailable on the web.
6+
void runNativeApp(void Function() main) => unsupported();
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// AUTO-GENERATED. DO NOT EDIT.
2+
// Any manual changes WILL BE LOST when this file is regenerated.
3+
4+
// ignore_for_file: unused_import, unnecessary_import
5+
6+
import 'unsupported.dart';
7+
8+
class AccessibilityManager {
9+
const AccessibilityManager._();
10+
11+
static const AccessibilityManager instance = AccessibilityManager._();
12+
13+
void enable() => unsupported();
14+
15+
bool isEnabled() => unsupported();
16+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// AUTO-GENERATED. DO NOT EDIT.
2+
// Any manual changes WILL BE LOST when this file is regenerated.
3+
4+
// ignore_for_file: unused_import, unnecessary_import
5+
6+
import 'unsupported.dart';
7+
8+
class AppInfo {
9+
const AppInfo._();
10+
11+
static const AppInfo instance = AppInfo._();
12+
13+
String? getName() => unsupported();
14+
15+
String? getIdentifier() => unsupported();
16+
17+
String? getVersion() => unsupported();
18+
19+
String? getBuildNumber() => unsupported();
20+
}
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
// AUTO-GENERATED. DO NOT EDIT.
2+
// Any manual changes WILL BE LOST when this file is regenerated.
3+
4+
// ignore_for_file: unused_import, unnecessary_import
5+
6+
import 'dart:async';
7+
8+
import 'foundation/event_request.dart';
9+
import 'menu.dart';
10+
import 'window.dart';
11+
import 'support.dart';
12+
import 'unsupported.dart';
13+
14+
enum Brightness {
15+
system(0),
16+
light(1),
17+
dark(2);
18+
19+
const Brightness(this.value);
20+
final int value;
21+
22+
static Brightness fromValue(int value) => switch (value) {
23+
0 => Brightness.system,
24+
1 => Brightness.light,
25+
2 => Brightness.dark,
26+
_ => Brightness.system,
27+
};
28+
}
29+
30+
/// One `ApplicationEvent`, in its concrete form.
31+
sealed class ApplicationEvent {
32+
const ApplicationEvent();
33+
}
34+
35+
final class ApplicationStartedEvent extends ApplicationEvent {
36+
const ApplicationStartedEvent();
37+
}
38+
39+
final class ApplicationExitingEvent extends ApplicationEvent {
40+
const ApplicationExitingEvent({required this.exitCode});
41+
42+
final int exitCode;
43+
}
44+
45+
final class ApplicationActivatedEvent extends ApplicationEvent {
46+
const ApplicationActivatedEvent();
47+
}
48+
49+
final class ApplicationDeactivatedEvent extends ApplicationEvent {
50+
const ApplicationDeactivatedEvent();
51+
}
52+
53+
final class ApplicationQuitRequestedEvent extends ApplicationEvent {
54+
const ApplicationQuitRequestedEvent({required this.request});
55+
56+
final EventRequest request;
57+
}
58+
59+
class Application {
60+
const Application._();
61+
62+
static const Application instance = Application._();
63+
64+
int run() => unsupported();
65+
66+
int runWithWindow(Window? window) => unsupported();
67+
68+
void quit(int exitCode) => unsupported();
69+
70+
bool isRunning() => unsupported();
71+
72+
bool isSingleInstance() => unsupported();
73+
74+
bool show() => unsupported();
75+
76+
bool hide() => unsupported();
77+
78+
bool isVisible() => unsupported();
79+
80+
bool setIcon(String iconPath) => unsupported();
81+
82+
bool setDockIconVisible(bool visible) => unsupported();
83+
84+
bool setProgressBar(double progress) => unsupported();
85+
86+
bool setBadgeLabel(String label) => unsupported();
87+
88+
bool setBrightness(Brightness brightness) => unsupported();
89+
90+
bool setMenuBar(Menu? menu) => unsupported();
91+
92+
Window? getPrimaryWindow() => unsupported();
93+
94+
void setPrimaryWindow(Window? window) => unsupported();
95+
96+
List<Window> getAllWindows() => unsupported();
97+
98+
ListenerId addListener(FutureOr<void> Function(ApplicationEvent) callback) =>
99+
unsupported();
100+
101+
bool removeListener(ListenerId listenerId) => unsupported();
102+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// AUTO-GENERATED. DO NOT EDIT.
2+
// Any manual changes WILL BE LOST when this file is regenerated.
3+
4+
// ignore_for_file: unused_import, unnecessary_import
5+
6+
import 'unsupported.dart';
7+
8+
class DeviceInfo {
9+
const DeviceInfo._();
10+
11+
static const DeviceInfo instance = DeviceInfo._();
12+
13+
String? getName() => unsupported();
14+
15+
String? getModel() => unsupported();
16+
17+
String? getManufacturer() => unsupported();
18+
19+
String? getOsName() => unsupported();
20+
21+
String? getOsVersion() => unsupported();
22+
23+
String? getKernelVersion() => unsupported();
24+
25+
String? getArchitecture() => unsupported();
26+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// AUTO-GENERATED. DO NOT EDIT.
2+
// Any manual changes WILL BE LOST when this file is regenerated.
3+
4+
// ignore_for_file: unused_import, unnecessary_import
5+
6+
enum DialogModality {
7+
none(0),
8+
application(1),
9+
window(2);
10+
11+
const DialogModality(this.value);
12+
final int value;
13+
14+
static DialogModality fromValue(int value) => switch (value) {
15+
0 => DialogModality.none,
16+
1 => DialogModality.application,
17+
2 => DialogModality.window,
18+
_ => DialogModality.none,
19+
};
20+
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
// AUTO-GENERATED. DO NOT EDIT.
2+
// Any manual changes WILL BE LOST when this file is regenerated.
3+
4+
// ignore_for_file: unused_import, unnecessary_import
5+
6+
import 'foundation/geometry.dart';
7+
import 'unsupported.dart';
8+
9+
typedef DisplayId = int;
10+
11+
enum DisplayOrientation {
12+
portrait(0),
13+
landscape(90),
14+
portraitFlipped(180),
15+
landscapeFlipped(270);
16+
17+
const DisplayOrientation(this.value);
18+
final int value;
19+
20+
static DisplayOrientation fromValue(int value) => switch (value) {
21+
0 => DisplayOrientation.portrait,
22+
90 => DisplayOrientation.landscape,
23+
180 => DisplayOrientation.portraitFlipped,
24+
270 => DisplayOrientation.landscapeFlipped,
25+
_ => DisplayOrientation.portrait,
26+
};
27+
}
28+
29+
/// One `DisplayEvent`, in its concrete form.
30+
sealed class DisplayEvent {
31+
const DisplayEvent();
32+
33+
Display get display;
34+
}
35+
36+
final class DisplayAddedEvent extends DisplayEvent {
37+
const DisplayAddedEvent({required this.display});
38+
39+
@override
40+
final Display display;
41+
}
42+
43+
final class DisplayRemovedEvent extends DisplayEvent {
44+
const DisplayRemovedEvent({required this.display});
45+
46+
@override
47+
final Display display;
48+
}
49+
50+
final class DisplayChangedEvent extends DisplayEvent {
51+
const DisplayChangedEvent({required this.display});
52+
53+
@override
54+
final Display display;
55+
}
56+
57+
class Display {
58+
Display.fromHandle(this.nativeHandle);
59+
Display.borrowed(this.nativeHandle);
60+
61+
final int nativeHandle;
62+
63+
void dispose() => unsupported();
64+
65+
DisplayId get id => unsupported();
66+
67+
String? get name => unsupported();
68+
69+
Point get position => unsupported();
70+
71+
Size get size => unsupported();
72+
73+
Rectangle get workArea => unsupported();
74+
75+
double get scaleFactor => unsupported();
76+
77+
bool get isPrimary => unsupported();
78+
79+
DisplayOrientation get orientation => unsupported();
80+
81+
int get refreshRate => unsupported();
82+
83+
int get bitDepth => unsupported();
84+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// AUTO-GENERATED. DO NOT EDIT.
2+
// Any manual changes WILL BE LOST when this file is regenerated.
3+
4+
// ignore_for_file: unused_import, unnecessary_import
5+
6+
import 'dart:async';
7+
8+
import 'display.dart';
9+
import 'foundation/geometry.dart';
10+
import 'support.dart';
11+
import 'unsupported.dart';
12+
13+
class DisplayManager {
14+
const DisplayManager._();
15+
16+
static const DisplayManager instance = DisplayManager._();
17+
18+
List<Display> getAll() => unsupported();
19+
20+
Display? getPrimary() => unsupported();
21+
22+
Point getCursorPosition() => unsupported();
23+
24+
ListenerId addListener(FutureOr<void> Function(DisplayEvent) callback) =>
25+
unsupported();
26+
27+
bool removeListener(ListenerId listenerId) => unsupported();
28+
}

0 commit comments

Comments
 (0)