Skip to content

Commit 8dfda93

Browse files
authored
Merge pull request #27 from ruscher/main
Add new A.I. LibreThinker
2 parents ff3506f + c4b50c2 commit 8dfda93

2 files changed

Lines changed: 83 additions & 0 deletions

File tree

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#!/bin/bash
2+
#Translation
3+
export TEXTDOMAINDIR="/usr/share/locale"
4+
export TEXTDOMAIN=biglinux-settings
5+
6+
check_state() {
7+
! command -v unopkg &>/dev/null && echo "false" && return
8+
LC_ALL=C unopkg list --shared >/tmp/u_s 2>&1
9+
LC_ALL=C unopkg list >/tmp/u_u 2>&1
10+
if grep -qi "LibreThinker" /tmp/u_s /tmp/u_u || find "$HOME/.config/libreoffice" -name "*LibreThinker*" 2>/dev/null | grep -q .; then echo "true"; else echo "false"; fi
11+
rm -f /tmp/u_s /tmp/u_u
12+
}
13+
14+
do_remove() {
15+
# Try to remove
16+
if unopkg remove -v "$1" >/tmp/u_log 2>&1; then
17+
# Success? Clean up residuals anyway to be sure
18+
find "$HOME/.config/libreoffice" -name "*LibreThinker*" -exec rm -rf {} + 2>/dev/null
19+
zenity --info --text=$"O LibreThinker foi removido com sucesso."
20+
return 0
21+
fi
22+
23+
ERR=$(cat /tmp/u_log)
24+
25+
# Lock file check
26+
if echo "$ERR" | grep -q ".lock"; then
27+
LOCK=$(echo "$ERR" | grep ".lock" | tail -1 | awk '{print $NF}' | tr -d ':')
28+
[ -z "$LOCK" ] || [ ! -f "$LOCK" ] && LOCK="$HOME/.config/libreoffice/4/.lock"
29+
30+
if zenity --question --title=$"Erro de Bloqueio" --text=$"O LibreOffice parece estar bloqueado (arquivo .lock encontrado).\n\nDeseja remover o arquivo de bloqueio e tentar novamente?"; then
31+
rm -f "$LOCK"
32+
if unopkg remove -v "$1" >>/tmp/u_log 2>&1; then
33+
find "$HOME/.config/libreoffice" -name "*LibreThinker*" -exec rm -rf {} + 2>/dev/null
34+
zenity --info --text=$"O LibreThinker foi removido com sucesso."
35+
return 0
36+
fi
37+
ERR=$(cat /tmp/u_log)
38+
fi
39+
fi
40+
41+
# Not deployed check
42+
if echo "$ERR" | grep -Eq "Não foi implantada|not deployed|IllegalArgumentException"; then
43+
zenity --info --text=$"A extensão não foi encontrada no registro do LibreOffice.\nArquivos residuais serão limpos."
44+
find "$HOME/.config/libreoffice" -name "*LibreThinker*" -exec rm -rf {} + 2>/dev/null
45+
return 0
46+
fi
47+
48+
zenity --error --text=$"Falha ao remover o LibreThinker (ID: $1).\n\n$ERR"
49+
exit 1
50+
}
51+
52+
toggle_state() {
53+
! command -v libreoffice &>/dev/null && zenity --error --text=$"O LibreOffice não foi encontrado." && exit 1
54+
if [[ "$1" == "true" ]]; then
55+
DEST="/tmp/LibreThinker.oxt"
56+
(curl -L "https://extensions.libreoffice.org/assets/downloads/7313/1768943183/LibreThinker.oxt" -o "$DEST" 2>&1 | stdbuf -oL tr '\r' '\n' | grep -oE '[0-9]+' | while read -r s; do echo "$s"; echo "# "$"Baixando extensão"" ($s%)"; done) | zenity --progress --title="Download" --text=$"Iniciando..." --percentage=0 --auto-close
57+
echo "no" | unopkg add -v -f "$DEST" >/tmp/rl 2>&1
58+
sed -i 's/\\X000d\\X000a/\n/g; s/\\X000a/\n/g; s/\\Xfeff//g; s/\\\"/\"/g' /tmp/rl
59+
sed -n '/Mozilla/,/\[Digite/p' /tmp/rl | head -n -1 >/tmp/fl
60+
[ ! -s /tmp/fl ] && echo -e $"Acordo de Licença de Software da extensão LibreThinker:\nMozilla Public License Version 2.0\n\n(O texto completo será processado durante a instalação)" >/tmp/fl
61+
echo -e "\n\n"$"Leia o contrato acima. Para aceitar, clique em 'Sim'.\n[O sistema enviará 'sim' automaticamente ao clicar]" >>/tmp/fl
62+
zenity --text-info --title=$"Acordo de Licença" --filename=/tmp/fl --ok-label=$"Sim" --cancel-label=$"Não" --width=750 --height=600 || { rm -f "$DEST" /tmp/rl /tmp/fl; return 0; }
63+
(echo "# "$"Finalizando instalação... Fechando LibreOffice."; pkill -9 soffice.bin 2>/dev/null; sleep 1; yes "sim" | unopkg add -v -f "$DEST" >/tmp/ul 2>&1 && echo "100" || exit 1) | zenity --progress --title=$"Instalação" --text=$"Registrando..." --pulsate --auto-close
64+
[ $? -eq 0 ] && { (zenity --question --title=$"Sucesso" --text=$"Instalado! Abrir LibreOffice agora?" --ok-label=$"Sim" --cancel-label=$"Não" && setsid libreoffice --writer >/dev/null 2>&1 &) >/dev/null 2>&1 & } || zenity --error --text=$"Erro na instalação:\n\n$(tail -n 5 /tmp/ul)"
65+
rm -f "$DEST" /tmp/rl /tmp/fl /tmp/ul
66+
else
67+
pkill -9 soffice.bin 2>/dev/null
68+
find_id() { [ -f "$1" ] && L=$(grep -n "LibreThinker" "$1" | head -1 | cut -d: -f1) && [ -n "$L" ] && head -n "$L" "$1" | grep "Identifier:" | tail -1 | awk '{print $2}'; }
69+
LC_ALL=C unopkg list --shared >/tmp/u_s 2>&1; LC_ALL=C unopkg list >/tmp/u_u 2>&1
70+
ID=$(find_id /tmp/u_s); [ -z "$ID" ] && ID=$(find_id /tmp/u_u); [ -z "$ID" ] && ID="LibreThinker"
71+
do_remove "$ID"; rm -f /tmp/u_s /tmp/u_u /tmp/u_log
72+
fi
73+
}
74+
case "$1" in "check") check_state ;; "toggle") toggle_state "$2" ;; *) echo "Use: $0 {check|toggle} [true|false]" && exit 1 ;; esac

usr/share/biglinux/biglinux-settings/ai_page.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,14 @@ def __init__(self, main_window, **kwargs):
3333
"chatai-symbolic",
3434
)
3535

36+
# LibreThinker
37+
self.create_row(
38+
group,
39+
_("LibreThinker: AI Copilot for LibreOffice"),
40+
_("Generative AI assistant for rewriting, summarizing, translating, and proofreading text. Use free models or your own API key (OpenAI, Mistral, Groq)."),
41+
"librethinker",
42+
"libreoffice-symbolic",
43+
)
44+
3645
# Syncs
3746
self.sync_all_switches()

0 commit comments

Comments
 (0)