Uses 1113K of libraries. Click here for Pure Java version (18712L/94K).
1 | !7 |
2 | |
3 | concept PasswordEntry { |
4 | S purpose; |
5 | SecretValue<S> password; |
6 | S globalID = aGlobalID(); |
7 | } |
8 | |
9 | cmodule2 PasswordManager > DynCRUD<PasswordEntry> { |
10 | transient TrayIcon trayIcon; |
11 | transient ReliableSingleThread rstMakeTrayIcon = dm_rst(this, r makeTrayIcon); |
12 | |
13 | start { |
14 | db(); // TODO: move DB to JavaX-Secret |
15 | onConceptsChangeAndNow(r { doLater(2.0, rstMakeTrayIcon) }); |
16 | } |
17 | |
18 | void makeTrayIcon enter { |
19 | disposeTrayIcon(trayIcon); |
20 | new L menuItems; // no left-click action |
21 | for (PasswordEntry e : conceptsSortedByFieldAlphanumIC(PasswordEntry, "purpose")) |
22 | if (nemptyAfterTrim(getVar(e.password))) |
23 | addAll(menuItems, "Copy password for " + e.purpose, rThread { copyPassword(e) }); |
24 | add(menuItems, "---"); |
25 | addAll(menuItems, "Edit Passwords...", rThread dm_activateOSAndModule); |
26 | pcall-short { |
27 | trayIcon = installTrayIcon(#1102954, "Password Manager", menuItems); |
28 | } |
29 | } |
30 | |
31 | afterVisualize { |
32 | // TODO: disable when at beginning/end of list |
33 | // TODO also: move to standard function |
34 | addSelectionDependentButton("Move Up", r { |
35 | PasswordEntry a = selected(), b = itemBefore(list(), a); |
36 | if (a != null && b != null) |
37 | swapConceptIDs(a, b); |
38 | }); |
39 | addSelectionDependentButton("Move Down", r { |
40 | PasswordEntry a = selected(), b = itemAfter(list(), a); |
41 | if (a != null && b != null) |
42 | swapConceptIDs(a, b); |
43 | }); |
44 | addSelectionDependentButton("Copy password", rThread { |
45 | copyPassword(selected()); |
46 | }); |
47 | } |
48 | |
49 | void cleanMeUp { |
50 | disposeTrayIcon(trayIcon); |
51 | } |
52 | |
53 | bool copyPassword(PasswordEntry p) { |
54 | if (p == null) false; |
55 | S pw = getVar(p.password); |
56 | if (empty(pw)) ret false with infoBox("No password set for " + p.purpose); |
57 | copyTextToClipboard(pw); |
58 | ret true with infoBox("Password for " + p.purpose + " copied to clipboard"); |
59 | } |
60 | |
61 | // API |
62 | |
63 | bool copyPasswordForGlobalID(S globalID) { |
64 | PasswordEntry entry = conceptWhere PasswordEntry(+globalID); |
65 | if (entry == null) false; |
66 | ret true with copyPassword(entry); |
67 | } |
68 | } |
Began life as a copy of #1020554
download show line numbers debug dex old transpilations
Travelled to 6 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1029670 |
Snippet name: | Password Manager [tray icon, copies passwords to clipboard, OK] |
Eternal ID of this version: | #1029670/16 |
Text MD5: | 15a822714967e7bfb530d9cf87bccf27 |
Transpilation MD5: | c83772db3399048ee708955747a4a167 |
Author: | stefan |
Category: | javax |
Type: | JavaX source code (Dynamic Module) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2021-05-18 03:33:09 |
Source code size: | 2118 bytes / 68 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 239 / 4427 |
Version history: | 15 change(s) |
Referenced in: | [show references] |