- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
当计算机(运行 node.js 的计算机)进入休眠或关闭时,是否可以让 OS X 通知我的 node.js 应用程序?似乎应该如此,但我找不到任何与 node.js 相关的内容。我确实找到了 this但它谈论的是 Cocoa 应用程序。也许我可以让其他应用程序(如 Cocoa)接收 sleep 通知并将其传递给 node.js?
我很乐意听到任何可能为我指明正确方向的建议。
最佳答案
使用 nodobjc
(它似乎有效,但我还没有很好地测试过):
'use strict';
const $ = require('nodobjc');
// Load the AppKit framework.
$.framework('AppKit');
// Create delegate that gets notified
let Delegate = $.NSObject.extend('Delegate');
// The function that gets called when OS X is going to sleep.
function receiveSleepNote(self, cmd, notif) {
console.log('going to sleep');
}
Delegate.addMethod('receiveSleepNote:', 'v@:@', receiveSleepNote);
Delegate.register();
// Instantiate the delegate and set it as observer.
let delegate = Delegate('alloc')('init');
let nc = $.NSWorkspace('sharedWorkspace')('notificationCenter');
nc(
'addObserver', delegate,
'selector' , 'receiveSleepNote:',
'name' , $.NSWorkspaceWillSleepNotification,
'object' , null
)
// Set up the runloop.
let app = $.NSApplication('sharedApplication');
function runLoop() {
let pool = $.NSAutoreleasePool('alloc')('init');
try {
app('nextEventMatchingMask', $.NSAnyEventMask.toString(),
'untilDate', $.NSDate('distantFuture'),
'inMode', $.NSDefaultRunLoopMode,
'dequeue', 1);
} catch(e) {
console.error('run loop error', e.message);
};
pool('drain');
process.nextTick(runLoop);
}
runLoop();
可以找到您可以观察到的其他类型的通知 here .
关于javascript - 计算机进入休眠状态时 Node.js/OS X : How to notify node. js 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38668938/
我正在尝试在我安装的 Laravel 5.1 中设置 Gulp。我已经运行然后命令 npm install正如 Laravel 文档中所指定的那样,效果很好。 但是,当我现在运行命令时 gulp我收到
我有两个扩展线程的类和一个等待/通知 class A extends Thread { int r = 20; public void run() { try {
我正在尝试在后台服务中启动通知,这也是位置监听器。我有一个功能: public Notification CreateNotification(){ Intent notificati
编辑:我将其范围缩小到 python 代码中 Notifier.notify('Something') 的问题。当 python 脚本从 launchd 启动时,这不会产生预期的行为。我的其他 pyt
我正在尝试使用 bootstrap-notify v3.1.3、typescript、aurelia 和 VS2015 在我的网站上显示警报。 我的 aurelia 组件是: //myAlert.ts
注:other question的标题不同,导致无法识别为匹配的。 系统.类 TCollection = class(TPersistent) protected procedure Notify
我正在将一个项目从 Sprockets 迁移到 Webpacker。 我似乎无法正确运行的最后一件事是通知。 我曾经能够做到:$.notify('Test') 但现在我得到了 Uncaught Typ
我在一个项目中有多个用户控件,其中一个从 XML 中检索项目,创建“ClassItem”类型的对象,并应通知其他用户控件有关这些项目的信息。 我为我的对象创建了一个类(所有项目都将具有的“模型”):
我以为我会理解 Java 中的并发概念,但现在有一件事打破了我的理解: 为什么我必须在同步块(synchronized block)中包含对 wait() 和 notify() 方法的调用? 假设我有
我正在开发 NodeJS/Electron/Angular 应用程序,我正在使用 node-notifier 模块。一切正常,但在我的通知消息底部有一个不合适的“toast”字符串。它仅在我使用“图标
我正在基于Sproutcore 1.9.1的Web应用程序上工作。要从服务器检索数据 发出一个SC.Request.getUrl()请求,该请求在除IE8之外的所有浏览器中都可以正常工作。 对于IE8
我试图写一个关于如何使用wait()和notify()的示例,但是似乎无法通知wait() public class Transfer { private int[] data; pr
我想使用QAudioInput从麦克风捕获声音,对其进行处理然后再播放。据我了解,我需要连接到notify信号和内部处理程序,以便用户使用readAll()函数来获取原始数据。但是问题是,此处理函数永
public class Signal2NoiseRatio { public ImagePlus SingleSNR(ImagePlus imagePlus) throws Interrup
为什么只有第一个任务退出后才调用dispatchGroup.notify? 下面的代码输出如下: 1) Did the other thing **2) Did all the things** 3)
假设线程 T1 正在等待进入同步块(synchronized block),线程 T2 在同步块(synchronized block)内 wait(),并且线程 T3 在同步块(synchroniz
我正在尝试仅使用等待/通知同步来实现合并排序。我知道更高级的结构,例如 Fork/Join、Executors。等等,但我需要在这里使用工作/通知。基于此https://courses.cs.wash
了解 notifyAll 让我对 notify 产生了一些疑问:在典型情况下,我们有多个线程正在等待对 methody notify 的调用。当这种情况发生时,其中一个线程(之前调用了 wait 方法
我正在使用 wait() 和 notify() 编写一个示例程序,但是当调用 notify() 时,会出现多个线程被唤醒而不是一个。 代码是: public class MyQueue { O
根据17.2.4. Interactions of Waits, Notification, and Interruption : Similarly, notifications cannot be
我是一名优秀的程序员,十分优秀!