pkgs: borderlessBrowser

This commit is contained in:
Zynh Ludwig 2024-08-17 22:44:09 -07:00
parent de6a416958
commit 97bb4b6327
3 changed files with 175 additions and 0 deletions

View file

@ -0,0 +1,91 @@
#!/usr/bin/env bash
set -eu
function die {
supress_generic_error=1
if [ -v bin_ZENITY ] && [ ! -z "$bin_ZENITY" ]; then
"$bin_ZENITY" --error --text="$*"
else
echo "error: $*" 2>&2
fi
}
function absolute_binary {
bin="$(command -v "$@" 2>&-)"
if [ -z "$bin" ]; then
die "No such commands: $@"
fi
echo $bin | head -n 1
}
function cleanup {
if [ $? != 0 ] && [ ! -v supress_generic_error ]; then
die "Errors happened during runtime. See this script logs for details."
fi
}
trap cleanup EXIT
CHROME_BINARIES=(chromium)
if [ ! -v bin_ZENITY ]; then
bin_ZENITY="$(absolute_binary zenity)"
fi
if [ ! -v bin_CHROMIUM ]; then
bin_CHROMIUM="$(absolute_binary chromium)"
fi
if [ ! -v text_QUERY ]; then
text_QUERY="Link to be opened"
fi
if [ ! -v text_NOURL ]; then
text_NOURL="No URL specified"
fi
if [ $# -eq 0 ]; then
URL="$("$bin_ZENITY" --entry --text="$text_QUERY" || true)"
else
URL="$@"
fi
if [ -z "$URL" ]; then
die $text_NOURL
fi
if [[ "$URL" =~ ^~ ]]; then
URL=$(echo $URL | sed -E s:^~\/?::)
URL="file://$HOME/$URL"
fi
if [[ "$URL" =~ ^\/ ]]; then
URL="file://$URL"
fi
if [[ ! "$URL" =~ ^(file|https?)?:\/\/ ]]; then
URL="https://$URL"
fi
echo final url: $URL
chromeFlags=()
if [ ! -v CHROME_DONT_BORDERLESS ]; then
chromeFlags+=(--app="$URL")
else
chromeFlags+=("$URL")
fi
if [ ! -v profileToplevel ]; then
profileToplevel=~/.config/borderless-browser-profiles
fi
if [ -v CHROME_PROFILE ] && [[ "$CHROME_PROFILE" =~ ^[a-zA-Z_0-9-]*$ ]]; then
profileDir=$profileToplevel/$CHROME_PROFILE
chromeFlags+=(--user-data-dir="$profileDir")
fi
echo "${chromeFlags[@]}"
"$bin_CHROMIUM" "${chromeFlags[@]}"

View file

@ -0,0 +1,83 @@
{ lib
, stdenvNoCC
, chromium
, gnome3
, zenity ? gnome3.zenity
, makeDesktopItem
, copyDesktopItems
, makeWrapper
}:
let
mkWebapp =
{ name ? "webapp"
, desktopName ? "Web Application"
, browser ? lib.getExe chromium
, icon ? "applications-internet"
, url ? null
, queryText ? "Link to be opened"
, noURLSpecifiedText ? "No URL specified"
, profile ? null
, passthru ? { }
}:
let
makeWrapperArgs = [
"--set-default"
"text_QUERY"
queryText
"--set-default"
"text_NOURL"
noURLSpecifiedText
"--set"
"bin_CHROMIUM"
browser
"--set"
"bin_ZENITY"
(lib.getExe zenity)
]
++ (lib.optionals (profile != null) [ "--set" "CHROME_PROFILE" profile ])
++ (lib.optionals (url != null) [ "--add-flags" url ])
;
in
stdenvNoCC.mkDerivation (attrs: {
name = "webapp-${name}";
dontUnpack = true;
nativeBuildInputs = [ copyDesktopItems makeWrapper ];
installPhase = ''
runHook preInstall
mkdir -p $out/bin
makeWrapper ${./borderlessBrowser} $out/bin/$name ${lib.escapeShellArgs makeWrapperArgs}
runHook postInstall
'';
postFixup = ''
substituteInPlace $out/share/applications/$name.desktop --replace @bin@ $out/bin/$name
'';
desktopItems = [
(makeDesktopItem {
inherit (attrs) name;
inherit desktopName icon;
type = "Application";
exec = "@bin@";
})
];
passthru = passthru // { inherit makeWrapperArgs; };
});
in
mkWebapp {
passthru = {
wrap = mkWebapp;
};
}

View file

@ -5,4 +5,5 @@ in
{
wrapWine = callDefaultPackage ./wrapWine;
writeXrandrScriptBin = callDefaultPackage ./writeXrandrScriptBin;
borderlessBrowser = callDefaultPackage ./writeXrandrScriptBin;
}