|
49 | 49 | use OC\AppScriptDependency; |
50 | 50 | use OC\AppScriptSort; |
51 | 51 | use bantu\IniGetWrapper\IniGetWrapper; |
| 52 | +use OCP\Share\IManager; |
52 | 53 | use Psr\Container\ContainerExceptionInterface; |
53 | 54 |
|
54 | 55 | /** |
|
57 | 58 | * @since 4.0.0 |
58 | 59 | */ |
59 | 60 | class Util { |
60 | | - /** @var \OCP\Share\IManager */ |
61 | | - private static $shareManager; |
| 61 | + private static ?IManager $shareManager = null; |
62 | 62 |
|
63 | | - /** @var array */ |
64 | | - private static $scripts = []; |
65 | | - |
66 | | - /** @var array */ |
67 | | - private static $scriptDeps = []; |
68 | | - |
69 | | - /** @var array */ |
70 | | - private static $sortedScriptDeps = []; |
| 63 | + private static array $scriptsInit = []; |
| 64 | + private static array $scripts = []; |
| 65 | + private static array $scriptDeps = []; |
71 | 66 |
|
72 | 67 | /** |
73 | 68 | * get the current installed version of Nextcloud |
@@ -163,6 +158,25 @@ public static function addStyle($application, $file = null) { |
163 | 158 | \OC_Util::addStyle($application, $file); |
164 | 159 | } |
165 | 160 |
|
| 161 | + /** |
| 162 | + * Add a standalone init js file that is loaded for initialization |
| 163 | + * |
| 164 | + * Be careful loading scripts using this method as they are loaded early |
| 165 | + * and block the initial page rendering. They should not have dependencies |
| 166 | + * on any other scripts than core-common and core-main. |
| 167 | + * |
| 168 | + * @since 28.0.0 |
| 169 | + */ |
| 170 | + public static function addInitScript(string $application, string $file): void { |
| 171 | + if (!empty($application)) { |
| 172 | + $path = "$application/js/$file"; |
| 173 | + } else { |
| 174 | + $path = "js/$file"; |
| 175 | + } |
| 176 | + |
| 177 | + self::$scriptsInit[] = $path; |
| 178 | + } |
| 179 | + |
166 | 180 | /** |
167 | 181 | * add a javascript file |
168 | 182 | * |
@@ -214,7 +228,8 @@ public static function getScripts(): array { |
214 | 228 | $sortedScripts = $scriptSort->sort(self::$scripts, self::$scriptDeps); |
215 | 229 |
|
216 | 230 | // Flatten array and remove duplicates |
217 | | - $sortedScripts = $sortedScripts ? array_merge(...array_values(($sortedScripts))) : []; |
| 231 | + $sortedScripts = array_merge([self::$scriptsInit], $sortedScripts); |
| 232 | + $sortedScripts = array_merge(...array_values($sortedScripts)); |
218 | 233 |
|
219 | 234 | // Override core-common and core-main order |
220 | 235 | if (in_array('core/js/main', $sortedScripts)) { |
|
0 commit comments