mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 14:02:21 -04:00
Expose control over AppNap for AnkiConnect
https://forums.ankiweb.net/t/recent-anki-updates-bundle-id-change-disabling-app-nap-macos-anki-connect/65550
This commit is contained in:
parent
f3b4284afb
commit
78a3b3ef7b
8 changed files with 51 additions and 7 deletions
|
@ -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
|
||||
|
|
25
qt/mac/appnap.swift
Normal file
25
qt/mac/appnap.swift
Normal 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
|
||||
}
|
|
@ -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!"
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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" }
|
||||
|
|
14
qt/mac/update-launcher-env
Executable file
14
qt/mac/update-launcher-env
Executable 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
|
||||
|
|
@ -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",
|
||||
|
|
6
uv.lock
6
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" },
|
||||
|
|
Loading…
Reference in a new issue