From 4abd9f35347371f818781267573b01897564cafe Mon Sep 17 00:00:00 2001 From: Grandschtroumpf Date: Mon, 22 Jul 2019 15:39:03 +0200 Subject: [PATCH 1/5] Permission return boolean value --- src/app/ui/persmission-handler.js | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/src/app/ui/persmission-handler.js b/src/app/ui/persmission-handler.js index 302df47783..dea16694c4 100644 --- a/src/app/ui/persmission-handler.js +++ b/src/app/ui/persmission-handler.js @@ -78,7 +78,7 @@ export class PermissionHandler { } this.persistPermissions() } - resolve() + resolve(true) } }, { @@ -105,19 +105,23 @@ export class PermissionHandler { * @returns {Promise} */ async askPermission (from, to) { - this.permissions = this._getFromLocal() - 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] - if (!allow) { - const warning = notAllowWarning(from, to) - addTooltip(warning) - throw new Error(warning) + try { + this.permissions = this._getFromLocal() + 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] + if (!allow) { + const warning = notAllowWarning(from, to) + addTooltip(warning) + throw new Error(warning) + } + return hash === from.hash + ? true // Allow + : this.openPermission(from, to) // New version of a plugin + } catch (err) { + return false } - return hash === from.hash - ? true // Allow - : this.openPermission(from, to) // New version of a plugin } /** From 5f05fb2a0c5e93b231543f55de57bd9a120b8ee5 Mon Sep 17 00:00:00 2001 From: Grandschtroumpf Date: Mon, 22 Jul 2019 15:39:27 +0200 Subject: [PATCH 2/5] Use emit function from plugin --- src/app/components/side-panel.js | 6 ++++++ src/app/components/vertical-icons.js | 4 ++++ src/app/files/fileManager.js | 14 ++++++++++++++ src/app/tabs/theme-module.js | 2 ++ src/framingService.js | 1 + 5 files changed, 27 insertions(+) diff --git a/src/app/components/side-panel.js b/src/app/components/side-panel.js index 730a56cc9c..e478f35a6c 100644 --- a/src/app/components/side-panel.js +++ b/src/app/components/side-panel.js @@ -73,16 +73,22 @@ export class SidePanel extends AbstractPanel { verticalIcons.events.on('toggleContent', (name) => { if (!this.contents[name]) return if (this.active === name) { + // TODO: Only keep `this.emit` (issue#2210) + this.emit('toggle', name) this.events.emit('toggle', name) return } this.showContent(name) + // TODO: Only keep `this.emit` (issue#2210) + this.emit('showing', name) this.events.emit('showing', name) }) // Force opening verticalIcons.events.on('showContent', (name) => { if (!this.contents[name]) return this.showContent(name) + // TODO: Only keep `this.emit` (issue#2210) + this.emit('showing', name) this.events.emit('showing', name) }) } diff --git a/src/app/components/vertical-icons.js b/src/app/components/vertical-icons.js index 3e73f976f1..aa9ab4aedc 100644 --- a/src/app/components/vertical-icons.js +++ b/src/app/components/vertical-icons.js @@ -187,6 +187,8 @@ export class VerticalIcons extends Plugin { */ select (name) { this.updateActivations(name) + // TODO: Only keep `this.emit` (issue#2210) + this.emit('showContent', name) this.events.emit('showContent', name) } @@ -196,6 +198,8 @@ export class VerticalIcons extends Plugin { */ toggle (name) { this.updateActivations(name) + // TODO: Only keep `this.emit` (issue#2210) + this.emit('toggleContent', name) this.events.emit('toggleContent', name) } diff --git a/src/app/files/fileManager.js b/src/app/files/fileManager.js index 61e2e27372..bdfa2bb99d 100644 --- a/src/app/files/fileManager.js +++ b/src/app/files/fileManager.js @@ -85,6 +85,8 @@ class FileManager extends Plugin { this.switchFile(newFocus) } } + // TODO: Only keep `this.emit` (issue#2210) + this.emit('fileRenamed', oldName, newName) this.events.emit('fileRenamed', oldName, newName) } @@ -104,8 +106,12 @@ class FileManager extends Plugin { delete this.openedFiles[name] if (!Object.keys(this.openedFiles).length) { this._deps.config.set('currentFile', '') + // TODO: Only keep `this.emit` (issue#2210) + this.emit('noFileSelected') this.events.emit('noFileSelected') } + // TODO: Only keep `this.emit` (issue#2210) + this.emit('fileClosed', name) this.events.emit('fileClosed', name) } @@ -234,6 +240,8 @@ class FileManager extends Plugin { } this.editor.discard(path) delete this.openedFiles[path] + // TODO: Only keep `this.emit` (issue#2210) + this.emit('fileRemoved', path) this.events.emit('fileRemoved', path) this.switchFile() } @@ -241,6 +249,8 @@ class FileManager extends Plugin { unselectCurrentFile () { this.saveCurrentFile() this._deps.config.set('currentFile', '') + // TODO: Only keep `this.emit` (issue#2210) + this.emit('noFileSelected') this.events.emit('noFileSelected') } @@ -258,6 +268,8 @@ class FileManager extends Plugin { } else { this.editor.open(file, content) } + // TODO: Only keep `this.emit` (issue#2210) + this.emit('currentFileChanged', file) this.events.emit('currentFileChanged', file) } }) @@ -271,6 +283,8 @@ class FileManager extends Plugin { if (fileList.length) { _switchFile(browserProvider.type + '/' + fileList[0]) } else { + // TODO: Only keep `this.emit` (issue#2210) + this.emit('noFileSelected') this.events.emit('noFileSelected') } }) diff --git a/src/app/tabs/theme-module.js b/src/app/tabs/theme-module.js index c010c5bf33..7a59133779 100644 --- a/src/app/tabs/theme-module.js +++ b/src/app/tabs/theme-module.js @@ -60,6 +60,8 @@ export class ThemeModule extends Plugin { document.getElementById('theme-link').setAttribute('href', nextTheme.url) document.documentElement.style.setProperty('--theme', nextTheme.quality) if (themeName) this.active = themeName + // TODO: Only keep `this.emit` (issue#2210) + this.emit('themeChanged', nextTheme) this.events.emit('themeChanged', nextTheme) } } diff --git a/src/framingService.js b/src/framingService.js index fe326b52dd..3106125b4f 100644 --- a/src/framingService.js +++ b/src/framingService.js @@ -10,6 +10,7 @@ export class FramingService { start () { this.sidePanel.events.on('toggle', () => { + console.log('Toggled') this.resizeFeature.panel1.clientWidth !== 0 ? this.resizeFeature.minimize() : this.resizeFeature.maximise() }) this.sidePanel.events.on('showing', () => { From 8c851af9a612ee59630451e5e6e808ed8442c3d8 Mon Sep 17 00:00:00 2001 From: Grandschtroumpf Date: Mon, 22 Jul 2019 15:51:17 +0200 Subject: [PATCH 3/5] standard --- src/app/ui/persmission-handler.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/ui/persmission-handler.js b/src/app/ui/persmission-handler.js index dea16694c4..8c38d3aa47 100644 --- a/src/app/ui/persmission-handler.js +++ b/src/app/ui/persmission-handler.js @@ -109,7 +109,7 @@ export class PermissionHandler { this.permissions = this._getFromLocal() 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] if (!allow) { const warning = notAllowWarning(from, to) From f1fee7a5d1edc2a49600e68d8a3e15c2936ecb36 Mon Sep 17 00:00:00 2001 From: Grandschtroumpf Date: Mon, 22 Jul 2019 16:11:07 +0200 Subject: [PATCH 4/5] remove console.log --- src/framingService.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/framingService.js b/src/framingService.js index 3106125b4f..fe326b52dd 100644 --- a/src/framingService.js +++ b/src/framingService.js @@ -10,7 +10,6 @@ export class FramingService { start () { this.sidePanel.events.on('toggle', () => { - console.log('Toggled') this.resizeFeature.panel1.clientWidth !== 0 ? this.resizeFeature.minimize() : this.resizeFeature.maximise() }) this.sidePanel.events.on('showing', () => { From 63818a29e2783d422db851334b10698dfea27d3d Mon Sep 17 00:00:00 2001 From: Grandschtroumpf Date: Mon, 22 Jul 2019 16:22:39 +0200 Subject: [PATCH 5/5] Permission returns false when not allow --- src/app/ui/persmission-handler.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/app/ui/persmission-handler.js b/src/app/ui/persmission-handler.js index 8c38d3aa47..dc8206a24e 100644 --- a/src/app/ui/persmission-handler.js +++ b/src/app/ui/persmission-handler.js @@ -114,13 +114,13 @@ export class PermissionHandler { if (!allow) { const warning = notAllowWarning(from, to) 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) { - return false + throw new Error(err) } }