Indeed, holding a strong reference will keep the process running.
I’ll post my example code here for reference if someone else has this problem. What this code does is to define a task template that is to be instantiated in Project Settings. Clicking Run will then create a named pipe test.fifo
and start a Process
reading from that pipe and logging received lines. It will tell Nova to execute the script test.sh
as TaskProcessAction
. That script will repeatedly write „spam“ to test.fifo
and delete the named pipe when it is stopped via Nova. The Process
reading the named pipe will end automatically since the named pipe closes when the last writer vanishes.
I recommend not clicking on the test.fifo
file in the Files Sidebar as Nova currently freezes if you do that (I did already file a bug).
Scripts/main.js
nova.assistants.registerTaskAssistant({
provideTasks: function() { return null; },
resolveTaskAction: function(context) {
return new Promise((resolve, reject) => {
let mkfifo = new Process("/usr/bin/mkfifo", {
args: ["test.fifo"],
cwd: nova.workspace.path
});
mkfifo.onDidExit((status) => {
if (status == 0) {
globalThis.curProc = new Process("/bin/cat", {
args: ["test.fifo"],
cwd: nova.workspace.path
});
globalThis.curProc.onStdout((line) => {
console.log("received line: " + line);
});
globalThis.curProc.start();
resolve(new TaskProcessAction("/bin/sh", {
args: [nova.path.join(nova.extension.path, "Scripts", "test.sh")],
cwd: nova.workspace.path
}));
} else {
reject("FIFO creation failed with exit status " + status);
}
});
mkfifo.start();
});
}
}, {identifier: "org.flyx.test.resolver"});
Scripts/test.sh
trap "rm test.fifo; kill 0" SIGINT SIGTERM EXIT
perl -e 'open my $f, ">", "test.fifo"; $f->autoflush(1); for (;1;) {print $f "spam.\n"; sleep 1}'
extension.json
{
"identifier": "org.flyx.test",
"name": "test",
"organization": "Felix Krause",
"description": "Lorem ipsum, dolor sit amet.",
"version": "1.0",
"categories": ["tasks"],
"main": "main.js",
"entitlements": {
"filesystem": "readwrite", "process": true
},
"taskTemplates": {
"test123": {
"name": "ProcessTest",
"description": "foo",
"tasks": {
"run": {
"resolve": "org.flyx.test.resolver",
"persistent": true
}
}
}
}
}