Monitor: parole chiave di esclusione dagli avvisi
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
1 parent
43c935f395
commit
fdb954b92e
5 files changed
+71
-3
No files matched your search
+56
-3
@@ -53,6 +53,56 @@ def make_icon(dest_icns: Path) -> None:
|
||||
shutil.rmtree(iconset, ignore_errors=True)
|
||||
|
||||
|
||||
LAUNCHER_C = r'''
|
||||
// Lanciatore nativo di LuZa: avvia Python come processo figlio, così i permessi
|
||||
// di macOS (microfono, disco, contatti…) concessi all'app valgono anche per Python.
|
||||
#include <spawn.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/wait.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/stat.h>
|
||||
extern char **environ;
|
||||
int main(void) {
|
||||
const char *home = getenv("HOME"); if (!home) home = "/tmp";
|
||||
char path[4096]; snprintf(path, sizeof path, "%s/.local/bin:/opt/homebrew/bin:/usr/local/bin:%s", home, getenv("PATH") ? getenv("PATH") : "/usr/bin:/bin");
|
||||
setenv("PATH", path, 1);
|
||||
unsetenv("CLAUDECODE"); unsetenv("CLAUDE_CONFIG_DIR"); unsetenv("ANTHROPIC_API_KEY");
|
||||
setenv("PYTHONUNBUFFERED", "1", 1);
|
||||
if (chdir(PROJECT_DIR) != 0) { perror("chdir"); return 1; }
|
||||
char logdir[4096]; snprintf(logdir, sizeof logdir, "%s/Library/Logs", home); mkdir(logdir, 0755);
|
||||
char logfile[4096]; snprintf(logfile, sizeof logfile, "%s/Library/Logs/" APP_NAME ".log", home);
|
||||
int fd = open(logfile, O_WRONLY | O_CREAT | O_APPEND, 0644);
|
||||
posix_spawn_file_actions_t fa; posix_spawn_file_actions_init(&fa);
|
||||
if (fd >= 0) { posix_spawn_file_actions_adddup2(&fa, fd, 1); posix_spawn_file_actions_adddup2(&fa, fd, 2); }
|
||||
char *argv[] = { PYTHON_BIN, "main.py", NULL };
|
||||
pid_t pid; int rc = posix_spawn(&pid, PYTHON_BIN, &fa, NULL, argv, environ);
|
||||
if (rc != 0) { fprintf(stderr, "posix_spawn: %s\n", strerror(rc)); return 1; }
|
||||
int status = 0; waitpid(pid, &status, 0);
|
||||
return WIFEXITED(status) ? WEXITSTATUS(status) : 1;
|
||||
}
|
||||
'''
|
||||
|
||||
|
||||
def build_native_launcher(dest: Path, python: Path) -> bool:
|
||||
"""Compila il lanciatore in C (serve clang, presente con Xcode o i Command Line Tools)."""
|
||||
if not shutil.which("xcrun"):
|
||||
return False
|
||||
src = dest.parent / "launcher.c"
|
||||
src.write_text(LAUNCHER_C.replace("PROJECT_DIR", f'"{PROJECT}"').replace("PYTHON_BIN", f'"{python}"').replace("APP_NAME", f'"{APP_NAME}"'))
|
||||
# Compilatore di Xcode con ambiente pulito (le variabili di Homebrew possono rompere il link).
|
||||
env = {k: v for k, v in os.environ.items() if k not in ("LDFLAGS", "CPPFLAGS", "CFLAGS", "LIBRARY_PATH", "CPATH", "SDKROOT")}
|
||||
res = subprocess.run(["xcrun", "clang", "-O2", "-o", str(dest), str(src)], capture_output=True, text=True, env=env)
|
||||
src.unlink(missing_ok=True)
|
||||
if res.returncode != 0:
|
||||
print(res.stderr[-400:])
|
||||
return False
|
||||
dest.chmod(0o755)
|
||||
return True
|
||||
|
||||
|
||||
def build(dest_dir: Path) -> Path:
|
||||
app = dest_dir / f"{APP_NAME}.app"
|
||||
shutil.rmtree(app, ignore_errors=True)
|
||||
@@ -62,7 +112,10 @@ def build(dest_dir: Path) -> Path:
|
||||
if not python.exists():
|
||||
sys.exit("Ambiente .venv non trovato: esegui prima `uv sync` nella cartella del progetto.")
|
||||
launcher = app / "Contents" / "MacOS" / APP_NAME
|
||||
launcher.write_text(f'''#!/bin/bash
|
||||
if build_native_launcher(launcher, python):
|
||||
print("Lanciatore nativo compilato.")
|
||||
else:
|
||||
launcher.write_text(f'''#!/bin/bash
|
||||
# Avvio di {APP_NAME}: usa l'ambiente Python del progetto.
|
||||
export PATH="$HOME/.local/bin:/opt/homebrew/bin:/usr/local/bin:$PATH"
|
||||
unset CLAUDECODE CLAUDE_CONFIG_DIR ANTHROPIC_API_KEY
|
||||
@@ -71,7 +124,7 @@ cd "{PROJECT}" || exit 1
|
||||
mkdir -p "$HOME/Library/Logs"
|
||||
exec "{python}" main.py >> "$HOME/Library/Logs/{APP_NAME}.log" 2>&1
|
||||
''')
|
||||
launcher.chmod(0o755)
|
||||
launcher.chmod(0o755)
|
||||
make_icon(app / "Contents" / "Resources" / f"{APP_NAME}.icns")
|
||||
info = {
|
||||
"CFBundleName": APP_NAME, "CFBundleDisplayName": APP_NAME, "CFBundleIdentifier": BUNDLE_ID,
|
||||
@@ -89,7 +142,7 @@ exec "{python}" main.py >> "$HOME/Library/Logs/{APP_NAME}.log" 2>&1
|
||||
}
|
||||
with open(app / "Contents" / "Info.plist", "wb") as f:
|
||||
plistlib.dump(info, f)
|
||||
subprocess.run(["codesign", "--force", "--deep", "--sign", "-", str(app)], check=False, capture_output=True)
|
||||
subprocess.run(["codesign", "--force", "--deep", "--sign", "-", "--identifier", BUNDLE_ID, str(app)], check=False, capture_output=True)
|
||||
return app
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user