Procházet zdrojové kódy

Merge branch 'master' of https://github.com/unaio/una

AntonLV před 7 roky
rodič
revize
5c7d5b9cad

+ 38 - 9
modules/boonex/mobile_apps/classes/BxMobileAppsModule.php

@@ -16,16 +16,29 @@ class BxMobileAppsModule extends BxDolModule
         parent::__construct($aModule);
     }
 
+    /**
+     * Get injection code required for mobile apps
+     * @return string
+     */
+    public function serviceInjectionHeadBegin()
+    {
+        $s = '';
+        if (false !== strpos($_SERVER['HTTP_USER_AGENT'], 'UNAMobileApp/Desktop')) {
+            $s .= "<script>if (typeof module === 'object') {window.module = module; module = undefined;}</script>";
+        }
+        return $s;
+    }
+    
     /**
      * Get injection code required for mobile apps
      * @return string with Styles and JS code
      */
-    public function serviceInjection()
+    public function serviceInjectionHead()
     {
         if (false === strpos($_SERVER['HTTP_USER_AGENT'], 'UNAMobileApp')) 
             return '';
 
-        $this->mobileRedirects();
+        $this->redirects();
 
         $oMenu = BxDolMenu::getObjectInstance('sys_account_notifications'); // sys_toolbar_member
         $a = $oMenu->getMenuItems();
@@ -53,10 +66,14 @@ class BxMobileAppsModule extends BxDolModule
 
         $this->_oTemplate->addJs('pulltorefresh.min.js');
 
+        if (false !== strpos($_SERVER['HTTP_USER_AGENT'], 'Desktop')) {
+            $s .= "<script>if (window.module) module = window.module;</script>";
+        }
+
         return $s;
     }
 
-    protected function mobileRedirects()
+    protected function redirects()
     {
         $bLoggedIn = isLogged() ? 1 : 0;
         $i = bx_get('i');
@@ -67,12 +84,24 @@ class BxMobileAppsModule extends BxDolModule
             header("Location: " . BX_DOL_URL_ROOT);
             exit;
         }
-        
-        // for logged in members some pages aren't available as well
-        $aI = array('forgot-password' => 1, 'create-account' => 1, 'login' => 1);
-        if ($bLoggedIn && isset($aI[$i])) {
-            header("Location: " . BX_DOL_URL_ROOT);
-            exit;
+
+        if ($bLoggedIn) {
+            if (false !== strpos($_SERVER['HTTP_USER_AGENT'], 'Desktop')) {
+                // desktop: for logged in members show messenger only
+                $aI = array('messenger' => 1);
+                if (!preg_match('/member.php$/', $_SERVER['PHP_SELF']) && !isset($aI[$i])) {
+                    header("Location: " . BX_DOL_URL_ROOT . 'page.php?i=messenger');
+                    exit;
+                }
+            }
+            else {        
+                // mobile: for logged in members some pages aren't available as well
+                $aI = array('forgot-password' => 1, 'create-account' => 1, 'login' => 1);
+                if (isset($aI[$i])) {
+                    header("Location: " . BX_DOL_URL_ROOT);
+                    exit;
+                }
+            }
         }
     }
 }

+ 2 - 1
modules/boonex/mobile_apps/install/sql/enable.sql

@@ -16,7 +16,8 @@ INSERT INTO `sys_options` (`name`, `value`, `category_id`, `caption`, `type`, `e
 -- Injections
 
 INSERT INTO `sys_injections`(`name`, `page_index`, `key`, `type`, `data`, `replace`, `active`) VALUES
-('bx_mobileapps', 0, 'injection_head', 'service', 'a:2:{s:6:"module";s:13:"bx_mobileapps";s:6:"method";s:9:"injection";}', 0, 1);
+('bx_mobileapps', 0, 'injection_head_begin', 'service', 'a:2:{s:6:"module";s:13:"bx_mobileapps";s:6:"method";s:20:"injection_head_begin";}', 0, 1),
+('bx_mobileapps', 0, 'injection_head', 'service', 'a:2:{s:6:"module";s:13:"bx_mobileapps";s:6:"method";s:14:"injection_head";}', 0, 1);
 
 -- Alerts
 

+ 35 - 0
modules/boonex/mobile_apps/template/mobile_apps_js.html

@@ -30,6 +30,41 @@
     else
         window.postMessage(sMsg, '*');
 
+
+    if (window && window.process && window.process.type) { // if run in electron
+        const { ipcRenderer, shell } = require('electron')
+        
+        // send all notification badges
+        ipcRenderer.send('message', __msg__);
+
+        // send messenger badge
+        setInterval(function () {
+            if ('undefined' !== typeof oLiveUpdates && oLiveUpdates._aSystemsActive && 'undefined' !== typeof oLiveUpdates._aSystemsActive.bx_messenger_new_messages) {
+                sMsg = {
+                    'bubbles': {
+                        'notifications-messenger': oLiveUpdates._aSystemsActive.bx_messenger_new_messages,
+                    },
+                };
+                ipcRenderer.send('message', sMsg);
+            }
+        }, 3000);
+        
+        if ($.cookie('memberID')) {
+            // force links to open in external browser in electron
+            $(document).ready(function () {
+                document.querySelector('body').addEventListener('click', event => {
+                    let link = event.target.href;
+                    console.log(link);
+                    if (event.target.tagName.toLowerCase() !== 'a') 
+                        return;
+                    event.preventDefault();
+                    shell.openExternal(link);
+                });
+            });
+        }
+    }
+
+    // pull to refresh
     $(document).ready(function () {
         PullToRefresh.init({
             instructionsPullToRefresh: '__txt_pull_to_refresh__',