Skip to content

Commit

Permalink
Fixed: Settings: Request permissions on option change
Browse files Browse the repository at this point in the history
  • Loading branch information
mbnuqw committed Oct 3, 2022
1 parent 584d5b0 commit 00ee928
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 19 deletions.
15 changes: 7 additions & 8 deletions src/page.setup/components/popup.container-config.vue
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ async function init(): Promise<void> {
if (userAgentInput.value) userAgentInput.value.recalcTextHeight()
}
function checkWebDataPerm(): boolean {
async function checkWebDataPerm(): Promise<boolean> {
if (!Permissions.reactive.webData) {
if (props.conf.proxified) {
props.conf.proxified = false
Expand All @@ -248,14 +248,13 @@ function checkWebDataPerm(): boolean {
props.conf.excludeHostsActive = false
props.conf.userAgentActive = false
Containers.saveContainers()
window.location.hash = 'all-urls'
return false
return Permissions.request('<all_urls>')
}
return true
}
async function toggleIncludeHosts(): Promise<void> {
if (!props.conf.includeHostsActive && !checkWebDataPerm()) return
if (!props.conf.includeHostsActive && !(await checkWebDataPerm())) return
props.conf.includeHostsActive = !props.conf.includeHostsActive
Containers.saveContainers()
Expand All @@ -270,7 +269,7 @@ function onIncludeHostsInput(value: string): void {
}
async function toggleExcludeHosts(): Promise<void> {
if (!props.conf.excludeHostsActive && !checkWebDataPerm()) return
if (!props.conf.excludeHostsActive && !(await checkWebDataPerm())) return
props.conf.excludeHostsActive = !props.conf.excludeHostsActive
Containers.saveContainers()
Expand All @@ -284,8 +283,8 @@ function onExcludeHostsInput(value: string): void {
Containers.saveContainers(500)
}
function switchProxy(type: browser.proxy.ProxyType): void {
if (type !== 'direct' && !checkWebDataPerm()) return
async function switchProxy(type: browser.proxy.ProxyType): Promise<void> {
if (type !== 'direct' && !(await checkWebDataPerm())) return
props.conf.proxy = {
type,
Expand Down Expand Up @@ -352,7 +351,7 @@ function onFieldKeydown(
}
async function toggleUserAgent(): Promise<void> {
if (!props.conf.userAgentActive && !checkWebDataPerm()) return
if (!props.conf.userAgentActive && !(await checkWebDataPerm())) return
props.conf.userAgentActive = !props.conf.userAgentActive
Containers.saveContainers()
Expand Down
9 changes: 4 additions & 5 deletions src/page.setup/components/popup.panel-config.vue
Original file line number Diff line number Diff line change
Expand Up @@ -472,11 +472,10 @@ function togglePanelMoveTabCtxNoChild(value: boolean): void {
async function toggleUrlRules(): Promise<void> {
if (!Utils.isTabsPanel(props.conf)) return
if (!props.conf.urlRulesActive) {
if (!Permissions.reactive.webData) {
window.location.hash = 'all-urls'
return
}
if (!props.conf.urlRulesActive && !Permissions.reactive.webData) {
const result = await Permissions.request('<all_urls>')
if (!result) return
}
props.conf.urlRulesActive = !props.conf.urlRulesActive
Expand Down
10 changes: 7 additions & 3 deletions src/page.setup/components/settings.tabs-tree.vue
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,13 @@ const el = ref<HTMLElement | null>(null)
onMounted(() => SetupPage.registerEl('settings_tabs_tree', el.value))
function toggleHideFoldedTabs(): void {
if (!Settings.state.hideFoldedTabs && !Permissions.reactive.tabHide) location.hash = 'tab-hide'
else Settings.state.hideFoldedTabs = !Settings.state.hideFoldedTabs
async function toggleHideFoldedTabs(): Promise<void> {
if (!Settings.state.hideInact && !Permissions.reactive.tabHide) {
const result = await Permissions.request('tabHide')
if (!result) return
}
Settings.state.hideFoldedTabs = !Settings.state.hideFoldedTabs
Settings.saveDebounced(150)
}
Expand Down
10 changes: 7 additions & 3 deletions src/page.setup/components/settings.tabs.vue
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,13 @@ function toggleActivateLastTabOnPanelSwitching(): void {
Settings.saveDebounced(150)
}
function toggleHideInact(): void {
if (!Settings.state.hideInact && !Permissions.reactive.tabHide) location.hash = 'tab-hide'
else Settings.state.hideInact = !Settings.state.hideInact
async function toggleHideInact(): Promise<void> {
if (!Settings.state.hideInact && !Permissions.reactive.tabHide) {
const result = await Permissions.request('tabHide')
if (!result) return
}
Settings.state.hideInact = !Settings.state.hideInact
if (Settings.state.hideInact && !Settings.state.activateLastTabOnPanelSwitching) {
Settings.state.activateLastTabOnPanelSwitching = true
Expand Down

0 comments on commit 00ee928

Please sign in to comment.