diff cagou/core/cagou_main.py @ 342:89799148f894

core: use classes and factory to handle platform specific behaviours in a generic way
author Goffi <goffi@goffi.org>
date Sat, 04 Jan 2020 16:24:57 +0100
parents d36040493434
children 7b9a0e57df53
line wrap: on
line diff
--- a/cagou/core/cagou_main.py	Fri Jan 03 15:48:59 2020 +0100
+++ b/cagou/core/cagou_main.py	Sat Jan 04 16:24:57 2020 +0100
@@ -62,8 +62,6 @@
 from kivy.core.window import Window
 from kivy.animation import Animation
 from kivy.metrics import dp
-from kivy import utils as kivy_utils
-from kivy.config import Config as KivyConfig
 from .cagou_widget import CagouWidget
 from .share_widget import ShareWidget
 from . import widgets_handler
@@ -89,16 +87,9 @@
 
 ## platform specific settings ##
 
-if kivy_utils.platform == "android":
-    import socket
-    from .platform_ import android
-    android.init_platform()
-else:
-    # we don't want multi-touch emulation with mouse
-
-    # this option doesn't make sense on Android and cause troubles, so we only activate
-    # it for other platforms (cf. https://github.com/kivy/kivy/issues/6229)
-    KivyConfig.set('input', 'mouse', 'mouse,disable_multitouch')
+from . import platform_
+local_platform = platform_.create()
+local_platform.init_platform()
 
 
 ## General Configuration ##
@@ -318,9 +309,7 @@
     def build(self):
         Window.bind(on_keyboard=self.key_input)
         wid = CagouRootWidget(Label(text="Loading please wait"))
-        if sys.platform == 'android':
-            # we don't want menu on Android
-            wid.root_menus.height = 0
+        local_platform.on_app_build(wid)
         return wid
 
     def showWidget(self):
@@ -340,27 +329,16 @@
 
     def initFrontendState(self):
         """Init state to handle paused/stopped/running on mobile OSes"""
-        if sys.platform == "android":
-            # XXX: we use a separated socket instead of bridge because if we
-            #      try to call a bridge method in on_pause method, the call data
-            #      is not written before the actual pause
-            s = self._frontend_status_socket = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
-            s.connect(os.path.join(android.SOCKET_DIR, android.SOCKET_FILE))
-            s.sendall(android.STATE_RUNNING)
+        local_platform.on_initFrontendState()
 
     def on_pause(self):
-        self.host.sync = False
-        self._frontend_status_socket.sendall(android.STATE_PAUSED)
-        return True
+        return local_platform.on_pause()
 
     def on_resume(self):
-        self._frontend_status_socket.sendall(android.STATE_RUNNING)
-        self.host.sync = True
+        return local_platform.on_resume()
 
     def on_stop(self):
-        if sys.platform == "android":
-            self._frontend_status_socket.sendall(android.STATE_STOPPED)
-            self._frontend_status_socket.close()
+        return local_platform.on_stop()
 
     def key_input(self, window, key, scancode, codepoint, modifier):
         if key == 27:
@@ -449,8 +427,7 @@
             patches.apply()
             log.warning("SSL certificate validation is disabled, this is unsecure!")
 
-        if sys.platform == 'android':
-            android.host_init(self)
+        local_platform.on_host_init(self)
 
     @property
     def visible_widgets(self):