forked from tiiuae/ghaf
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix PDF XDG handler and add a new handler for JPG and PNG images
Signed-off-by: Yuri Nesterov <[email protected]>
- Loading branch information
1 parent
637bdfd
commit 8c94a34
Showing
13 changed files
with
225 additions
and
171 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
# Copyright 2022-2024 TII (SSRC) and the Ghaf contributors | ||
# SPDX-License-Identifier: Apache-2.0 | ||
{ | ||
config, | ||
lib, | ||
pkgs, | ||
... | ||
}: | ||
let | ||
cfg = config.ghaf.services.xdghandlers; | ||
inherit (lib) | ||
mkIf | ||
mkEnableOption | ||
; | ||
# XDG item for PDF | ||
xdgPdfItem = pkgs.makeDesktopItem { | ||
name = "ghaf-pdf-xdg"; | ||
desktopName = "Ghaf PDF Viewer"; | ||
exec = "${xdgOpenFile}/bin/xdgopenfile pdf %f"; | ||
mimeTypes = [ "application/pdf" ]; | ||
noDisplay = true; | ||
}; | ||
# XDG item for JPG and PNG | ||
xdgImageItem = pkgs.makeDesktopItem { | ||
name = "ghaf-image-xdg"; | ||
desktopName = "Ghaf Image Viewer"; | ||
exec = "${xdgOpenFile}/bin/xdgopenfile image %f"; | ||
mimeTypes = [ | ||
"image/jpeg" | ||
"image/png" | ||
]; | ||
noDisplay = true; | ||
}; | ||
# The xdgopenfile script sends a command to the GUIVM with the file path and type over TCP connection | ||
xdgOpenFile = pkgs.writeShellScriptBin "xdgopenfile" '' | ||
type=$1 | ||
filename=$2 | ||
filepath=$(/run/current-system/sw/bin/realpath "$filename") | ||
if [[ -z "$filepath" ]]; then | ||
echo "File path is empty in the XDG open script" | systemd-cat -p info | ||
exit 1 | ||
fi | ||
if [[ "$type" != "pdf" && "$type" != "image" ]]; then | ||
echo "Unknown file type in the XDF open script" | systemd-cat -p info | ||
exit 1 | ||
fi | ||
echo "Opening $filepath with type $type" | systemd-cat -p info | ||
echo -e "$type\n$filepath" | ${pkgs.netcat}/bin/nc -N gui-vm ${toString config.ghaf.services.xdgopener.xdgPort} | ||
''; | ||
in | ||
{ | ||
options.ghaf.services.xdghandlers = { | ||
enable = mkEnableOption "Enable Ghaf XDG handlers"; | ||
}; | ||
config = mkIf cfg.enable { | ||
environment.systemPackages = [ | ||
pkgs.xdg-utils | ||
xdgPdfItem | ||
xdgImageItem | ||
xdgOpenFile | ||
]; | ||
|
||
xdg.mime.defaultApplications."application/pdf" = "ghaf-pdf-xdg.desktop"; | ||
xdg.mime.defaultApplications."image/jpeg" = "ghaf-image-xdg.desktop"; | ||
xdg.mime.defaultApplications."image/png" = "ghaf-image-xdg.desktop"; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
# Copyright 2022-2024 TII (SSRC) and the Ghaf contributors | ||
# SPDX-License-Identifier: Apache-2.0 | ||
{ | ||
config, | ||
lib, | ||
pkgs, | ||
... | ||
}: | ||
let | ||
inherit (builtins) toString; | ||
inherit (lib) | ||
mkEnableOption | ||
mkOption | ||
mkIf | ||
types | ||
; | ||
cfg = config.ghaf.services.xdgopener; | ||
|
||
# TODO: Fix the path to get the sshKeyPath so that | ||
# ghaf-xdg-open can be exported as a normal package from | ||
# packaged/flake-module.nix and hence easily imported | ||
# into all targets | ||
ghaf-xdg-open = pkgs.callPackage ../../../packages/ghaf-xdg-open { | ||
inherit (config.ghaf.security.sshKeys) sshKeyPath; | ||
}; | ||
in | ||
{ | ||
options.ghaf.services.xdgopener = { | ||
enable = mkEnableOption "Enable the XDG opening service"; | ||
xdgPort = mkOption { | ||
type = types.int; | ||
default = 1200; | ||
description = "TCP port for the XDG socket"; | ||
}; | ||
}; | ||
|
||
config = mkIf cfg.enable { | ||
# XDG handler service receives a file path and type over TCP connection and executes ghaf-xdg-open script | ||
systemd = { | ||
sockets."xdg" = { | ||
unitConfig = { | ||
Description = "Ghaf XDG socket"; | ||
}; | ||
socketConfig = { | ||
ListenStream = "${toString cfg.xdgPort}"; | ||
Accept = "yes"; | ||
}; | ||
wantedBy = [ "sockets.target" ]; | ||
}; | ||
|
||
services."xdg@" = { | ||
description = "XDG opener"; | ||
serviceConfig = { | ||
# The user 'ghaf' is used here to access SSH keys for the scp command | ||
# This is required to copy files to the zathuravm | ||
User = "ghaf"; | ||
ExecStart = "${ghaf-xdg-open}/bin/ghaf-xdg-open"; | ||
StandardInput = "socket"; | ||
StandardOutput = "journal"; | ||
StandardError = "journal"; | ||
}; | ||
}; | ||
}; | ||
|
||
# Open TCP port for the XDG socket | ||
networking.firewall.allowedTCPPorts = [ cfg.xdgPort ]; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.