Skip to content

Commit

Permalink
Refresh preferences page if changed in another tab or in the popup (#277
Browse files Browse the repository at this point in the history
)
  • Loading branch information
stoically committed Jun 28, 2019
1 parent 95d9087 commit 84b365a
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 14 deletions.
2 changes: 2 additions & 0 deletions src/background/runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ class Runtime {
this.storage.local.preferences = message.payload.preferences;
await this.storage.persist();

browser.runtime.sendMessage({info: 'preferencesUpdated', fromTabId: sender.tab && sender.tab.id});

if (this.storage.local.preferences.contextMenu !== message.payload.preferences.contextMenu ||
this.storage.local.preferences.contextMenuBookmarks !== message.payload.preferences.contextMenuBookmarks ||
this.storage.local.preferences.deletesHistory.contextMenu !== message.payload.preferences.deletesHistory.contextMenu ||
Expand Down
2 changes: 1 addition & 1 deletion src/ui/components/export_import.vue
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export default {
resolve(JSON.parse(event.target.result));
} catch (error) {
// eslint-disable-next-line no-console
console.log('error while importing preferences', error);
console.error('error while importing preferences', error);
this.$root.$emit('showError', 'Error while importing preferences!');
}
};
Expand Down
16 changes: 10 additions & 6 deletions src/ui/components/isolation/global.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export default {
};
},
async mounted() {
this.$nextTick(() => {
$('#isolationGlobal .ui.accordion').accordion({
...this.popup ? {
Expand Down Expand Up @@ -67,13 +68,15 @@ export default {
'Permanent containers to exclude'
,
values: excludeContainers,
onChange: (selectedContainers) => {
this.preferences.isolation.global.excludedContainers = {};
if (selectedContainers) {
selectedContainers.split(',').map(excludeContainer => {
this.$set(this.preferences.isolation.global.excludedContainers, excludeContainer, {});
});
onAdd: (addedContainer) => {
if (this.preferences.isolation.global.excludedContainers[addedContainer]) {
return;
}
this.$set(this.preferences.isolation.global.excludedContainers, addedContainer, {});
},
onRemove: (removedContainer) => {
console.log(removedContainer);
this.$delete(this.preferences.isolation.global.excludedContainers, removedContainer, {});
}
});
Expand All @@ -87,6 +90,7 @@ export default {
this.excludeDomainPattern = '';
}
});
},
methods: {
removeExcludedDomain(excludedDomainPattern) {
Expand Down
11 changes: 10 additions & 1 deletion src/ui/options.vue
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,16 @@ export default {
$.address.value(hash.replace('#/', ''));
}
}, 100);
browser.runtime.onMessage.addListener(message => {
if (typeof message !== 'object') {
return;
}
if (message.info && message.info === 'preferencesUpdated' &&
(!message.fromTabId || (message.fromTabId !== this.app.currentTab.id))) {
this.$root.$emit('initialize');
}
});
}
};
</script>
Expand Down Expand Up @@ -86,7 +96,6 @@ export default {
>{{ t('optionsNavExportImport') }}</a>
</div>
<message />

<div
class="ui tab segment"
data-tab="general"
Expand Down
19 changes: 13 additions & 6 deletions src/ui/root.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ export default (App, {popup = false}) => {
data: () => ({
app: {
initialized: false,
popup,
expandedPreferences: false
}
popup
},
expandedPreferences: false
}),
watch: {
app: {
Expand Down Expand Up @@ -55,7 +55,11 @@ export default (App, {popup = false}) => {
this.initialize();

this.$root.$on('initialize', () => {
this.app.initialized = false;
this.app = {
initialized: false,
preferences: false,
popup
};
this.$nextTick(() => {
this.initialize();
});
Expand All @@ -82,17 +86,20 @@ export default (App, {popup = false}) => {
this.$root.$emit('showPreferencesError', error);
}

let activeTab = false;
let activeTab;
if (popup) {
const [tab] = await browser.tabs.query({currentWindow: true, active: true});
tab.parsedUrl = new URL(tab.url);
activeTab = tab;
activeTab.parsedUrl = new URL(tab.url);
}

const currentTab = await browser.tabs.getCurrent();

this.app = {
initialized: true,
popup,
activeTab,
currentTab,
storage,
preferences: storage.preferences,
permissions
Expand Down

0 comments on commit 84b365a

Please sign in to comment.