Damien Elmes 2025-08-19 19:45:45 +10:00
parent f3b4284afb
commit 78a3b3ef7b
8 changed files with 51 additions and 7 deletions

View file

@ -33,6 +33,12 @@ class _MacOSHelper:
"On completion, file should be saved if no error has arrived." "On completion, file should be saved if no error has arrived."
self._dll.end_wav_record() 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 # this must not be overwritten or deallocated
@CFUNCTYPE(None, c_char_p) # type: ignore @CFUNCTYPE(None, c_char_p) # type: ignore

25
qt/mac/appnap.swift Normal file
View file

@ -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
}

View file

@ -15,6 +15,7 @@ echo "Building macOS helper dylib..."
# Create the wheel using uv # Create the wheel using uv
echo "Creating wheel..." echo "Creating wheel..."
cd "$SCRIPT_DIR" cd "$SCRIPT_DIR"
rm -rf dist
"$PROJ_ROOT/out/extracted/uv/uv" build --wheel "$PROJ_ROOT/out/extracted/uv/uv" build --wheel
echo "Build complete!" echo "Build complete!"

View file

@ -1,8 +1,6 @@
# Copyright: Ankitects Pty Ltd and contributors # Copyright: Ankitects Pty Ltd and contributors
# License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html # License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
import os
import platform
import subprocess import subprocess
import sys import sys
from pathlib import Path from pathlib import Path

View file

@ -4,7 +4,7 @@ build-backend = "hatchling.build"
[project] [project]
name = "anki-mac-helper" name = "anki-mac-helper"
version = "0.1.0" version = "0.1.1"
description = "Small support library for Anki on Macs" description = "Small support library for Anki on Macs"
requires-python = ">=3.9" requires-python = ">=3.9"
license = { text = "AGPL-3.0-or-later" } license = { text = "AGPL-3.0-or-later" }

14
qt/mac/update-launcher-env Executable file
View file

@ -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

View file

@ -12,7 +12,7 @@ dependencies = [
"send2trash", "send2trash",
"waitress>=2.0.0", "waitress>=2.0.0",
"pywin32; sys.platform == 'win32'", "pywin32; sys.platform == 'win32'",
"anki-mac-helper; sys.platform == 'darwin'", "anki-mac-helper>=0.1.1; sys.platform == 'darwin'",
"pip-system-certs!=5.1", "pip-system-certs!=5.1",
"pyqt6>=6.2", "pyqt6>=6.2",
"pyqt6-webengine>=6.2", "pyqt6-webengine>=6.2",

View file

@ -147,10 +147,10 @@ dev = [
[[package]] [[package]]
name = "anki-mac-helper" name = "anki-mac-helper"
version = "0.1.0" version = "0.1.1"
source = { registry = "https://pypi.org/simple" } source = { registry = "https://pypi.org/simple" }
wheels = [ 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]] [[package]]
@ -214,7 +214,7 @@ qt68 = [
[package.metadata] [package.metadata]
requires-dist = [ 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-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 = "beautifulsoup4" },
{ name = "flask" }, { name = "flask" },
{ name = "flask-cors" }, { name = "flask-cors" },