Skip to content

Commit

Permalink
feat: increase robustness of macos-installer.py script regarding keyc…
Browse files Browse the repository at this point in the history
…hain access
  • Loading branch information
MShekow committed Sep 6, 2023
1 parent 74b3d90 commit de53fd8
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions macos-installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import json
import os
import shutil
import subprocess
import sys
from pathlib import Path
from typing import Optional, Tuple
Expand Down Expand Up @@ -71,7 +72,7 @@ def set_existing_installation_path(installation_path: Path):
CONFIG_FILE_PATH.write_text(str(installation_path))


def install_or_upgrade_app(temp_archive_path: Path, installation_path: Path):
def install_or_upgrade_app(temp_archive_path: Path, installation_path: Path, is_version_upgrade: bool = False):
is_replace = False
if installation_path.is_dir():
# clean the existing contents
Expand All @@ -90,7 +91,18 @@ def install_or_upgrade_app(temp_archive_path: Path, installation_path: Path):
urlcleanup()

if is_replace:
print("Successfully replaced your focus-time installation")
print("Successfully replaced your focus-time installation.")
if is_version_upgrade:
input("Note: the calendar credentials are stored in a macOS Keychain. Keychain detects that the "
"'focus-time' binary has changed (due to the version upgrade), and therefore rejects the new "
"binary's request to read the credentials, for security reasons. "
"Please press <enter> to run the 'sync' command, which will "
"cause a macOS dialog to show up, asking you to grant 'focus-time' access to the keychain again. "
"You will have to provide your password and then click 'Always allow'.")

focus_time_binary_path = installation_path / "focus-time"
output = subprocess.check_output([str(focus_time_binary_path), "sync"]).decode("utf-8")
print(f"Result of 'sync' command: {output}")
else:
print("Successfully installed focus-time")

Expand All @@ -106,7 +118,8 @@ def install_or_upgrade_app(temp_archive_path: Path, installation_path: Path):
existing_version, existing_path = existing_installation
if input(f"Found an existing version ({existing_version}) in '{existing_path}'. "
f"Do you want to overwrite it with a clean installation? If so, type 'y' or 'yes':\n") in ["y", "yes"]:
install_or_upgrade_app(temp_archive_path, existing_path)
install_or_upgrade_app(temp_archive_path, existing_path,
is_version_upgrade=latest_version != existing_version)
sys.exit(0)

installation_path = None
Expand Down

0 comments on commit de53fd8

Please sign in to comment.