Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

68
LINES

< > BotCompany Repo | #1029670 // Password Manager [tray icon, copies passwords to clipboard, OK]

JavaX source code (Dynamic Module) [tags: use-pretranspiled] - run with: Stefan's OS

Uses 1113K of libraries. Click here for Pure Java version (18712L/94K).

!7

concept PasswordEntry {
  S purpose;
  SecretValue<S> password;
  S globalID = aGlobalID();
}

cmodule2 PasswordManager > DynCRUD<PasswordEntry> {
  transient TrayIcon trayIcon;
  transient ReliableSingleThread rstMakeTrayIcon = dm_rst(this, r makeTrayIcon);
  
  start {
    db(); // TODO: move DB to JavaX-Secret
    onConceptsChangeAndNow(r { doLater(2.0, rstMakeTrayIcon) });
  }

  void makeTrayIcon enter {
    disposeTrayIcon(trayIcon);
    new L menuItems; // no left-click action
    for (PasswordEntry e : conceptsSortedByFieldAlphanumIC(PasswordEntry, "purpose"))
      if (nemptyAfterTrim(getVar(e.password)))
        addAll(menuItems, "Copy password for " + e.purpose, rThread { copyPassword(e) });
    add(menuItems, "---");
    addAll(menuItems, "Edit Passwords...", rThread dm_activateOSAndModule);
    pcall-short {
      trayIcon = installTrayIcon(#1102954, "Password Manager", menuItems);
    }
  }
  
  afterVisualize {
    // TODO: disable when at beginning/end of list
    // TODO also: move to standard function
    addSelectionDependentButton("Move Up", r {
      PasswordEntry a = selected(), b = itemBefore(list(), a);
      if (a != null && b != null)
        swapConceptIDs(a, b);
    });
    addSelectionDependentButton("Move Down", r {
      PasswordEntry a = selected(), b = itemAfter(list(), a);
      if (a != null && b != null)
        swapConceptIDs(a, b);
    });
    addSelectionDependentButton("Copy password", rThread {
      copyPassword(selected());
    });
  }

  void cleanMeUp {
    disposeTrayIcon(trayIcon);
  }

  bool copyPassword(PasswordEntry p) {
    if (p == null) false;
    S pw = getVar(p.password);
    if (empty(pw)) ret false with infoBox("No password set for " + p.purpose);
    copyTextToClipboard(pw);
    ret true with infoBox("Password for " + p.purpose + " copied to clipboard");
  }
  
  // API
  
  bool copyPasswordForGlobalID(S globalID) {
    PasswordEntry entry = conceptWhere PasswordEntry(+globalID);
    if (entry == null) false;
    ret true with copyPassword(entry);
  }
}

Author comment

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: 182 / 4327
Version history: 15 change(s)
Referenced in: [show references]