node.js - 如何使用keytar(用于电子)
问题描述
所以貌似electron有个叫keytar的模块,但是文档少了很多,不知道怎么用。
https://github.com/atom/node-keytar
我现在的代码是(在主进程中)
const keytar = require('keytar');
...
keytar.setPassword('KeytarTest', 'AccountName', 'secret');
const secret = keytar.getPassword('KeytarTest', 'AccountName');
console.log(secret);
哪个打印出来
Promise { <pending> }
有人可以教我如何获取实际密码吗?
解决方案
好的,环顾四周后,我找到了答案。您调用生成的 Promise 并对 Promise 的参数进行操作。
keytar.setPassword('KeytarTest', 'AccountName', 'secret');
const secret = keytar.getPassword('KeytarTest', 'AccountName');
secret.then((result) => {
console.log("result: "+ result); // result will be 'secret'
});
推荐阅读
- c++ - 如何使用多维初始化列表初始化自定义容器?
- spring - Spring security 的 CSRF 令牌 - 我可以使用纯 HTML,还是需要 JSP?
- go - Go Firestore 从集合中获取所有文档
- python - 三角函数python的导数
- java - 无法从 jboss 调用 api.backblaze.com
- flutter - 如何处理小部件测试中的设备宽度和方向?
- c# - ASP.NET Core Jwt 401 未经授权。策略认证
- javascript - chrome上的getDisplayMedia拆分选择窗口
- rust - Rust 链表不能借用上一个和下一个元素作为可变的(只需要不可变的引用)
- java - 引起:java.sql.SQLException:ORA-06550:第 1 行,第 7 列:PLS-00306:调用“PR_SP_FAHMI”时参数的数量或类型错误