#!/bin/bash

# Définition du fichier de log
LOG_DIR="$HOME/.logs"
LOG_FILE="$LOG_DIR/flatpak_install.log"

# Création du répertoire de logs
mkdir -p "$LOG_DIR"

# Fonction de logging
log() {
    echo "$(date +"%Y-%m-%d %H:%M:%S") | $1" | tee -a "$LOG_FILE"
}

log "Début de l'installation de VSCode Stable via Flatpak."

# Ajout du dépôt Flathub
log "Ajout du dépôt Flathub..."
flatpak remote-add --if-not-exists flathub https://flathub.org/repo/flathub.flatpakrepo
log "Flathub ajouté."

# Installation de VSCode Stable
log "Installation de VSCode Stable..."
flatpak install -y flathub com.visualstudio.code
log "Installation terminée."

# Accorder les autorisations
log "Configuration des autorisations..."
flatpak override --user --filesystem=host com.visualstudio.code
flatpak override --user --device=all com.visualstudio.code
flatpak override --user --socket=system-bus com.visualstudio.code
log "Autorisations accordées."

log "Installation et configuration de VSCode Stable terminées avec succès ! 🚀"