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
8 changes: 4 additions & 4 deletions src/EventBus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,21 +89,21 @@ internal sealed class Scheduler(ILogger logger) : IScheduler
{
public IDisposable ScheduleOnce(TimeSpan delay, Action work)
{
// 先建成不触发的,赋值之后再 Change —— 否则回调可能早于赋值而拿不到自己。
// 先建成不引发的那种,赋值之后再 Change —— 否则回调可能早于赋值而拿不到自己。
Timer? timer = null;
timer = new Timer(_ =>
{
timer!.Dispose();
Fire(work);
Raise(work);
}, null, Timeout.InfiniteTimeSpan, Timeout.InfiniteTimeSpan);
timer.Change(delay, Timeout.InfiniteTimeSpan);
return new Handle(timer);
}

public IDisposable SchedulePeriodic(TimeSpan interval, Action work) =>
new Handle(new Timer(_ => Fire(work), null, interval, interval));
new Handle(new Timer(_ => Raise(work), null, interval, interval));

private void Fire(Action work)
private void Raise(Action work)
{
try
{
Expand Down
25 changes: 24 additions & 1 deletion src/NativeHostingEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ public static class NativeHostingEntry
///
/// 2:<see cref="Start"/> / <see cref="StartUnderParent"/> 的参数改为
/// <c>{ const char* carrier_directory; void* host; }</c>(FX-0065)。
/// 3:入口表新增 <see cref="CarrierEnabled"/>,载体插件被父级启用时由原生侧调用(FX-0067)。
/// </summary>
public const int HostingContractVersion = 2;
public const int HostingContractVersion = 3;

/// <summary>给原生垫片读取的契约版本入口。</summary>
[UnmanagedCallersOnly]
Expand Down Expand Up @@ -125,6 +126,28 @@ private static (string? CarrierDirectory, nint Host) ReadStartArgs(IntPtr arg, i
[UnmanagedCallersOnly]
public static int StopUnderParent(IntPtr arg, int argSizeInBytes) => StopCore();

/// <summary>
/// 载体插件自己被父级启用了(Endstone 的 <c>onEnable</c>)。可注册的调用从这一刻起才被接受,
/// 所以能力层的等待闸门在这里统一放开 —— 子插件的 <c>OnEnable</c> 已经先于父级跑完,
/// 只靠轮询会晚整整一拍。
/// </summary>
[UnmanagedCallersOnly]
public static int CarrierEnabled(IntPtr arg, int argSizeInBytes) => SignalCore();

private static int SignalCore()
{
try
{
CarrierEnableSignal.Signal();
return 0;
}
catch (Exception ex)
{
s_loggerFactory?.CreateLogger("Hosihikari").LogError(ex, "启用信号分发失败");

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Localize the carrier-enable failure diagnostic

If a carrier-enable signal handler throws, this catch block emits a hard-coded Chinese diagnostic even on English or other non-Chinese servers, bypassing the existing UI-culture lookup and neutral English fallback. Add a resource key to CoreStrings.resx and CoreStrings.zh.resx and log it through CoreText.Get, as the other native-entry failure paths do. This violates the operator-message localization invariant in AGENTS.md.

AGENTS.md reference: AGENTS.md:L34-L35

Useful? React with 👍 / 👎.

return 1;
}
}

private static int StopCore()
{
var logger = s_loggerFactory?.CreateLogger("Hosihikari");
Expand Down