Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build/frontend/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const modules = {
},
core: {
'ajax-cron': resolve(import.meta.dirname, 'core/src', 'ajax-cron.ts'),
appmenu: resolve(import.meta.dirname, 'core/src', 'appmenu.ts'),
install: resolve(import.meta.dirname, 'core/src', 'install.ts'),
'legacy-unified-search': resolve(import.meta.dirname, 'core/src', 'legacy-unified-search.ts'),
login: resolve(import.meta.dirname, 'core/src', 'login.ts'),
Expand Down
23 changes: 23 additions & 0 deletions core/src/appmenu.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*!
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*
* Standalone entry for the waffle launcher (AppMenu). Mounts independently of
* core-main so the app grid lives in its own chunk.
*/

import { createApp } from 'vue'
import AppMenu from './components/AppMenu/AppMenu.vue'
import { mountInPlace } from './utils/mountInPlace.ts'

const placeholder = document.getElementById('header-start__appmenu')
// No placeholder on layouts without the app menu, e.g. public pages.
if (placeholder) {
const appMenu = mountInPlace(createApp(AppMenu), placeholder) as InstanceType<typeof AppMenu>

Object.assign(window.OC, {
setNavigationCounter(id: string, counter: number) {
appMenu.setNavigationCounter(id, counter)
},
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
-->

<script setup lang="ts">
import type { INavigationEntry } from '../types/navigation.d.ts'
import type { INavigationEntry } from '../../types/navigation.d.ts'

import { mdiCog, mdiDotsGrid } from '@mdi/js'
import { getCurrentUser } from '@nextcloud/auth'
Expand All @@ -18,7 +18,7 @@ import NcIconSvgWrapper from '@nextcloud/vue/components/NcIconSvgWrapper'
import NcPopover from '@nextcloud/vue/components/NcPopover'
import AppMenuActions from './AppMenuActions.vue'
import AppMenuItem from './AppMenuItem.vue'
import { logger } from '../utils/logger.ts'
import { logger } from '../../utils/logger.ts'

// Settings IDs that represent actions, not navigable pages.
const SETTINGS_ACTION_IDS = new Set(['logout'])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
-->

<script setup lang="ts">
import type { INavigationEntry } from '../types/navigation.d.ts'
import type { INavigationEntry } from '../../types/navigation.d.ts'

import { emit as emitOnEventBus } from '@nextcloud/event-bus'
import { computed } from 'vue'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<script setup lang="ts">
import type { ComponentPublicInstance } from 'vue'
import type { INavigationEntry } from '../types/navigation.d.ts'
import type { INavigationEntry } from '../../types/navigation.d.ts'

import { mdiDotsHorizontal } from '@mdi/js'
import { t } from '@nextcloud/l10n'
Expand Down
Comment thread
pringelmann marked this conversation as resolved.
Resolved
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
-->

<script setup lang="ts">
import type { INavigationEntry } from '../types/navigation.d.ts'
import type { INavigationEntry } from '../../types/navigation.d.ts'

import { n } from '@nextcloud/l10n'
import { computed } from 'vue'
import AppIcon from './AppIcon.vue'
import AppIcon from '../AppIcon.vue'

const props = withDefaults(defineProps<{
app: INavigationEntry
Expand Down
27 changes: 0 additions & 27 deletions core/src/components/MainMenu.ts

This file was deleted.

2 changes: 0 additions & 2 deletions core/src/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import { getLocale } from '@nextcloud/l10n'
import moment from 'moment'
import { setUp as setUpContactsMenu } from './components/ContactsMenu.ts'
import { setUp as setUpMainMenu } from './components/MainMenu.ts'
import { setUp as setUpUserMenu } from './components/UserMenu.ts'
import { initSessionHeartBeat } from './session-heartbeat.ts'
import { initFallbackClipboardAPI } from './utils/ClipboardFallback.ts'
Expand Down Expand Up @@ -46,7 +45,6 @@ export function initCore() {

initSessionHeartBeat()

setUpMainMenu()
setUpUserMenu()
setUpContactsMenu()
}
84 changes: 84 additions & 0 deletions core/src/tests/appmenu.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*!
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

import { beforeEach, describe, expect, it, vi } from 'vitest'

vi.mock('@nextcloud/initial-state', () => ({
loadState: (_app: string, key: string, fallback: unknown) => key === 'apps'
? [{ id: 'files', app: 'files', active: false, order: 0, href: '/apps/files', icon: '/apps/files/img/app.svg', type: 'link', name: 'Files', unread: 0 }]
: fallback,
}))
vi.mock('@nextcloud/auth', () => ({
getCurrentUser: () => ({ isAdmin: false }),
}))
vi.mock('@nextcloud/event-bus', () => ({
subscribe: () => undefined,
unsubscribe: () => undefined,
}))
vi.mock('@nextcloud/router', () => ({
generateUrl: (path: string) => path,
imagePath: (app: string, file: string) => `/${app}/img/${file}`,
}))

const logger = vi.hoisted(() => ({
warn: vi.fn(),
}))
vi.mock('../utils/logger.ts', () => ({ logger }))

type SetNavigationCounter = (id: string, counter: number) => void

/**
* Get the counter setter the app menu adds to the OC global, if any.
*/
function getSetNavigationCounter(): SetNavigationCounter | undefined {
return (window.OC as { setNavigationCounter?: SetNavigationCounter }).setNavigationCounter
}

/**
* Add the placeholder the app menu is mounted in place of.
*/
function addPlaceholder(): void {
const placeholder = document.createElement('nav')
placeholder.id = 'header-start__appmenu'
document.body.appendChild(placeholder)
}

describe('core: appmenu', () => {
beforeEach(() => {
document.body.innerHTML = ''
window.OC = {} as typeof window.OC
logger.warn.mockClear()
vi.resetModules()
})

it('mounts the app menu in place of the placeholder', async () => {
addPlaceholder()

await import('../appmenu.ts')

expect(document.querySelector('.app-menu')).not.toBeNull()
expect(document.getElementById('header-start__appmenu')).toBeNull()
})

it('does nothing without the placeholder', async () => {
await import('../appmenu.ts')

expect(document.body.children.length).toBe(0)
expect(getSetNavigationCounter()).toBeUndefined()
})

it('forwards OC.setNavigationCounter to the app menu', async () => {
addPlaceholder()

await import('../appmenu.ts')

const setNavigationCounter = getSetNavigationCounter()!
setNavigationCounter('files', 3)
expect(logger.warn).not.toHaveBeenCalled()

setNavigationCounter('unknown', 3)
expect(logger.warn).toHaveBeenCalledOnce()
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import { mdiPlus } from '@mdi/js'
import { mount } from '@vue/test-utils'
import { describe, expect, it } from 'vitest'
import AppActionIcon from '../../components/AppActionIcon.vue'
import AppActionIcon from '../../../components/AppMenu/AppActionIcon.vue'

describe('core: AppActionIcon', () => {
it('paints the icon from its URL', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

import type { INavigationEntry } from '../../types/navigation.d.ts'
import type { INavigationEntry } from '../../../types/navigation.d.ts'

import { mount } from '@vue/test-utils'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
Expand Down Expand Up @@ -118,7 +118,7 @@ function eightApps(activeIndex: number = -1): INavigationEntry[] {
// Import AFTER mocks are registered. Static `import` would hoist above
// vi.mock() and break the wiring; dynamic import in beforeAll/await is the
// idiomatic Vitest workaround when you need to control mock state per test.
import type AppMenuModule from '../../components/AppMenu.vue'
import type AppMenuModule from '../../../components/AppMenu/AppMenu.vue'
let AppMenu: typeof AppMenuModule

beforeEach(async () => {
Expand All @@ -128,7 +128,7 @@ beforeEach(async () => {
}
initialState.loadState.mockImplementation(stateFor({ apps: fakeApps() }))
auth.getCurrentUser.mockReturnValue({ isAdmin: false })
AppMenu = (await import('../../components/AppMenu.vue')).default
AppMenu = (await import('../../../components/AppMenu/AppMenu.vue')).default
})

afterEach(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

import type { INavigationEntry } from '../../types/navigation.d.ts'
import type { INavigationEntry } from '../../../types/navigation.d.ts'

import { mount } from '@vue/test-utils'
import { describe, expect, it, vi } from 'vitest'
Expand All @@ -17,7 +17,7 @@ vi.mock('@nextcloud/l10n', () => ({
},
}))

import AppMenuItem from '../../components/AppMenuItem.vue'
import AppMenuItem from '../../../components/AppMenu/AppMenuItem.vue'

function makeApp(overrides: Partial<INavigationEntry> = {}): INavigationEntry {
return {
Expand Down
3 changes: 3 additions & 0 deletions lib/private/TemplateLayout.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ public function getPageTemplate(string $renderAs, string $appId): ITemplate {
Util::addStyle('core', 'unified-search');
}

Util::addScript('core', 'appmenu', 'core');
Util::addStyle('core', 'appmenu');

// Set logo link target
$logoUrl = $this->config->getSystemValueString('logo_url', '');
$page->assign('logoUrl', $logoUrl);
Expand Down
Loading