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

Prompt the user to delete the profile when deleting its last site #422

Merged
merged 4 commits into from
Nov 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions extension/src/sites/manage.html
Original file line number Diff line number Diff line change
Expand Up @@ -376,8 +376,18 @@ <h5 class="modal-title" id="site-remove-label">Remove web app</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
Are you sure you want to remove this web app? App data will <strong>not</strong> be
removed, but you can remove them through the app browser or by deleting app's profile.
Are you sure you want to remove this web app?
<div id="site-remove-not-last">
Other apps are present in this profile, so the profile will <strong>not</strong> be removed.
The app data will <strong>remain</strong>, but you can remove them through the app browser or by deleting the app's profile.
</div>
<div id="site-remove-last">
This is the last app in this profile, so you can choose to delete it and the associated app data.
<div class="form-check pt-2">
<input class="form-check-input" type="checkbox" id="site-remove-last-checkbox" checked>
<label class="form-check-label" for="site-remove-last-checkbox">Delete profile and app data</label>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button>
Expand Down
38 changes: 31 additions & 7 deletions extension/src/sites/manage.js
Original file line number Diff line number Diff line change
Expand Up @@ -367,17 +367,33 @@ async function createSiteList () {

const removeElement = siteElement.querySelector('#sites-list-template-remove')
removeElement.addEventListener('click', () => {
const lastSiteInProfile = profiles[site.profile].sites.length <= 1

document.getElementById('site-remove-button').onclick = async function () {
this.disabled = true
this.innerText = 'Removing...'

const response = await browser.runtime.sendNativeMessage('firefoxpwa', {
cmd: 'UninstallSite',
params: { id: site.ulid }
})

if (response.type === 'Error') throw new Error(response.data)
if (response.type !== 'SiteUninstalled') throw new Error(`Received invalid response type: ${response.type}`)
const deleteProfileCheckbox = document.getElementById('site-remove-last-checkbox')
const deleteProfileEnabled = deleteProfileCheckbox.checked
deleteProfileCheckbox.disabled = true

if (lastSiteInProfile && deleteProfileEnabled) {
const response = await browser.runtime.sendNativeMessage('firefoxpwa', {
cmd: 'RemoveProfile',
params: { id: site.profile }
})

if (response.type === 'Error') throw new Error(response.data)
if (response.type !== 'ProfileRemoved') throw new Error(`Received invalid response type: ${response.type}`)
} else {
const response = await browser.runtime.sendNativeMessage('firefoxpwa', {
cmd: 'UninstallSite',
params: { id: site.ulid }
})

if (response.type === 'Error') throw new Error(response.data)
if (response.type !== 'SiteUninstalled') throw new Error(`Received invalid response type: ${response.type}`)
}

this.disabled = true
this.innerText = 'Removed!'
Expand All @@ -388,6 +404,14 @@ async function createSiteList () {
}, 5000)
}

if (lastSiteInProfile) {
document.getElementById('site-remove-last').hidden = false
document.getElementById('site-remove-not-last').hidden = true
} else {
document.getElementById('site-remove-last').hidden = true
document.getElementById('site-remove-not-last').hidden = false
}

Modal.getOrCreateInstance(document.getElementById('site-remove-modal')).show()
})
removeElement.removeAttribute('id')
Expand Down