Commit 7244c6a
Changed files (3)
modules
desktop
app
noctalia
users
hpcesia
modules/desktop/app/ocr.nix
@@ -0,0 +1,78 @@
+{
+ den.aspects.desktop.app.ocr = {
+ hjem = {pkgs, ...}: let
+ ix-ocr-script = pkgs.callPackage ({
+ writeShellApplication,
+ coreutils,
+ grim,
+ libnotify,
+ slurp,
+ tesseract,
+ wl-clipboard-rs,
+ languages ? "eng+chi_sim+chi_tra",
+ psm ? "6",
+ }: (writeShellApplication {
+ name = "ix-ocr";
+ runtimeInputs = [
+ coreutils
+ grim
+ libnotify
+ slurp
+ tesseract
+ wl-clipboard-rs
+ ];
+ text = ''
+ geom="$(slurp -d)" || exit 0
+
+ img="$(mktemp --suffix=.png)"
+ trap 'rm -f "$img"' EXIT
+
+ grim -g "$geom" "$img" || {
+ notify-send -u critical "OCR" "Screenshot failed (grim)"
+ exit 1
+ }
+
+ text="$(tesseract "$img" stdout -l ${languages} --psm ${psm} 2>/dev/null)" || {
+ notify-send -u critical "OCR" "Text recognition failed (tesseract)"
+ exit 1
+ }
+
+ if [ -z "$(printf '%s' "$text" | tr -d '[:space:]')" ]; then
+ notify-send "OCR" "No text recognized in the selection"
+ exit 0
+ fi
+
+ printf '%s' "$text" | wl-copy
+ printf '%s\n' "$text"
+ '';
+ meta.mainProgram = "ix-ocr";
+ })) {};
+
+ ix-ocr-desktop-entry = pkgs.makeDesktopItem {
+ name = "ix-ocr";
+ exec = "ix-ocr";
+ icon = "scanner";
+ desktopName = "OCR Text Grab";
+ comment = "Select a screen region and copy its text";
+ categories = ["Utility" "Graphics"];
+ keywords = ["ocr" "text" "scan"];
+ terminal = false;
+ startupNotify = false;
+ };
+
+ ix-ocr = pkgs.stdenv.mkDerivation rec {
+ name = "ix-ocr";
+ buildCommand = let
+ in ''
+ mkdir -p $out/bin
+ cp ${ix-ocr-script}/bin/${name} $out/bin
+ mkdir -p $out/share/applications
+ cp ${ix-ocr-desktop-entry}/share/applications/${name}.desktop $out/share/applications/${name}.desktop
+ '';
+ dontBuild = true;
+ };
+ in {
+ packages = [ix-ocr];
+ };
+ };
+}
modules/desktop/noctalia/default.nix
@@ -34,10 +34,6 @@
plugins =
{
- "fel/ocr" = {
- src = "${communityPlugins}/ocr";
- systemDeps = [pkgs.slurp pkgs.grim pkgs.tesseract];
- };
"noctalia/kaomoji".src = "${officialPlugins}/kaomoji";
}
// (lib.optionalAttrs
@@ -98,10 +94,6 @@
];
};
plugin_settings = {
- "fel/ocr" = {
- languages = "eng+chi_sim+chi_tra";
- show_notification = false;
- };
"icefish/phone-connect" = {
language = "zh-Hans";
auto_select_online = true;
@@ -158,7 +150,6 @@
{type = "wallpaper";}
{type = "caffeine";}
{type = "notification";}
- {type = "fel/ocr:grab";}
];
};
launcher = {
modules/users/hpcesia/desktop.nix
@@ -28,6 +28,7 @@
desktop.app.nixpak.telegram
desktop.app.nixpak.wechat
desktop.app.obs-studio
+ desktop.app.ocr
desktop.app.picard
desktop.app.term.foot
desktop.app.thunderbird