{ nixosConfig, lib, pkgs, username, ... }:
let
  cfg = nixosConfig.my.desktop.vesktop;
in
{
  config = lib.mkIf cfg.enable {
    home.packages = [
      (pkgs.writeShellScriptBin "vesktop-portable" ''
        exec /home/${username}/vesktop/vesktop --ozone-platform-hint=auto --enable-features=WaylandWindowDecorations --enable-wayland-ime=true --enable-blink-features=MiddleClickAutoscroll "$@"
      '')
    ];
    xdg.desktopEntries.vesktop = {
      name = "Vesktop";
      genericName = "Discord Client";
      exec = "vesktop-portable %U";
      icon = "vesktop";
      terminal = false;
      categories = [ "Network" "InstantMessaging" "Chat" ];
    };

    programs.vesktop = {
      enable = true;
      package = pkgs.vesktop.override {
        withMiddleClickScroll = true;
      };
      settings = {
        arRPC = true;
        tray = true;
        minimizeToTray = true;
      };
      vencord = {
        settings = {
          plugins = {
            AlwaysTrust.enabled = true;
            BetterSessions.enabled = true;
            BetterSettings.enabled = true;
            BiggerStreamPreview.enabled = true;
            CallTimer.enabled = true;
            ClearURLs.enabled = true;
            CopyEmojiMarkdown.enabled = true;
            CopyFileContents.enabled = true;
            CopyUserURLs.enabled = true;
            CrashHandler.enabled = true;
            CustomIdle = {
              enabled = true;
              idleTimeout = 0;
              remainInIdle = false;
            };
            Dearrow.enabled = true;
            DisableCallIdle.enabled = true;
            ExpressionCloner.enabled = true;
            FavoriteEmojiFirst.enabled = true;
            FixSpotifyEmbeds.enabled = true;
            FixYoutubeEmbeds.enabled = true;
            FullSearchContext.enabled = true;
            GameActivityToggle.enabled = true;
            GifPaste.enabled = true;
            ImageZoom.enabled = true;
            LoadingQuotes.enabled = true;
            MemberCount.enabled = true;
            MentionAvatars.enabled = true;
            MessageLinkEmbeds.enabled = true;
            MessageLogger = {
              enabled = true;
              inlineEdits = false;
            };
            NewGuildSettings.enabled = true;
            NoF1.enabled = true;
            NoOnboardingDelay.enabled = true;
            NormalizeMessageLinks.enabled = true;
            NoUnblockToJump.enabled = true;
            OnePingPerDm.enabled = true;
            OpenInApp.enabled = true;
            petpet.enabled = true;
            ReadAllNotificationsButton.enabled = true;
            RelationshipNotifier.enabled = true;
            ReverseImageSearch.enabled = true;
            ServerInfo.enabled = true;
            ServerListIndicators.enabled = false;
            ShowHiddenChannels.enabled = true;
            ShowHiddenThings.enabled = true;
            SpotifyControls.enabled = true;
            ThemeAttributes.enabled = true;
            TypingIndicator.enabled = true;
            TypingTweaks.enabled = true;
            UnlockedAvatarZoom.enabled = true;
            UnsuppressEmbeds.enabled = true;
            UserVoiceShow.enabled = true;
            ValidUser.enabled = true;
            ViewIcons.enabled = true;
            ViewRaw.enabled = true;
            VoiceChatDoubleClick.enabled = true;
            VoiceDownload.enabled = true;
            VoiceMessages.enabled = true;
            WebKeybinds.enabled = true;
            WebScreenShareFixes.enabled = true;
            WhoReacted.enabled = true;
            YoutubeAdblock.enabled = true;
            DisableDeepLinks.enabled = true;
            NoTrack.enabled = true;
            Settings.enabled = true;
            SupportHelper.enabled = true;
            WebContextMenus.enabled = true;
          };
        };
      };
    };
  };
}
