Skip to content

Commit

Permalink
Install profiles to a new profile by default on Linux/macOS (closes #216
Browse files Browse the repository at this point in the history
)
  • Loading branch information
filips123 committed Sep 17, 2022
1 parent 01966a8 commit 2dc9cc5
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
21 changes: 18 additions & 3 deletions extension/src/sites/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ async function initializeForm () {
// Add an option to create a new profile to the select input
profilesElement.add(new Option('Create a new profile', 'create-new-profile'))

// Add an option to automatically create a new profile to the select input
const autoNewProfile = platform.os === 'linux' || platform.os === 'mac'
profilesElement.add(new Option('Automatically create a new profile', 'auto-create-new-profile', autoNewProfile, autoNewProfile))

// Handle creating a new profile
let lastProfileSelection = profilesElement.value
profilesElement.addEventListener('change', function (event) {
Expand Down Expand Up @@ -160,8 +164,8 @@ async function initializeForm () {

// Create a new option in the select input and select it
const id = response.data
profilesElement.add(new Option(name ?? id, id, true, true), profilesElement.length - 1)
profilesElement.value = profilesElement.length - 2
profilesElement.add(new Option(name ?? id, id, true, true), profilesElement.length - 2)
profilesElement.value = profilesElement.length - 3

// Hide the modal
Modal.getOrCreateInstance(document.getElementById('new-profile-modal'), { backdrop: 'static', keyboard: false }).hide()
Expand Down Expand Up @@ -271,7 +275,7 @@ async function initializeForm () {

// Get simple site data
const startUrl = document.getElementById('web-app-start-url').value || null
const profile = document.getElementById('web-app-profile').value || null
let profile = document.getElementById('web-app-profile').value || null
const name = document.getElementById('web-app-name').value || null
const description = document.getElementById('web-app-description').value || null

Expand All @@ -298,6 +302,17 @@ async function initializeForm () {
manifestUrl += fromByteArray(new TextEncoder().encode(JSON.stringify(manifest)))
}

// Create a new profile if requested by the user
if (profile === 'auto-create-new-profile') {
const profileName = name || manifest.name || manifest.short_name || new URL(manifest.scope).host
const response = await browser.runtime.sendNativeMessage('firefoxpwa', { cmd: 'CreateProfile', params: { name: profileName } })

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

profile = response.data
}

// Tell the native connector to install the site
const response = await browser.runtime.sendNativeMessage('firefoxpwa', {
cmd: 'InstallSite',
Expand Down
2 changes: 1 addition & 1 deletion extension/src/sites/manage.html
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ <h5 class="offcanvas-title" id="profile-edit-label">Edit profile</h5>
<label for="profile-description" class="form-label">Description</label>
<input type="text" class="form-control form-control-sm" id="profile-description" />
</div>
<div class="mb-3">
<div class="mb-3" id="profile-ulid-div">
<label for="profile-ulid" class="form-label fw-bold">ID</label>
<input type="url" class="form-control form-control-sm" id="profile-ulid" readonly />
</div>
Expand Down
6 changes: 6 additions & 0 deletions extension/src/sites/manage.js
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,9 @@ async function createProfileList () {
document.getElementById('profile-name').value = ''
document.getElementById('profile-description').value = ''

// Hide profile ULID box
document.getElementById('profile-ulid-div').classList.add('d-none')

// Set form to be validated after all inputs are filled with default values and enable submit button
form.classList.add('was-validated')
submit.disabled = false
Expand Down Expand Up @@ -455,6 +458,9 @@ async function createProfileList () {
document.getElementById('profile-description').value = profile.description || ''
document.getElementById('profile-ulid').value = profile.ulid

// Show profile ULID box
document.getElementById('profile-ulid-div').classList.remove('d-none')

// Set form to be validated after all inputs are filled with default values and enable submit button
form.classList.add('was-validated')
submit.disabled = false
Expand Down

0 comments on commit 2dc9cc5

Please sign in to comment.