Skip to content

Commit f6b43d6

Browse files
authored
Merge pull request #263 from ozer550/adopt-migrate-kolibri-new-hook-architecture
Migrate according to new hooks architecture in PR#12879
2 parents 3888a70 + e48acce commit f6b43d6

3 files changed

Lines changed: 34 additions & 16 deletions

File tree

src/android_app_plugin/kolibri_plugin.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
import logging
22

3+
from android_utils import is_active_network_metered
4+
from android_utils import os_user
5+
from android_utils import share_by_intent
36
from django.utils import timezone
47
from jnius import autoclass
8+
from kolibri.core.device.hooks import CheckIsMeteredHook
9+
from kolibri.core.device.hooks import GetOSUserHook
10+
from kolibri.core.device.hooks import ShareFileHook
511
from kolibri.core.tasks.hooks import StorageHook
612
from kolibri.core.tasks.job import Priority
713
from kolibri.plugins import KolibriPluginBase
@@ -20,6 +26,27 @@ class AndroidApp(KolibriPluginBase):
2026
pass
2127

2228

29+
@register_hook
30+
class AndroidGetOSUserHook(GetOSUserHook):
31+
def get_os_user(self, auth_token=None):
32+
return os_user(auth_token)
33+
34+
35+
@register_hook
36+
class AndroidCheckIsMeteredHook(CheckIsMeteredHook):
37+
def check_is_metered(self):
38+
try:
39+
return bool(is_active_network_metered())
40+
except Exception:
41+
return False
42+
43+
44+
@register_hook
45+
class AndroidShareFileHook(ShareFileHook):
46+
def share_file(self, *args, **kwargs):
47+
return share_by_intent(*args, **kwargs)
48+
49+
2350
@register_hook
2451
class StorageHook(StorageHook):
2552
def schedule(

src/main.py

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,9 @@
22

33
import initialization # noqa: F401 keep this first, to ensure we're set up for other imports
44
from android_utils import get_os_user_auth_token
5-
from android_utils import is_active_network_metered
6-
from android_utils import os_user
7-
from android_utils import share_by_intent
85
from jnius import autoclass
6+
from kolibri.core.device.utils import app_initialize_url
97
from kolibri.main import enable_plugin
10-
from kolibri.plugins.app.utils import interface
118
from kolibri.utils.cli import initialize
129
from kolibri.utils.server import BaseKolibriProcessBus
1310
from kolibri.utils.server import KolibriServerPlugin
@@ -34,25 +31,20 @@ def __init__(self, bus):
3431
self.bus.subscribe("SERVING", self.SERVING)
3532

3633
def SERVING(self, port):
37-
start_url = "http://127.0.0.1:{port}".format(
38-
port=port
39-
) + interface.get_initialize_url(auth_token=auth_token_value)
34+
start_url = "http://127.0.0.1:{port}".format(port=port) + app_initialize_url(
35+
auth_token=auth_token_value
36+
)
4037
loadUrl(start_url)
4138

4239

4340
logging.info("Initializing Kolibri and running any upgrade routines")
4441

45-
# activate app mode
46-
enable_plugin("kolibri.plugins.app")
42+
4743
enable_plugin("android_app_plugin")
4844

4945
# we need to initialize Kolibri to allow us to access the app key
5046
initialize()
5147

52-
interface.register(share_file=share_by_intent)
53-
interface.register(check_is_metered=is_active_network_metered)
54-
interface.register(get_os_user=os_user)
55-
5648
kolibri_bus = BaseKolibriProcessBus()
5749
# Setup zeroconf plugin
5850
zeroconf_plugin = ZeroConfPlugin(kolibri_bus, kolibri_bus.port)

src/taskworker.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import logging
22

33
import initialization # noqa: F401 keep this first, to ensure we're set up for other imports
4-
from android_utils import os_user
4+
from kolibri.main import enable_plugin
55
from kolibri.main import initialize
6-
from kolibri.plugins.app.utils import interface
76

7+
enable_plugin("android_app_plugin")
88
initialize(skip_update=True)
9-
interface.register(get_os_user=os_user)
109

1110
logger = logging.getLogger(__name__)
1211

0 commit comments

Comments
 (0)