Skip to content

Commit

Permalink
feat(gaming): add shortcuts for mihoyo games
Browse files Browse the repository at this point in the history
  • Loading branch information
zakuciael committed Jun 22, 2024
1 parent 98a1a9e commit d094200
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 1 deletion.
5 changes: 4 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"drun",
"ehci",
"fenix",
"fetchurl",
"filebrowser",
"Filesystems",
"flatpak",
Expand Down Expand Up @@ -97,6 +98,7 @@
"partlabel",
"pkgs",
"playerctl",
"pname",
"polkit",
"powermenu",
"pseudotile",
Expand Down Expand Up @@ -160,7 +162,8 @@
"bootloader",
"fish",
"git",
"shell"
"shell",
"gaming"
],
"todohighlight.isEnable": true,
"todohighlight.isCaseSensitive": true,
Expand Down
57 changes: 57 additions & 0 deletions modules/desktop/gaming/mihoyo.nix
Original file line number Diff line number Diff line change
@@ -1,24 +1,81 @@
{
config,
lib,
pkgs,
username,
...
}:
with lib;
with lib.my;
with lib.my.utils; let
inherit (pkgs) makeDesktopItem fetchurl symlinkJoin;
inherit (pkgs.stdenv) mkDerivation;
cfg = config.modules.desktop.gaming.mihoyo;
layout = findLayoutConfig config ({index, ...}: index == 1); # Main monitor
monitor = getLayoutMonitor layout "wayland";
launcherClass = "^(moe.launcher.an-anime-game-launcher)$";
gameTitle = "^(Genshin Impact)$";

mkGameShortcut = {
name,
desktopName,
iconSrc,
package,
}: let
icon = mkDerivation {
name = "${name}-icon";
src = iconSrc;
nativeBuildInputs = with pkgs; [libicns];
buildCommand = ''
cp "${iconSrc}" ./${name}.icns
chmod -R u+w -- "./${name}.icns"
mkdir -p "$out/share/pixmaps/"
TMP_DIR=$(mktemp -d mihoyo-icon.XXXXXXXXXX)
icns2png -x -d 32 -s 512 -o "$TMP_DIR" "./${name}.icns"
cp "$TMP_DIR/${name}_512x512x32.png" "$out/share/pixmaps/${name}.png"
'';
};
desktopEntry = makeDesktopItem {
inherit name desktopName;
genericName = desktopName;
exec = "${package}/bin/${package.pname} --run-game";
categories = ["Game"];
icon = name;
};
in
symlinkJoin {
inherit name;
paths = [icon desktopEntry];
meta = with lib; {
description = "A shortcut for ${desktopName}";
license = licenses.unlicense;
maintainers = with maintainers; [zakuciael];
platforms = platforms.linux;
};
};
in {
options.modules.desktop.gaming.mihoyo = {
enable = mkEnableOption "miHoYo games";
test = mkOption {
type = types.raw;
};
};

config = mkIf (cfg.enable) {
home-manager.users.${username} = {
home.packages = [
(mkGameShortcut {
name = "genshin-impact";
desktopName = "Genshin Impact";
iconSrc = fetchurl {
url = "https://parsefiles.back4app.com/JPaQcFfEEQ1ePBxbf6wvzkPMEqKYHhPYv8boI1Rc/3c03a44960ac2060be92bd7182c35e83_F5ttFHp0ag.icns";
hash = "sha256-jEa14o2TqUVuSzgpA8hvWmUedwoKt39iEwrn6NPzBKU=";
};
package = config.programs.anime-game-launcher.package;
})
];

wayland.windowManager.hyprland.settings = {
windowrulev2 = [
"float, class:${launcherClass}"
Expand Down

0 comments on commit d094200

Please sign in to comment.