【问题标题】:How to use keytar (for electron)如何使用keytar(用于电子)
【发布时间】:2020-02-07 22:59:46
【问题描述】:

所以貌似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> }

有人可以教我如何获取实际密码吗?

【问题讨论】:

    标签: node.js promise electron


    【解决方案1】:

    好吧,环顾四周,我找到了答案。您调用生成的 Promise 并对 Promise 的参数进行操作。

    keytar.setPassword('KeytarTest', 'AccountName', 'secret');
    const secret = keytar.getPassword('KeytarTest', 'AccountName');
    secret.then((result) => {
        console.log("result: "+ result); // result will be 'secret'
    });
    

    【讨论】:

      猜你喜欢
      • 2020-11-11
      • 2020-03-30
      • 2017-08-31
      • 2019-09-03
      • 2015-11-24
      • 2015-12-19
      • 2018-03-10
      • 1970-01-01
      • 2017-01-28
      相关资源
      最近更新 更多