Merge pull request #264 from drov-drov/master

Some additions for plugins subsystem
This commit is contained in:
Eric Froemling 2021-04-19 18:34:40 -07:00 committed by GitHub
commit bfce939164
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 40 additions and 0 deletions

View File

@ -484,6 +484,7 @@ class App:
def on_app_pause(self) -> None:
"""Called when the app goes to a suspended state."""
self.plugins.on_app_pause()
def on_app_resume(self) -> None:
"""Run when the app resumes from a suspended state."""
@ -491,6 +492,7 @@ class App:
self.fg_state += 1
self.accounts.on_app_resume()
self.music.on_app_resume()
self.plugins.on_app_resume()
def launch_coop_game(self,
game: str,
@ -543,6 +545,7 @@ class App:
def on_app_shutdown(self) -> None:
"""(internal)"""
self.music.on_app_shutdown()
self.plugins.on_app_shutdown()
def handle_deep_link(self, url: str) -> None:
"""Handle a deep link URL."""

View File

@ -6,6 +6,7 @@ from __future__ import annotations
from typing import TYPE_CHECKING
from dataclasses import dataclass
import _ba
if TYPE_CHECKING:
@ -36,6 +37,33 @@ class PluginSubsystem:
from ba import _error
_error.print_exception('Error in plugin on_app_launch()')
def on_app_pause(self) -> None:
"""Called when the app goes to a suspended state."""
for plugin in self.active_plugins.values():
try:
plugin.on_app_pause()
except Exception:
from ba import _error
_error.print_exception('Error in plugin on_app_pause()')
def on_app_resume(self) -> None:
"""Run when the app resumes from a suspended state."""
for plugin in self.active_plugins.values():
try:
plugin.on_app_resume()
except Exception:
from ba import _error
_error.print_exception('Error in plugin on_app_resume()')
def on_app_shutdown(self) -> None:
"""Called when the app is being closed."""
for plugin in self.active_plugins.values():
try:
plugin.on_app_shutdown()
except Exception:
from ba import _error
_error.print_exception('Error in plugin on_app_shutdown()')
def load_plugins(self) -> None:
"""(internal)"""
from ba._general import getclass
@ -94,3 +122,12 @@ class Plugin:
def on_app_launch(self) -> None:
"""Called when the app is being launched."""
def on_app_pause(self) -> None:
"""Сalled after pausing game activity."""
def on_app_resume(self) -> None:
"""Called after the game continues."""
def on_app_shutdown(self) -> None:
"""Called before closing the application."""