Skip to content

Commit

Permalink
change naming of application hooks
Browse files Browse the repository at this point in the history
enable ready hook for classic applications
fix some typos
expose runtime error to console
  • Loading branch information
fschade committed Sep 3, 2021
1 parent 6366328 commit 5b91d37
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 35 deletions.
13 changes: 0 additions & 13 deletions packages/web-app-skeleton/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,6 @@ const appInfo = {
const injectExtensions = async api => {
// the promise is just there to showcase lazy loading of extensions
await new Promise(resolve => setTimeout(resolve, 2000))
console.log('#############################################################################')
console.log('# FROM THE APP (SKELETON)')
console.log('# a maybe long running task like wopi started')
console.log('#############################################################################')
await new Promise(resolve => setTimeout(resolve, 10000))
console.log('#############################################################################')
console.log('# FROM THE APP (SKELETON)')
console.log('# the server answered and we have all information to register a extension')
console.log('#############################################################################')

api.announceExtension({
extension: 'txt',
Expand All @@ -37,10 +28,6 @@ const injectExtensions = async api => {
'files-public-list'
]
})
console.log('#############################################################################')
console.log('# FROM THE APP (SKELETON)')
console.log('# new extension is now registered, ...')
console.log('#############################################################################')
}

export default {
Expand Down
2 changes: 1 addition & 1 deletion packages/web-runtime/src/container/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ const requestRouter = (router: VueRouter): VueRouter => {
}

/**
* exposed runtime api, this wraps all available api actions in a closure and provide application
* exposed runtime api, this wraps all available api actions in a closure and provides application
* specific data to the implementations.
*
* each application get it's own provisioned api!
Expand Down
27 changes: 17 additions & 10 deletions packages/web-runtime/src/container/application/classic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class ClassicApplication extends NextApplication {
this.applicationScript = applicationScript
}

prepare(): Promise<void> {
initialize(): Promise<void> {
const { routes, navItems, translations, quickActions, store } = this.applicationScript

routes && this.runtimeApi.announceRoutes(routes)
Expand All @@ -31,23 +31,30 @@ class ClassicApplication extends NextApplication {
return Promise.resolve(undefined)
}

register(): Promise<void> {
ready(): Promise<void> {
const { ready: readyHook } = this.applicationScript
this.attachPublicApi(readyHook)
return Promise.resolve(undefined)
}

mounted(instance: Vue): Promise<void> {
const { mounted: mountedHook } = this.applicationScript
isFunction(mountedHook) &&
mountedHook({
portal: {
open: (...args) => this.runtimeApi.openPortal.apply(instance, [instance, ...args])
},
this.attachPublicApi(mountedHook, instance)
return Promise.resolve(undefined)
}

private attachPublicApi(hook: unknown, instance?: Vue) {
isFunction(hook) &&
hook({
...(instance && {
portal: {
open: (...args) => this.runtimeApi.openPortal.apply(instance, [instance, ...args])
}
}),
store: this.runtimeApi.requestStore(),
router: this.runtimeApi.requestRouter(),
...this.runtimeApi
announceExtension: this.runtimeApi.announceExtension
})

return Promise.resolve(undefined)
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/web-runtime/src/container/application/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export const buildApplication = async ({
let application: NextApplication

try {
/** add valuable sniffer to detect nex applications, then implement next application factory */
/** add valuable sniffer to detect next applications, then implement next application factory */
if (!isObject(applicationScript.appInfo)) {
throw new RuntimeError('next applications not implemented yet, stay tuned')
} else {
Expand Down
4 changes: 2 additions & 2 deletions packages/web-runtime/src/container/application/next.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ export abstract class NextApplication {
this.runtimeApi = runtimeApi
}

abstract register(): Promise<void>
abstract initialize(): Promise<void>

abstract prepare(): Promise<void>
abstract ready(): Promise<void>

abstract mounted(instance: Vue): Promise<void>
}
6 changes: 3 additions & 3 deletions packages/web-runtime/src/container/bootstrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export const announceApplications = async ({
translations: unknown
supportedLanguages: { [key: string]: string }
}): Promise<void> => {
const { apps: applications = [], external_apps: externalApplications } = runtimeConfiguration
const { apps: applications = [], external_apps: externalApplications = [] } = runtimeConfiguration

const allApplications = [
...applications.map(application => `web-app-${application}`),
Expand All @@ -87,8 +87,8 @@ export const announceApplications = async ({
buildApplication({ applicationPath, store, supportedLanguages, router, translations })
)
)
await Promise.all(applicationImplementations.map(application => application.prepare()))
await Promise.all(applicationImplementations.map(application => application.register()))
await Promise.all(applicationImplementations.map(application => application.initialize()))
await Promise.all(applicationImplementations.map(application => application.ready()))
}

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/web-runtime/src/container/store.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { NextApplication } from './application'

/**
* main propose of this is to keep a reference to all announced applications.
* main purpose of this is to keep a reference to all announced applications.
* this is used for example in the mounted hook outside container module
*/
export const applicationStore = new Map<string, NextApplication>()
1 change: 1 addition & 0 deletions packages/web-runtime/src/container/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export interface ClassicApplicationScript {
navItems?: ApplicationNavigationItem[]
quickActions?: ApplicationQuickActions
translations?: unknown
ready?: () => void
mounted?: () => void
}

Expand Down
1 change: 0 additions & 1 deletion packages/web-runtime/src/defaults/vue.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ Vue.use(MediaSource)
Vue.use(WebPlugin)
Vue.use(VueResize)
Vue.use(VueMeta, {
// optional pluginOptions
refreshOnceOnNavigation: true
})
Vue.use(ChunkedUpload)
Expand Down
5 changes: 2 additions & 3 deletions packages/web-runtime/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,10 @@ export const renderSuccess = (): void => {
})
}

export const renderFailure = async (err: Error): Promise<void> => {
console.error(err)
export const renderFailure = (err: Error): Promise<void> => {
await announceTranslations({ vue: Vue, supportedLanguages, translations })
await announceTheme({ store, vue: Vue, designSystem })

console.error(err)
new Vue({
el: '#owncloud',
store,
Expand Down

0 comments on commit 5b91d37

Please sign in to comment.