Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ pub mod timers;
mod type_description;
pub mod ui_dispatcher;
mod value;
#[cfg(feature = "classic")]
#[cfg(any(feature = "classic", feature = "napi_engine"))]
pub(crate) mod win32;
#[cfg(feature = "classic")]
pub(crate) mod win32_fast;
Expand Down
20 changes: 14 additions & 6 deletions runtime/src/napi_engine/event_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ thread_local! {
static KEEP_ALIVE: Cell<i64> = const { Cell::new(0) };
}

pub(crate) fn retain() {
KEEP_ALIVE.with(|k| k.set(k.get() + 1));
}

pub(crate) fn release() {
KEEP_ALIVE.with(|k| k.set((k.get() - 1).max(0)));
}

/// Install `__nsLoopRetain` / `__nsLoopRelease` on the global object (install-if-missing; on
/// Node these are never consulted because nswinrt.js manages its own pump lifecycle).
pub fn install_loop_natives(env: &Env) -> napi::Result<()> {
Expand All @@ -40,16 +48,16 @@ pub fn install_loop_natives(env: &Env) -> napi::Result<()> {
if present {
return Ok(());
}
let retain = env.create_function_from_closure("__nsLoopRetain", |_ctx| {
KEEP_ALIVE.with(|k| k.set(k.get() + 1));
let retain_fn = env.create_function_from_closure("__nsLoopRetain", |_ctx| {
retain();
Ok(())
})?;
global.set_named_property("__nsLoopRetain", retain)?;
let release = env.create_function_from_closure("__nsLoopRelease", |_ctx| {
KEEP_ALIVE.with(|k| k.set((k.get() - 1).max(0)));
global.set_named_property("__nsLoopRetain", retain_fn)?;
let release_fn = env.create_function_from_closure("__nsLoopRelease", |_ctx| {
release();
Ok(())
})?;
global.set_named_property("__nsLoopRelease", release)?;
global.set_named_property("__nsLoopRelease", release_fn)?;
Ok(())
}

Expand Down
2 changes: 2 additions & 0 deletions runtime/src/napi_engine/globals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ pub fn install_globals(env: &Env) -> napi::Result<()> {
// NSWinRT.asDelegate(typeName, fn): wraps a JS function as a COM-backed WinRT delegate.
crate::napi_engine::delegate::install_as_delegate(env)?;

crate::napi_engine::win32::install_win32(env)?;

// NSWinRT.makeItemsSource/extendItemsSource/insertItemsSource/removeItemsSource/
// updateItemsSource/resetItemsSource: the native IObservableVector<IInspectable> ItemsSource
// core's ListView (ui/list-view/index.windows.js) requires on Windows.
Expand Down
1 change: 1 addition & 0 deletions runtime/src/napi_engine/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ pub mod timers;
pub mod url;
pub mod value;
pub mod websocket;
pub mod win32;
pub mod xaml_host;

// Engine-neutral marshaling types the napi backend and standalone hosts build against.
Expand Down
Loading