diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index 519e6c8f..fdec67c9 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -33,7 +33,6 @@ use OCP\Share\Events\ShareCreatedEvent; use OCP\User\Events\UserChangedEvent; use OCP\User\Events\UserFirstTimeLoggedInEvent; -use OCP\Util; use Psr\Container\ContainerInterface; class Application extends App implements IBootstrap { @@ -63,7 +62,6 @@ public function boot(IBootContext $context): void { $this->setupGuestRestrictions($context->getAppContainer(), $context->getServerContainer()); $this->setupNotifications($context->getAppContainer()); $context->getAppContainer()->get(RestrictionManager::class)->lateSetupRestrictions(); - Util::addScript('guests', 'guests-init'); } private function setupGuestManagement(ContainerInterface $container, ContainerInterface $server): void { diff --git a/lib/Listener/BeforeTemplateRenderedListener.php b/lib/Listener/BeforeTemplateRenderedListener.php index 73d4ce42..440c565b 100644 --- a/lib/Listener/BeforeTemplateRenderedListener.php +++ b/lib/Listener/BeforeTemplateRenderedListener.php @@ -12,7 +12,6 @@ use OCA\Guests\Config; use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent; -use OCP\AppFramework\Services\IInitialState; use OCP\EventDispatcher\Event; use OCP\EventDispatcher\IEventListener; use OCP\Util; @@ -23,7 +22,6 @@ class BeforeTemplateRenderedListener implements IEventListener { public function __construct( private Config $config, - private IInitialState $initialState, ) { } @@ -32,10 +30,17 @@ public function handle(Event $event): void { return; } - $this->initialState->provideInitialState('canCreateGuests', $this->config->canCreateGuests()); + if (!$event->isLoggedIn()) { + return; + } + + if (!$this->config->canCreateGuests()) { + return; + } + Util::addScript('guests', 'guests-init'); Util::addScript('guests', 'guests-contactsmenu'); - if (!$event->isLoggedIn() || $event->getResponse()->getTemplateName() !== 'index') { + if ($event->getResponse()->getTemplateName() !== 'index') { return; } diff --git a/src/contactsmenu.ts b/src/contactsmenu.ts index 23d4f5bf..c65ff37f 100644 --- a/src/contactsmenu.ts +++ b/src/contactsmenu.ts @@ -5,15 +5,16 @@ import AccountPlusOutlineSvg from '@mdi/svg/svg/account-plus-outline.svg?raw' import { t } from '@nextcloud/l10n' +import { guestForm } from './init.ts' window.addEventListener('DOMContentLoaded', () => { - if (OC.ContactsMenu && OCA.Guests?.openGuestDialog) { + if (OC.ContactsMenu) { OC.ContactsMenu.addAction({ id: 'guests_addGuestAction', icon: AccountPlusOutlineSvg, label: t('guests', 'Add guest'), onClick: () => { - OCA.Guests.openGuestDialog('core') + guestForm.populate({ app: 'core' }) }, }) } diff --git a/src/init.ts b/src/init.ts index 37ab55f7..f9ca669a 100644 --- a/src/init.ts +++ b/src/init.ts @@ -8,8 +8,6 @@ import Vue from 'vue' import GuestForm from './views/GuestForm.vue' import Nextcloud from './mixins/Nextcloud.js' -import { loadState } from '@nextcloud/initial-state' - Vue.mixin(Nextcloud) if (!OCA.Guests) { @@ -25,8 +23,8 @@ guestRoot.setAttribute('id', 'guest-root') document.body.appendChild(guestRoot) guestForm.$mount('#guest-root') -if (loadState('guests', 'canCreateGuests', false)) { - OCA.Guests.openGuestDialog = (app: string, shareWith?: string) => guestForm.populate({ app }, shareWith) +OCA.Guests.openGuestDialog = (app: string, shareWith?: string) => { + guestForm.populate({ app }, shareWith) } export { guestForm } diff --git a/src/views/GuestForm.vue b/src/views/GuestForm.vue index cf6c06e2..a65afd18 100644 --- a/src/views/GuestForm.vue +++ b/src/views/GuestForm.vue @@ -21,7 +21,7 @@