Skip to content

Commit 494e4c1

Browse files
committed
feat(core): load AppMenu as a deferred core script
Register the core/appmenu entry in the user layout so the waffle launcher mounts like every other core script. Signed-off-by: Peter Ringelmann <peter.ringelmann@nextcloud.com>
1 parent 74279dc commit 494e4c1

3 files changed

Lines changed: 22 additions & 22 deletions

File tree

core/src/appmenu/main.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@
44
*
55
* Standalone entry for the waffle launcher (AppMenu). Mounts independently of
66
* core-main so the app grid lives in its own chunk.
7-
*
8-
* Uses Vue 2 syntax because the legacy webpack pipeline (build/frontend-legacy/)
9-
* still resolves `vue` to 2.7.16. The modern Vite pipeline ships Vue 3 but does
10-
* not currently include core; migrating core is out of scope for this work.
117
*/
128
import Vue from 'vue'
139
import AppMenu from './AppMenu.vue'
@@ -17,7 +13,7 @@ interface AppMenuInstance {
1713
}
1814

1915
declare global {
20-
// eslint-disable-next-line no-var
16+
2117
var OC: {
2218
setNavigationCounter?: (id: string, counter: number) => void
2319
}
@@ -38,6 +34,4 @@ function mount(): void {
3834
}
3935
}
4036

41-
// Loaded as a deferred core script, so the document is already parsed and the
42-
// nav container exists by the time this runs.
4337
mount()

core/src/tests/appmenu/main.spec.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@
44
*/
55
import { beforeEach, describe, expect, it, vi } from 'vitest'
66

7-
// Match every transitive dependency reachable from AppMenu.vue so its module
8-
// graph resolves cleanly inside JSDOM. We do NOT mock `vue`: the legacy Vitest
9-
// config aliases `vue` to Vue 2.7, which matches what the production webpack
10-
// bundle resolves to. Using the real Vue exercises the actual mount path.
117
vi.mock('@nextcloud/initial-state', () => ({
128
loadState: () => [],
139
}))

lib/private/TemplateLayout.php

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@
4242
use OCP\Template\ITemplateManager;
4343
use OCP\Util;
4444

45-
class TemplateLayout {
45+
class TemplateLayout
46+
{
4647
private string $versionHash = '';
4748
/** @var string[] */
4849
private array $cacheBusterCache = [];
@@ -59,10 +60,10 @@ public function __construct(
5960
private ITemplateManager $templateManager,
6061
private ServerVersion $serverVersion,
6162
private IRequest $request,
62-
) {
63-
}
63+
) {}
6464

65-
public function getPageTemplate(string $renderAs, string $appId): ITemplate {
65+
public function getPageTemplate(string $renderAs, string $appId): ITemplate
66+
{
6667
// Add fallback theming variables if not rendered as user
6768
if ($renderAs !== TemplateResponse::RENDER_AS_USER) {
6869
// TODO cache generated default theme if enabled for fallback if server is erroring ?
@@ -92,6 +93,8 @@ public function getPageTemplate(string $renderAs, string $appId): ITemplate {
9293
Util::addScript('core', 'unified-search', 'core');
9394
}
9495

96+
Util::addScript('core', 'appmenu', 'core');
97+
9598
// Set logo link target
9699
$logoUrl = $this->config->getSystemValueString('logo_url', '');
97100
$page->assign('logoUrl', $logoUrl);
@@ -267,7 +270,8 @@ public function getPageTemplate(string $renderAs, string $appId): ITemplate {
267270

268271
// Do not initialise scss appdata until we have a fully installed instance
269272
// Do not load scss for update, errors, installation or login page
270-
if ($this->config->getSystemValueBool('installed', false)
273+
if (
274+
$this->config->getSystemValueBool('installed', false)
271275
&& !Util::needUpgrade()
272276
&& $pathInfo !== ''
273277
&& !preg_match('/^\/login/', $pathInfo)
@@ -315,7 +319,8 @@ public function getPageTemplate(string $renderAs, string $appId): ITemplate {
315319
return $page;
316320
}
317321

318-
protected function getVersionHashSuffix(string $path = '', string $file = ''): string {
322+
protected function getVersionHashSuffix(string $path = '', string $file = ''): string
323+
{
319324
if ($this->config->getSystemValueBool('debug', false)) {
320325
// allows chrome workspace mapping in debug mode
321326
return '';
@@ -346,7 +351,8 @@ protected function getVersionHashSuffix(string $path = '', string $file = ''): s
346351
return '?v=' . $hash . $themingSuffix;
347352
}
348353

349-
private function getVersionHashByPath(string $path): string|false {
354+
private function getVersionHashByPath(string $path): string|false
355+
{
350356
if (array_key_exists($path, $this->cacheBusterCache) === false) {
351357
// Not yet cached, so lets find the cache buster string
352358
$appId = $this->getAppNamefromPath($path);
@@ -373,15 +379,17 @@ private function getVersionHashByPath(string $path): string|false {
373379
return $this->cacheBusterCache[$path];
374380
}
375381

376-
private function findStylesheetFiles(array $styles): array {
382+
private function findStylesheetFiles(array $styles): array
383+
{
377384
if ($this->cssLocator === null) {
378385
$this->cssLocator = Server::get(CSSResourceLocator::class);
379386
}
380387
$this->cssLocator->find($styles);
381388
return $this->cssLocator->getResources();
382389
}
383390

384-
public function getAppNamefromPath(string $path): string|false {
391+
public function getAppNamefromPath(string $path): string|false
392+
{
385393
if ($path !== '') {
386394
$pathParts = explode('/', $path);
387395
if ($pathParts[0] === 'css') {
@@ -395,7 +403,8 @@ public function getAppNamefromPath(string $path): string|false {
395403
return false;
396404
}
397405

398-
private function findJavascriptFiles(array $scripts): array {
406+
private function findJavascriptFiles(array $scripts): array
407+
{
399408
if ($this->jsLocator === null) {
400409
$this->jsLocator = Server::get(JSResourceLocator::class);
401410
}
@@ -409,7 +418,8 @@ private function findJavascriptFiles(array $scripts): array {
409418
* @return string Relative path
410419
* @throws \Exception If $filePath is not under \OC::$SERVERROOT
411420
*/
412-
public static function convertToRelativePath(string $filePath) {
421+
public static function convertToRelativePath(string $filePath)
422+
{
413423
$relativePath = explode(\OC::$SERVERROOT, $filePath);
414424
if (count($relativePath) !== 2) {
415425
throw new \Exception('$filePath is not under the \OC::$SERVERROOT');

0 commit comments

Comments
 (0)