LCOV - code coverage report
Current view: top level - xenolith/application - XLApplicationPlatform.cc (source / functions) Hit Total Coverage
Test: coverage.info Lines: 2 5 40.0 %
Date: 2024-05-12 00:16:13 Functions: 2 3 66.7 %

          Line data    Source code
       1             : /**
       2             :  Copyright (c) 2023 Stappler LLC <admin@stappler.dev>
       3             : 
       4             :  Permission is hereby granted, free of charge, to any person obtaining a copy
       5             :  of this software and associated documentation files (the "Software"), to deal
       6             :  in the Software without restriction, including without limitation the rights
       7             :  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
       8             :  copies of the Software, and to permit persons to whom the Software is
       9             :  furnished to do so, subject to the following conditions:
      10             : 
      11             :  The above copyright notice and this permission notice shall be included in
      12             :  all copies or substantial portions of the Software.
      13             : 
      14             :  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
      15             :  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
      16             :  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
      17             :  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
      18             :  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
      19             :  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
      20             :  THE SOFTWARE.
      21             :  **/
      22             : 
      23             : #include "XLApplication.h"
      24             : 
      25             : #if ANDROID
      26             : 
      27             : #include "android/XLPlatformAndroidActivity.h"
      28             : 
      29             : namespace STAPPLER_VERSIONIZED stappler::xenolith {
      30             : 
      31             : void Application::nativeInit() {
      32             :         auto activity = static_cast<platform::Activity *>(_info.nativeHandle);
      33             : 
      34             :         auto tok = activity->getMessageToken();
      35             :         if (!tok.empty()) {
      36             :                 handleMessageToken(move(tok));
      37             :         }
      38             :         activity->addTokenCallback(this, [this] (StringView str) {
      39             :                 performOnMainThread([this, str = str.str<Interface>()] () mutable {
      40             :                         handleMessageToken(move(str));
      41             :                 }, this);
      42             :         });
      43             : 
      44             :         activity->addRemoteNotificationCallback(this, [this] (const Value &val) {
      45             :                 performOnMainThread([this, val = val] () mutable {
      46             :                         handleRemoteNotification(move(val));
      47             :                 }, this);
      48             :         });
      49             : }
      50             : 
      51             : void Application::nativeDispose() {
      52             :         auto activity = static_cast<platform::Activity *>(_info.nativeHandle);
      53             : 
      54             :         activity->removeTokenCallback(this);
      55             :         activity->removeRemoteNotificationCallback(this);
      56             : }
      57             : 
      58             : void Application::openUrl(StringView url) const {
      59             :         auto activity = static_cast<platform::Activity *>(_info.nativeHandle);
      60             : 
      61             :         activity->openUrl(url);
      62             : }
      63             : 
      64             : }
      65             : 
      66             : #endif
      67             : 
      68             : 
      69             : #if LINUX
      70             : 
      71             : #include <stdlib.h>
      72             : 
      73             : namespace STAPPLER_VERSIONIZED stappler::xenolith {
      74             : 
      75          30 : void Application::nativeInit() { }
      76             : 
      77          30 : void Application::nativeDispose() { }
      78             : 
      79           0 : void Application::openUrl(StringView url) const {
      80           0 :         ::system(toString("xdg-open ", url).data());
      81           0 : }
      82             : 
      83             : }
      84             : 
      85             : #endif
      86             : 
      87             : 
      88             : #if WIN32
      89             : 
      90             : #include "SPPlatformUnistd.h"
      91             : #include <shellapi.h>
      92             : 
      93             : namespace STAPPLER_VERSIONIZED stappler::xenolith {
      94             : 
      95             : void Application::nativeInit() {
      96             :         platform::clock(core::ClockType::Monotonic);
      97             : }
      98             : 
      99             : void Application::nativeDispose() { }
     100             : 
     101             : void Application::openUrl(StringView url) const {
     102             :         ShellExecute(0, 0, L"http://www.google.com", 0, 0 , SW_SHOW );
     103             : }
     104             : 
     105             : }
     106             : 
     107             : #endif

Generated by: LCOV version 1.14