Comments (4)
This PR adds event channel support.
There are no examples yet, but the usage should be roughtly like this:
const CHANNEL_APP_NOTIFICATIONS: &str = "channel_name";
pub struct AppState {
sinks: HashMap<i64, EventSink>,
}
impl AppState {
pub fn new(context: Context) -> RegisteredEventChannel<Self> {
Self {
sinks: HashMap::new(),
}
.register(context, CHANNEL_APP_NOTIFICATIONS)
}
fn send_message(&self, message: &Value) {
for sink in self.sinks.values() {
sink.send_message(message).ok();
}
}
}
impl EventChannelHandler for AppState {
fn register_event_sink(
&mut self,
sink: nativeshell::shell::EventSink,
_listen_argument: Value,
) {
self.sinks.insert(sink.id(), sink);
}
fn unregister_event_sink(&mut self, sink_id: i64) {
self.sinks.remove(&sink_id);
}
}
Dart side:
const _appNotificationsChannel = EventChannel('channel_name');
...
_appNotificationsChannel
.receiveBroadcastStream()
.listen((event) {...});
from nativeshell.
The low-ish level api for this would be shell.MessageManager
, register_message_handler
and get_message_sender
. Those operate on messages instead of method calls. I played a bit with async executor that invokes futures on main loop but in the end decided it might not be worth it.
from nativeshell.
It's working like a charm. Thank you!
If you want I can add an example using an Async Executor to send stream events down an EventSink.
from nativeshell.
That'd be great! Examples will need some work right now to build with current master. I plan to do that over this weekend (as well as new nativeshell release).
from nativeshell.
Related Issues (20)
- NativeShell degrades performance compared to custom embedding HOT 3
- Crashes on multiple monitors in Windows HOT 4
- Is there any way to lower the minimum supported version of macOS HOT 1
- way to run existing flutter code HOT 4
- How to specify libflutter location
- Frameless windows are not resizable on macOS
- Fails to build on apple silicon with Flutter 3.0.0 HOT 2
- The Flutter Attach to Process gets stuck on Waiting... HOT 3
- Invalid read causes segmentation fault HOT 3
- std::rc::Weak<ContextImpl>` cannot be sent between threads safely
- std::rc::Weak<ContextImpl>` cannot be sent between threads safely
- MenuItem clash with flutter widget of the same name HOT 1
- Getting an error when trying to run the examples HOT 2
- Build Error on MacOS 13.2.1 - cargo run or cargo run --release unable to build and run the flutter app for example provided
- Issues with native plugin `media_kit` HOT 2
- Latest SharedPreferences not working HOT 1
- Jitter when resizing on Windows when frame is `WindowFrame.noTitle` HOT 1
- Unable to build sample project HOT 2
- [super_context_menu] Change/Remove Progress Indicator for DeferredMenuElement
- Calling dart from rust side?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nativeshell.