Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: run dependencies in sequenced order #464

Closed
wants to merge 4 commits into from
Closed
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

fix: add notification dialog to user after starting plugin

  • Loading branch information...
ryanio committed Sep 6, 2019
commit 792bed012d08fdb9fbbc0943b7392724c55f8200
@@ -243,6 +243,9 @@ class Plugin extends EventEmitter {
async response => {
const userPermission = response !== 1 // = index of 'cancel'
if (userPermission) {
dialog.showMessageBox({
message: `Starting ${this.displayName}, please wait...`
})
await this.start(flags, release)
} else {
console.log('User cancelled start dialog.')
@@ -162,41 +162,43 @@ class AppManager extends EventEmitter {

const { dependencies } = app
if (dependencies) {
var sequence = Promise.resolve()
// Execute dependneices one at a time with a sequence
// as inspired by https://stackoverflow.com/a/36672042
This conversation was marked as resolved by ryanio

This comment has been minimized.

This comment has been minimized.

Copy link
@ryanio

ryanio Sep 9, 2019

Author Collaborator

thanks, will swap.

let sequence = Promise.resolve()
dependencies.forEach(async dependency => {
console.log('Found dependency: ', dependency)
const plugin = global.PluginHost.getPluginByName(dependency.name)
if (!plugin) {
console.log('Could not find necessary plugin.')
} else if (plugin.isRunning) {
console.log(`Plugin ${plugin.name} already running.`)
} else {
// TODO: error handling of malformed settings
const settings = plugin.settings || []
let config = {}
sequence = sequence.then(async () => {
console.log('Found dependency: ', dependency)
const plugin = global.PluginHost.getPluginByName(dependency.name)
if (!plugin) {
console.log('Could not find necessary plugin.')
} else if (plugin.isRunning) {
console.log(`Plugin ${plugin.name} already running.`)
} else {
// TODO: error handling of malformed settings
const settings = plugin.settings || []
let config = {}

// 1. set default => check buildPluginDefaults in grid-ui
// TODO: this code should not be duplicated
settings.forEach(setting => {
if ('default' in setting) {
config[setting.id] = setting.default
}
})
// 1. set default => check buildPluginDefaults in grid-ui
// TODO: this code should not be duplicated
settings.forEach(setting => {
if ('default' in setting) {
config[setting.id] = setting.default
}
})

// 2. respect persisted user settings
const persistedConfig = (await UserConfig.getItem('settings')) || {}
const persistedPluginConfig = persistedConfig[plugin.name]
config = Object.assign({}, config)
// 2. respect persisted user settings
const persistedConfig = (await UserConfig.getItem('settings')) || {}
const persistedPluginConfig = persistedConfig[plugin.name]
config = Object.assign({}, config)

// 3. overwrite configs with required app settings
dependency.settings.forEach(setting => {
config[setting.id] = setting.value
})
// 3. overwrite configs with required app settings
dependency.settings.forEach(setting => {
config[setting.id] = setting.value
})

const flags = generateFlags(config, settings)
const release = undefined // TODO: allow apps to choose specific release?
console.log('Request start: ', app, flags, release)
sequence = sequence.then(async () => {
const flags = generateFlags(config, settings)
const release = undefined // TODO: allow apps to choose specific release?
console.log('Request start: ', app, flags, release)
try {
// TODO: show progress to user
await plugin.requestStart(app, flags, release)
@@ -205,9 +207,10 @@ class AppManager extends EventEmitter {
console.log('Error: ', error)
return // do NOT start in this case
}
})
}
}
})
})
await sequence
}

if (app.name === 'grid-ui') {
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.