Unverified Commit 3d2594fa authored by yann300's avatar yann300 Committed by GitHub

Merge pull request #2212 from ethereum/plugin-permissions

Improve Plugin permissions + Use emit function from plugin
parents 008399c7 63818a29
...@@ -73,16 +73,22 @@ export class SidePanel extends AbstractPanel { ...@@ -73,16 +73,22 @@ export class SidePanel extends AbstractPanel {
verticalIcons.events.on('toggleContent', (name) => { verticalIcons.events.on('toggleContent', (name) => {
if (!this.contents[name]) return if (!this.contents[name]) return
if (this.active === name) { if (this.active === name) {
// TODO: Only keep `this.emit` (issue#2210)
this.emit('toggle', name)
this.events.emit('toggle', name) this.events.emit('toggle', name)
return return
} }
this.showContent(name) this.showContent(name)
// TODO: Only keep `this.emit` (issue#2210)
this.emit('showing', name)
this.events.emit('showing', name) this.events.emit('showing', name)
}) })
// Force opening // Force opening
verticalIcons.events.on('showContent', (name) => { verticalIcons.events.on('showContent', (name) => {
if (!this.contents[name]) return if (!this.contents[name]) return
this.showContent(name) this.showContent(name)
// TODO: Only keep `this.emit` (issue#2210)
this.emit('showing', name)
this.events.emit('showing', name) this.events.emit('showing', name)
}) })
} }
......
...@@ -187,6 +187,8 @@ export class VerticalIcons extends Plugin { ...@@ -187,6 +187,8 @@ export class VerticalIcons extends Plugin {
*/ */
select (name) { select (name) {
this.updateActivations(name) this.updateActivations(name)
// TODO: Only keep `this.emit` (issue#2210)
this.emit('showContent', name)
this.events.emit('showContent', name) this.events.emit('showContent', name)
} }
...@@ -196,6 +198,8 @@ export class VerticalIcons extends Plugin { ...@@ -196,6 +198,8 @@ export class VerticalIcons extends Plugin {
*/ */
toggle (name) { toggle (name) {
this.updateActivations(name) this.updateActivations(name)
// TODO: Only keep `this.emit` (issue#2210)
this.emit('toggleContent', name)
this.events.emit('toggleContent', name) this.events.emit('toggleContent', name)
} }
......
...@@ -85,6 +85,8 @@ class FileManager extends Plugin { ...@@ -85,6 +85,8 @@ class FileManager extends Plugin {
this.switchFile(newFocus) this.switchFile(newFocus)
} }
} }
// TODO: Only keep `this.emit` (issue#2210)
this.emit('fileRenamed', oldName, newName)
this.events.emit('fileRenamed', oldName, newName) this.events.emit('fileRenamed', oldName, newName)
} }
...@@ -104,8 +106,12 @@ class FileManager extends Plugin { ...@@ -104,8 +106,12 @@ class FileManager extends Plugin {
delete this.openedFiles[name] delete this.openedFiles[name]
if (!Object.keys(this.openedFiles).length) { if (!Object.keys(this.openedFiles).length) {
this._deps.config.set('currentFile', '') this._deps.config.set('currentFile', '')
// TODO: Only keep `this.emit` (issue#2210)
this.emit('noFileSelected')
this.events.emit('noFileSelected') this.events.emit('noFileSelected')
} }
// TODO: Only keep `this.emit` (issue#2210)
this.emit('fileClosed', name)
this.events.emit('fileClosed', name) this.events.emit('fileClosed', name)
} }
...@@ -234,6 +240,8 @@ class FileManager extends Plugin { ...@@ -234,6 +240,8 @@ class FileManager extends Plugin {
} }
this.editor.discard(path) this.editor.discard(path)
delete this.openedFiles[path] delete this.openedFiles[path]
// TODO: Only keep `this.emit` (issue#2210)
this.emit('fileRemoved', path)
this.events.emit('fileRemoved', path) this.events.emit('fileRemoved', path)
this.switchFile() this.switchFile()
} }
...@@ -241,6 +249,8 @@ class FileManager extends Plugin { ...@@ -241,6 +249,8 @@ class FileManager extends Plugin {
unselectCurrentFile () { unselectCurrentFile () {
this.saveCurrentFile() this.saveCurrentFile()
this._deps.config.set('currentFile', '') this._deps.config.set('currentFile', '')
// TODO: Only keep `this.emit` (issue#2210)
this.emit('noFileSelected')
this.events.emit('noFileSelected') this.events.emit('noFileSelected')
} }
...@@ -258,6 +268,8 @@ class FileManager extends Plugin { ...@@ -258,6 +268,8 @@ class FileManager extends Plugin {
} else { } else {
this.editor.open(file, content) this.editor.open(file, content)
} }
// TODO: Only keep `this.emit` (issue#2210)
this.emit('currentFileChanged', file)
this.events.emit('currentFileChanged', file) this.events.emit('currentFileChanged', file)
} }
}) })
...@@ -271,6 +283,8 @@ class FileManager extends Plugin { ...@@ -271,6 +283,8 @@ class FileManager extends Plugin {
if (fileList.length) { if (fileList.length) {
_switchFile(browserProvider.type + '/' + fileList[0]) _switchFile(browserProvider.type + '/' + fileList[0])
} else { } else {
// TODO: Only keep `this.emit` (issue#2210)
this.emit('noFileSelected')
this.events.emit('noFileSelected') this.events.emit('noFileSelected')
} }
}) })
......
...@@ -60,6 +60,8 @@ export class ThemeModule extends Plugin { ...@@ -60,6 +60,8 @@ export class ThemeModule extends Plugin {
document.getElementById('theme-link').setAttribute('href', nextTheme.url) document.getElementById('theme-link').setAttribute('href', nextTheme.url)
document.documentElement.style.setProperty('--theme', nextTheme.quality) document.documentElement.style.setProperty('--theme', nextTheme.quality)
if (themeName) this.active = themeName if (themeName) this.active = themeName
// TODO: Only keep `this.emit` (issue#2210)
this.emit('themeChanged', nextTheme)
this.events.emit('themeChanged', nextTheme) this.events.emit('themeChanged', nextTheme)
} }
} }
...@@ -78,7 +78,7 @@ export class PermissionHandler { ...@@ -78,7 +78,7 @@ export class PermissionHandler {
} }
this.persistPermissions() this.persistPermissions()
} }
resolve() resolve(true)
} }
}, },
{ {
...@@ -105,19 +105,23 @@ export class PermissionHandler { ...@@ -105,19 +105,23 @@ export class PermissionHandler {
* @returns {Promise<boolean>} * @returns {Promise<boolean>}
*/ */
async askPermission (from, to) { async askPermission (from, to) {
this.permissions = this._getFromLocal() try {
if (!this.permissions[to.name]) this.permissions[to.name] = {} this.permissions = this._getFromLocal()
if (!this.permissions[to.name][from.name]) return this.openPermission(from, to) if (!this.permissions[to.name]) this.permissions[to.name] = {}
if (!this.permissions[to.name][from.name]) return this.openPermission(from, to)
const { allow, hash } = this.permissions[to.name][from.name] const { allow, hash } = this.permissions[to.name][from.name]
if (!allow) { if (!allow) {
const warning = notAllowWarning(from, to) const warning = notAllowWarning(from, to)
addTooltip(warning) addTooltip(warning)
throw new Error(warning) return false
}
return hash === from.hash
? true // Allow
: this.openPermission(from, to) // New version of a plugin
} catch (err) {
throw new Error(err)
} }
return hash === from.hash
? true // Allow
: this.openPermission(from, to) // New version of a plugin
} }
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment