aboutsummaryrefslogtreecommitdiffstats
path: root/lib/public/Util.php
diff options
context:
space:
mode:
authorJulius Härtl <jus@bitgrid.net>2023-09-07 10:37:14 +0200
committerJulius Härtl <jus@bitgrid.net>2023-09-07 21:42:06 +0200
commitbd65f1ea283650d5ee52dc239aed8c4b00e82760 (patch)
tree4e765034c31a3407c2b8ddb66236fcf13e8f6efb /lib/public/Util.php
parenteb5510188ecc721bf43ad615b22d99bd98b46ee3 (diff)
downloadnextcloud-server-bd65f1ea283650d5ee52dc239aed8c4b00e82760.tar.gz
nextcloud-server-bd65f1ea283650d5ee52dc239aed8c4b00e82760.zip
feat: Add dedicated method to load init scripts
Signed-off-by: Julius Härtl <jus@bitgrid.net> Co-authored-by: John Molakvoæ <skjnldsv@protonmail.com> Update lib/public/Util.php Co-authored-by: Côme Chilliet <91878298+come-nc@users.noreply.github.com> Signed-off-by: Julius Härtl <jus@bitgrid.net>
Diffstat (limited to 'lib/public/Util.php')
-rw-r--r--lib/public/Util.php37
1 files changed, 26 insertions, 11 deletions
diff --git a/lib/public/Util.php b/lib/public/Util.php
index bff8038b3dd..781aa87d66b 100644
--- a/lib/public/Util.php
+++ b/lib/public/Util.php
@@ -49,6 +49,7 @@ namespace OCP;
use OC\AppScriptDependency;
use OC\AppScriptSort;
use bantu\IniGetWrapper\IniGetWrapper;
+use OCP\Share\IManager;
use Psr\Container\ContainerExceptionInterface;
/**
@@ -57,17 +58,11 @@ use Psr\Container\ContainerExceptionInterface;
* @since 4.0.0
*/
class Util {
- /** @var \OCP\Share\IManager */
- private static $shareManager;
+ private static ?IManager $shareManager = null;
- /** @var array */
- private static $scripts = [];
-
- /** @var array */
- private static $scriptDeps = [];
-
- /** @var array */
- private static $sortedScriptDeps = [];
+ private static array $scriptsInit = [];
+ private static array $scripts = [];
+ private static array $scriptDeps = [];
/**
* get the current installed version of Nextcloud
@@ -164,6 +159,25 @@ class Util {
}
/**
+ * Add a standalone init js file that is loaded for initialization
+ *
+ * Be careful loading scripts using this method as they are loaded early
+ * and block the initial page rendering. They should not have dependencies
+ * on any other scripts than core-common and core-main.
+ *
+ * @since 28.0.0
+ */
+ public static function addInitScript(string $application, string $file): void {
+ if (!empty($application)) {
+ $path = "$application/js/$file";
+ } else {
+ $path = "js/$file";
+ }
+
+ self::$scriptsInit[] = $path;
+ }
+
+ /**
* add a javascript file
*
* @param string $application
@@ -214,7 +228,8 @@ class Util {
$sortedScripts = $scriptSort->sort(self::$scripts, self::$scriptDeps);
// Flatten array and remove duplicates
- $sortedScripts = $sortedScripts ? array_merge(...array_values(($sortedScripts))) : [];
+ $sortedScripts = array_merge([self::$scriptsInit], $sortedScripts);
+ $sortedScripts = array_merge(...array_values($sortedScripts));
// Override core-common and core-main order
if (in_array('core/js/main', $sortedScripts)) {