{
  lib,
  config,
  pkgs,
  username,
  ...
}:
let
  cfg = config.adb;
  xdg = config.home-manager.users.${username}.xdg;
in
{
  options = {
    adb = {
      enable = lib.mkEnableOption "Enable adb and scrcpy in NixOS & home-manager";
    };
  };
  config = lib.mkIf cfg.enable {
    programs.adb.enable = true;
    users.users.${username}.extraGroups = [ "adbusers" ];
    environment.systemPackages = [ pkgs.scrcpy ];

    home-manager.users.${username}.home.file = {
      desktop-entry-adb-connect-shield-tv = {
        enable = true;
        text = ''
          [Desktop Entry]
          Exec=adb connect shield-tv.home
          Name=adb-connect-shield-tv
          Type=Application
        '';
        target = "${xdg.configHome}/autostart/adb-connect-shield-tv.desktop";
      };
      desktop-entry-adb-connect-luna = {
        enable = true;
        text = ''
          [Desktop Entry]
          Exec=adb connect luna.home
          Name=adb-connect-luna
          Type=Application
        '';
        target = "${xdg.configHome}/autostart/adb-connect-luna.desktop";
      };
    };

  };
}
