我正在使用web API从Firefox开发一个本机消息传递应用程序。该扩展应该调用一个解析stdin的应用程序,然后基于它解析的一些数据调用我的另一个rust应用程序,但是出于明显的原因,rust应用程序不接受来自firefox的输入(当我手动)。这是扩展的代码:
/*
On a click on the browser action, send the app a message.
*/
browser.browserAction.onClicked.addListener(() => {
console.log("Sending: ping");
var sending = browser.runtime.sendNativeMessage(
"themefox_manager",
"ping");
sending.then(onResponse, onError);
});
function onResponse(response) {
console.log("Received " + response);
}
function onError(error) {
console.log(`Error: ${error}`);
}
以及此rust应用程序的代码:
use std::fs;
use std::io;
use std::io::prelude::*;
fn main() {
let stdin = io::stdin();
for line in stdin.lock().lines() {
let mut file = fs::File::create("/home/user/filename.txt").unwrap();
//
if line.unwrap() == "ping" {
file.write_all(b"TEST").expect("Error");
}
}
}
奇怪的是,当我关闭firefox时(而不是在应用启动时),我的主目录中的文本文件首先出现。而且它也没有文字TEST。
感谢您的帮助!
欢呼声
我设法制定了自己的解决方案,从this crate中花了点时间。