diff --git a/qt/mac/anki_mac_helper/__init__.py b/qt/mac/anki_mac_helper/__init__.py index a0adb469e..88dfedc8d 100644 --- a/qt/mac/anki_mac_helper/__init__.py +++ b/qt/mac/anki_mac_helper/__init__.py @@ -33,6 +33,12 @@ class _MacOSHelper: "On completion, file should be saved if no error has arrived." self._dll.end_wav_record() + def disable_appnap(self) -> None: + self._dll.disable_appnap() + + def enable_appnap(self) -> None: + self._dll.enable_appnap() + # this must not be overwritten or deallocated @CFUNCTYPE(None, c_char_p) # type: ignore diff --git a/qt/mac/appnap.swift b/qt/mac/appnap.swift new file mode 100644 index 000000000..1e6db3d17 --- /dev/null +++ b/qt/mac/appnap.swift @@ -0,0 +1,25 @@ +// Copyright: Ankitects Pty Ltd and contributors +// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html + +import Foundation + +private var currentActivity: NSObjectProtocol? + +@_cdecl("disable_appnap") +public func disableAppNap() { + // No-op if already assigned + guard currentActivity == nil else { return } + + currentActivity = ProcessInfo.processInfo.beginActivity( + options: .userInitiatedAllowingIdleSystemSleep, + reason: "AppNap is disabled" + ) +} + +@_cdecl("enable_appnap") +public func enableAppNap() { + guard let activity = currentActivity else { return } + + ProcessInfo.processInfo.endActivity(activity) + currentActivity = nil +} \ No newline at end of file diff --git a/qt/mac/build.sh b/qt/mac/build.sh index 4c14a13f4..06a34ad36 100755 --- a/qt/mac/build.sh +++ b/qt/mac/build.sh @@ -15,6 +15,7 @@ echo "Building macOS helper dylib..." # Create the wheel using uv echo "Creating wheel..." cd "$SCRIPT_DIR" +rm -rf dist "$PROJ_ROOT/out/extracted/uv/uv" build --wheel echo "Build complete!" diff --git a/qt/mac/helper_build.py b/qt/mac/helper_build.py index aaf997669..cfdffeb89 100644 --- a/qt/mac/helper_build.py +++ b/qt/mac/helper_build.py @@ -1,8 +1,6 @@ # Copyright: Ankitects Pty Ltd and contributors # License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html -import os -import platform import subprocess import sys from pathlib import Path diff --git a/qt/mac/pyproject.toml b/qt/mac/pyproject.toml index 93f4e939b..ec78845d6 100644 --- a/qt/mac/pyproject.toml +++ b/qt/mac/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "hatchling.build" [project] name = "anki-mac-helper" -version = "0.1.0" +version = "0.1.1" description = "Small support library for Anki on Macs" requires-python = ">=3.9" license = { text = "AGPL-3.0-or-later" } diff --git a/qt/mac/update-launcher-env b/qt/mac/update-launcher-env new file mode 100755 index 000000000..3150d1740 --- /dev/null +++ b/qt/mac/update-launcher-env @@ -0,0 +1,14 @@ +#!/bin/bash +# +# Build and install into the launcher venv + +set -e + +./build.sh +if [[ "$OSTYPE" == "darwin"* ]]; then + export VIRTUAL_ENV=$HOME/Library/Application\ Support/AnkiProgramFiles/.venv +else + export VIRTUAL_ENV=$HOME/.local/share/AnkiProgramFiles/.venv +fi +../../out/extracted/uv/uv pip install dist/*.whl + diff --git a/qt/pyproject.toml b/qt/pyproject.toml index 1ff34f59d..35ecaa200 100644 --- a/qt/pyproject.toml +++ b/qt/pyproject.toml @@ -12,7 +12,7 @@ dependencies = [ "send2trash", "waitress>=2.0.0", "pywin32; sys.platform == 'win32'", - "anki-mac-helper; sys.platform == 'darwin'", + "anki-mac-helper>=0.1.1; sys.platform == 'darwin'", "pip-system-certs!=5.1", "pyqt6>=6.2", "pyqt6-webengine>=6.2", diff --git a/uv.lock b/uv.lock index d4277425a..b470d007d 100644 --- a/uv.lock +++ b/uv.lock @@ -147,10 +147,10 @@ dev = [ [[package]] name = "anki-mac-helper" -version = "0.1.0" +version = "0.1.1" source = { registry = "https://pypi.org/simple" } wheels = [ - { url = "https://files.pythonhosted.org/packages/b3/9f/c4d3e635ddbd2c6c24ff5454e96900fd2061b9abbb0198b9283446780d08/anki_mac_helper-0.1.0-py3-none-any.whl", hash = "sha256:ed449aba27ea3bc7999054afa10dacf08ef856ed7af46526d9c8599d8179a618", size = 40637, upload-time = "2025-06-19T14:38:07.672Z" }, + { url = "https://files.pythonhosted.org/packages/40/82/edb6194704defec181dddce8bc6a53c4afc72fa1f2bb4d68ffe244567767/anki_mac_helper-0.1.1-py3-none-any.whl", hash = "sha256:774a69cf9f0fe6d4b54949e2d6588a54a76ff51e78cbfc26b527d1ed3c5b34e3", size = 41812, upload-time = "2025-08-19T09:43:50.345Z" }, ] [[package]] @@ -214,7 +214,7 @@ qt68 = [ [package.metadata] requires-dist = [ { name = "anki-audio", marker = "(sys_platform == 'darwin' and extra == 'audio') or (sys_platform == 'win32' and extra == 'audio')", specifier = "==0.1.0" }, - { name = "anki-mac-helper", marker = "sys_platform == 'darwin'" }, + { name = "anki-mac-helper", marker = "sys_platform == 'darwin'", specifier = ">=0.1.1" }, { name = "beautifulsoup4" }, { name = "flask" }, { name = "flask-cors" },