aboutsummarylogtreecommitdiffstats
path: root/granola.in
blob: d073f3cb02974be98d591f86eef5551eccd04f72 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/env bash
set -euo pipefail

pkgver="@PKGVER@"
export WINEPREFIX="${GRANOLA_WINEPREFIX:-${HOME}/.wine-prefixes/granola}"

if [[ "${GRANOLA_WINE_ENABLE_SELF_UPDATES:-0}" != "1" ]]; then
  export GRANOLA_FEATURES='{"UPDATE_CHECKS":false}'
fi

app_src="${GRANOLA_WINE_APP_SRC:-/opt/granola-wine/app}"
wine_user="${WINEUSER:-$(id -un)}"
app_dst="${WINEPREFIX}/drive_c/users/${wine_user}/AppData/Local/Programs/@granolaelectron"
updater_cache="${WINEPREFIX}/drive_c/users/${wine_user}/AppData/Local/@granolaelectron-updater"
user_data="${WINEPREFIX}/drive_c/users/${wine_user}/AppData/Roaming/Granola"
log_dir="${XDG_DATA_HOME:-${HOME}/.local/share}/granola-wine"
log_file="${log_dir}/granola.log"
exe_path="C:\\users\\${wine_user}\\AppData\\Local\\Programs\\@granolaelectron\\Granola.exe"

mkdir -p "$log_dir" "$WINEPREFIX"

if [[ ! -f "${WINEPREFIX}/.granola-wine-url-handler-configured" ]]; then
  xdg-mime default granola-wine.desktop x-scheme-handler/granola \
    < /dev/null >> "$log_file" 2>&1 || true
  xdg-settings set default-url-scheme-handler granola granola-wine.desktop \
    < /dev/null >> "$log_file" 2>&1 || true
  touch "${WINEPREFIX}/.granola-wine-url-handler-configured"
fi

if [[ ! -e "${WINEPREFIX}/system.reg" ]]; then
  WINEPREFIX="$WINEPREFIX" wineboot -u < /dev/null >> "$log_file" 2>&1 || true
fi

if [[ ! -f "${WINEPREFIX}/.granola-wine-x11-decorations-configured" ]]; then
  WINEPREFIX="$WINEPREFIX" wine reg add 'HKCU\Software\Wine\X11 Driver' /v Decorated /t REG_SZ /d N /f \
    < /dev/null >> "$log_file" 2>&1 || true
  WINEPREFIX="$WINEPREFIX" wine reg add 'HKCU\Software\Wine\X11 Driver' /v Managed /t REG_SZ /d Y /f \
    < /dev/null >> "$log_file" 2>&1 || true
  touch "${WINEPREFIX}/.granola-wine-x11-decorations-configured"
fi

if [[ "${GRANOLA_WINE_ENABLE_SELF_UPDATES:-0}" != "1" ]]; then
  rm -rf "${updater_cache}/pending"
  rm -f "${user_data}/installing-update.txt"
fi

if [[ ! -x "${app_dst}/Granola.exe" ]] || [[ ! -f "${app_dst}/.granola-wine-pkgver" ]] || [[ "$(cat "${app_dst}/.granola-wine-pkgver" 2>/dev/null)" != "$pkgver" ]]; then
  rm -rf "$app_dst"
  mkdir -p "$(dirname "$app_dst")"
  cp -a "$app_src" "$app_dst"
  printf '%s\n' "$pkgver" > "${app_dst}/.granola-wine-pkgver"
fi

exec wine "$exe_path" "$@" < /dev/null >> "$log_file" 2>&1