Skip to content

Commit

Permalink
For Multi-Instance apps, add a new item in the account menu to displa…
Browse files Browse the repository at this point in the history
…y the Opener app page, allowing to switch to the other HumHub instance
  • Loading branch information
marc-farre committed Dec 12, 2024
1 parent 45202c6 commit 260e151
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 6 deletions.
23 changes: 22 additions & 1 deletion Events.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
use humhub\modules\fcmPush\services\DriverService;
use humhub\modules\fcmPush\widgets\PushNotificationInfoWidget;
use humhub\modules\notification\targets\MobileTargetProvider;
use humhub\modules\ui\menu\MenuLink;
use humhub\modules\user\widgets\AccountTopMenu;
use humhub\modules\user\widgets\AuthChoice;
use humhub\modules\web\pwa\controllers\ManifestController;
use humhub\modules\web\pwa\controllers\ServiceWorkerController;
Expand Down Expand Up @@ -90,7 +92,7 @@ public static function onLayoutAddonInit($event)
{
if (Yii::$app->session->has(self::SESSION_VAR_LOGOUT)) {
MobileAppHelper::unregisterNotificationScript(); // Before Logout
MobileAppHelper::registerLogoutScript();
MobileAppHelper::registerShowOpenerScript();
Yii::$app->session->remove(self::SESSION_VAR_LOGOUT);
}

Expand Down Expand Up @@ -137,4 +139,23 @@ public static function onAuthChoiceBeforeRun(Event $event)
$sender->setClients([]);
}
}

public static function onAccountTopMenuInit(Event $event)
{
if (!MobileAppHelper::isMultiInstanceApp()) {
return;
}

/** @var AccountTopMenu $menu */
$menu = $event->sender;

$menu->addEntry(new MenuLink([
'label' => Yii::t('FcmPushModule.base', 'Switch network'),
'url' => ['/fcm-push/mobile-app/instance-opener'],
'icon' => 'arrows-h',
'sortOrder' => 699, // Just before "Logout"
'isActive' => true,
'isVisible' => true,
]));
}
}
11 changes: 7 additions & 4 deletions config.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@

/** @noinspection MissedFieldInspection */

use humhub\modules\fcmPush\Events;
use humhub\components\Controller;
//use humhub\modules\notification\widgets\NotificationInfoWidget;
use humhub\modules\fcmPush\Events;
use humhub\modules\user\components\User;
use humhub\modules\user\widgets\AccountTopMenu;
use humhub\modules\user\widgets\AuthChoice;
use humhub\widgets\LayoutAddons;
use yii\base\Application;
use humhub\modules\user\components\User;

//use humhub\modules\notification\widgets\NotificationInfoWidget;

return [
'id' => 'fcm-push',
Expand All @@ -23,7 +25,8 @@
[User::class, User::EVENT_AFTER_LOGOUT, [Events::class, 'onAfterLogout']],
[User::class, User::EVENT_AFTER_LOGIN, [Events::class, 'onAfterLogin']],
[AuthChoice::class, AuthChoice::EVENT_BEFORE_RUN, [Events::class, 'onAuthChoiceBeforeRun']],
//[NotificationInfoWidget::class, \humhub\widgets\BaseStack::EVENT_RUN, [Events::class, 'onNotificationInfoWidget']]
//[NotificationInfoWidget::class, \humhub\widgets\BaseStack::EVENT_RUN, [Events::class, 'onNotificationInfoWidget']],
[AccountTopMenu::class, AccountTopMenu::EVENT_INIT, [Events::class, 'onAccountTopMenuInit']],
],
'consoleControllerMap' => [
'firebase' => 'humhub\modules\fcmPush\commands\SendController',
Expand Down
10 changes: 10 additions & 0 deletions controllers/MobileAppController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use humhub\modules\admin\components\Controller;
use humhub\modules\admin\notifications\NewVersionAvailable;
use humhub\modules\fcmPush\helpers\MobileAppHelper;
use humhub\modules\fcmPush\models\FcmUser;
use humhub\modules\user\models\User;
use Yii;
Expand Down Expand Up @@ -43,4 +44,13 @@ public function actionIndex()
return $this->render('index');
}

public function actionInstanceOpener()
{
// Send to the mobile app to display the instance opener
MobileAppHelper::registerShowOpenerScript();

// Stay in the same page, for when we come back from the mobile app to this instance
return $this->redirect(Yii::$app->request->referrer);
}

}
1 change: 1 addition & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Changelog
2.1.1 (unreleased)
------------------------
- Fix #58: iOS mobile app detection for iPad devices
- Enh: For Multi-Instance apps, add a new item in the account menu to display the Opener app page, allowing to switch to the other HumHub instance

2.1.0 (October 21, 2024)
------------------------
Expand Down
9 changes: 8 additions & 1 deletion helpers/MobileAppHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public static function registerLoginScript()
self::sendFlutterMessage($message);
}

public static function registerLogoutScript()
public static function registerShowOpenerScript()
{
if (!static::isAppRequest()) {
return;
Expand Down Expand Up @@ -90,4 +90,11 @@ public static function isIosApp(): bool
static::isAppRequest()
&& Yii::$app->request->headers->get('x-humhub-app-is-ios');
}

public static function isMultiInstanceApp(): bool
{
return
static::isAppRequest()
&& Yii::$app->request->headers->get('x-humhub-app-is-multi-instance');
}
}

0 comments on commit 260e151

Please sign in to comment.