Add files via upload

This commit is contained in:
Daniil Rakhov 2021-04-19 09:24:07 +03:00 committed by GitHub
parent a6fb047189
commit b86c57c4d3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 37 additions and 4 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,8 @@ from __future__ import annotations
from typing import TYPE_CHECKING
from dataclasses import dataclass
from ba import print_exception
import _ba
if TYPE_CHECKING:
@ -33,8 +35,28 @@ class PluginSubsystem:
try:
plugin.on_app_launch()
except Exception:
from ba import _error
_error.print_exception('Error in plugin on_app_launch()')
print_exception('Error in plugin on_app_launch()')
def on_app_pause(self) -> None:
for plugin in self.active_plugins.values():
try:
plugin.on_app_pause()
except Exception:
print_exception('Error in plugin on_app_pause()')
def on_app_resume(self) -> None:
for plugin in self.active_plugins.values():
try:
plugin.on_app_resume()
except Exception:
print_exception('Error in plugin on_app_resume()')
def on_app_shutdown(self) -> None:
for plugin in self.active_plugins.values():
try:
plugin.on_app_shutdown()
except Exception:
print_exception('Error in plugin on_app_shutdown()')
def load_plugins(self) -> None:
"""(internal)"""
@ -61,8 +83,7 @@ class PluginSubsystem:
assert plugkey not in self.active_plugins
self.active_plugins[plugkey] = plugin
except Exception:
from ba import _error
_error.print_exception(f'Error loading plugin: {plugkey}')
print_exception(f'Error loading plugin: {plugkey}')
@dataclass
@ -94,3 +115,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."""