-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSubPasswordGenerate.js
46 lines (41 loc) · 1.53 KB
/
SubPasswordGenerate.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
const {AbstractTypiePackage, TypieCore, TypieRowItem} = require("typie-sdk");
const {clipboard} = require("electron");
const Path = require("path");
class SubPasswordGenerate extends AbstractTypiePackage {
constructor(win, config, pkgPath, parent) {
super(win, config, pkgPath);
this.packageName = "Password";
this.db = "Password";
this.typie = new TypieCore(this.packageName, "Password");
this.icon = Path.join(this.getPackagePath(), "icons", "generate-pass.svg");
this.availabelChars = config.availabelChars;
this.numOfChars = config.numOfChars;
}
activate(pkgList, item, cb) {
this.win.hide();
this.lastPaste = item.getPath();
clipboard.writeText(item.getPath());
this.typie.pasteText().go();
}
enterPkg(pkgList, item, cb) {
const res = {data: [], length: 0, err: 0};
for (let i = 0; i < 5; i++) {
res.data.push(new TypieRowItem(this.generate())
.setIcon(this.icon)
.setPath(this.generate())
.setDescription("Activate to Paste")
.setDB("null")
.setPackage(this.packageName).toPayload());
}
res.length = res.data.length;
cb(res);
}
generate() {
let password = "";
for (let i = 0; i < this.numOfChars; i++) {
password += this.availabelChars.charAt(Math.floor(Math.random() * this.availabelChars.length));
}
return password;
}
}
module.exports = SubPasswordGenerate;