aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/app')
-rw-r--r--client/src/app/app.component.ts4
-rw-r--r--client/src/app/core/plugins/hooks.service.ts7
-rw-r--r--client/src/app/core/plugins/plugin.service.ts10
-rw-r--r--client/src/app/search/search.component.ts4
-rw-r--r--client/src/app/videos/+video-watch/video-watch.component.ts6
5 files changed, 18 insertions, 13 deletions
diff --git a/client/src/app/app.component.ts b/client/src/app/app.component.ts
index bde97c68b..14fd27784 100644
--- a/client/src/app/app.component.ts
+++ b/client/src/app/app.component.ts
@@ -206,9 +206,7 @@ export class AppComponent implements OnInit {
206 private async loadPlugins () { 206 private async loadPlugins () {
207 this.pluginService.initializePlugins() 207 this.pluginService.initializePlugins()
208 208
209 await this.pluginService.loadPluginsByScope('common') 209 this.hooks.runAction('action:application.init', 'common')
210
211 this.hooks.runAction('action:application.init')
212 } 210 }
213 211
214 private initHotkeys () { 212 private initHotkeys () {
diff --git a/client/src/app/core/plugins/hooks.service.ts b/client/src/app/core/plugins/hooks.service.ts
index 80c57869c..257e27e6b 100644
--- a/client/src/app/core/plugins/hooks.service.ts
+++ b/client/src/app/core/plugins/hooks.service.ts
@@ -37,8 +37,9 @@ export class HooksService {
37 return this.pluginService.runHook(hookName, result, params) 37 return this.pluginService.runHook(hookName, result, params)
38 } 38 }
39 39
40 runAction<T, U extends ClientActionHookName> (hookName: U, params?: T) { 40 runAction<T, U extends ClientActionHookName> (hookName: U, scope: PluginClientScope, params?: T) {
41 this.pluginService.runHook(hookName, params) 41 this.pluginService.ensurePluginsAreLoaded(scope)
42 .catch((err: any) => console.error('Fatal hook error.', { err })) 42 .then(() => this.pluginService.runHook(hookName, params))
43 .catch((err: any) => console.error('Fatal hook error.', { err }))
43 } 44 }
44} 45}
diff --git a/client/src/app/core/plugins/plugin.service.ts b/client/src/app/core/plugins/plugin.service.ts
index 90ebe5669..5d180e5a0 100644
--- a/client/src/app/core/plugins/plugin.service.ts
+++ b/client/src/app/core/plugins/plugin.service.ts
@@ -36,6 +36,7 @@ export class PluginService implements ClientHook {
36 private scopes: { [ scopeName: string ]: PluginInfo[] } = {} 36 private scopes: { [ scopeName: string ]: PluginInfo[] } = {}
37 private loadedScripts: { [ script: string ]: boolean } = {} 37 private loadedScripts: { [ script: string ]: boolean } = {}
38 private loadedScopes: PluginClientScope[] = [] 38 private loadedScopes: PluginClientScope[] = []
39 private loadingScopes: { [id in PluginClientScope]?: boolean } = {}
39 40
40 private hooks: { [ name: string ]: HookStructValue[] } = {} 41 private hooks: { [ name: string ]: HookStructValue[] } = {}
41 42
@@ -63,6 +64,8 @@ export class PluginService implements ClientHook {
63 } 64 }
64 65
65 ensurePluginsAreLoaded (scope: PluginClientScope) { 66 ensurePluginsAreLoaded (scope: PluginClientScope) {
67 this.loadPluginsByScope(scope)
68
66 return this.pluginsLoaded[scope].asObservable() 69 return this.pluginsLoaded[scope].asObservable()
67 .pipe(first(), shareReplay()) 70 .pipe(first(), shareReplay())
68 .toPromise() 71 .toPromise()
@@ -104,6 +107,11 @@ export class PluginService implements ClientHook {
104 } 107 }
105 108
106 async loadPluginsByScope (scope: PluginClientScope, isReload = false) { 109 async loadPluginsByScope (scope: PluginClientScope, isReload = false) {
110 if (this.loadingScopes[scope]) return
111 if (!isReload && this.loadedScopes.includes(scope)) return
112
113 this.loadingScopes[scope] = true
114
107 try { 115 try {
108 await this.ensurePluginsAreBuilt() 116 await this.ensurePluginsAreBuilt()
109 117
@@ -111,6 +119,7 @@ export class PluginService implements ClientHook {
111 119
112 const toLoad = this.scopes[ scope ] 120 const toLoad = this.scopes[ scope ]
113 if (!Array.isArray(toLoad)) { 121 if (!Array.isArray(toLoad)) {
122 this.loadingScopes[scope] = false
114 this.pluginsLoaded[scope].next(true) 123 this.pluginsLoaded[scope].next(true)
115 124
116 return 125 return
@@ -130,6 +139,7 @@ export class PluginService implements ClientHook {
130 await Promise.all(promises) 139 await Promise.all(promises)
131 140
132 this.pluginsLoaded[scope].next(true) 141 this.pluginsLoaded[scope].next(true)
142 this.loadingScopes[scope] = false
133 } catch (err) { 143 } catch (err) {
134 console.error('Cannot load plugins by scope %s.', scope, err) 144 console.error('Cannot load plugins by scope %s.', scope, err)
135 } 145 }
diff --git a/client/src/app/search/search.component.ts b/client/src/app/search/search.component.ts
index 691e57619..5c4bb9379 100644
--- a/client/src/app/search/search.component.ts
+++ b/client/src/app/search/search.component.ts
@@ -53,8 +53,6 @@ export class SearchComponent implements OnInit, OnDestroy {
53 } 53 }
54 54
55 ngOnInit () { 55 ngOnInit () {
56 this.pluginService.loadPluginsByScope('search')
57
58 this.subActivatedRoute = this.route.queryParams.subscribe( 56 this.subActivatedRoute = this.route.queryParams.subscribe(
59 queryParams => { 57 queryParams => {
60 const querySearch = queryParams['search'] 58 const querySearch = queryParams['search']
@@ -80,7 +78,7 @@ export class SearchComponent implements OnInit, OnDestroy {
80 err => this.notifier.error(err.text) 78 err => this.notifier.error(err.text)
81 ) 79 )
82 80
83 this.hooks.runAction('action:search.init') 81 this.hooks.runAction('action:search.init', 'search')
84 } 82 }
85 83
86 ngOnDestroy () { 84 ngOnDestroy () {
diff --git a/client/src/app/videos/+video-watch/video-watch.component.ts b/client/src/app/videos/+video-watch/video-watch.component.ts
index 0d9b6d680..228c45a06 100644
--- a/client/src/app/videos/+video-watch/video-watch.component.ts
+++ b/client/src/app/videos/+video-watch/video-watch.component.ts
@@ -103,8 +103,6 @@ export class VideoWatchComponent implements OnInit, OnDestroy {
103 } 103 }
104 104
105 async ngOnInit () { 105 async ngOnInit () {
106 this.pluginService.loadPluginsByScope('video-watch')
107
108 this.configSub = this.serverService.configLoaded 106 this.configSub = this.serverService.configLoaded
109 .subscribe(() => { 107 .subscribe(() => {
110 if ( 108 if (
@@ -133,7 +131,7 @@ export class VideoWatchComponent implements OnInit, OnDestroy {
133 131
134 this.theaterEnabled = getStoredTheater() 132 this.theaterEnabled = getStoredTheater()
135 133
136 this.hooks.runAction('action:video-watch.init') 134 this.hooks.runAction('action:video-watch.init', 'video-watch')
137 } 135 }
138 136
139 ngOnDestroy () { 137 ngOnDestroy () {
@@ -497,7 +495,7 @@ export class VideoWatchComponent implements OnInit, OnDestroy {
497 this.setOpenGraphTags() 495 this.setOpenGraphTags()
498 this.checkUserRating() 496 this.checkUserRating()
499 497
500 this.hooks.runAction('action:video-watch.video.loaded') 498 this.hooks.runAction('action:video-watch.video.loaded', 'video-watch')
501 } 499 }
502 500
503 private setRating (nextRating: UserVideoRateType) { 501 private setRating (nextRating: UserVideoRateType) {