Skip to content

Commit

Permalink
implemented update button
Browse files Browse the repository at this point in the history
  • Loading branch information
rafapaezbas committed Feb 26, 2024
1 parent 3087059 commit d4cb2b3
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions lib/system-status.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ customElements.define('system-status', class extends HTMLElement {
this.shellProfiles = null
this.root = this.attachShadow({ mode: 'open' })
this.#render()
this.updateButton = this.shadowRoot.querySelector('#update-button')
this.update = null
}

#render () {
Expand All @@ -98,6 +100,12 @@ customElements.define('system-status', class extends HTMLElement {
#tip {
margin-top: 3rem;
}
#update-button {
position: fixed;
left: 975px;
top: 170px;
display: none;
}
h1 {
padding: 0.5rem;
display: inline-block;
Expand All @@ -110,6 +118,7 @@ customElements.define('system-status', class extends HTMLElement {
}
</style>
<h1>System Status</h1>
<button id="update-button"> Update </button>
${
this.#installed()
? '<pear-welcome></pear-welcome>'
Expand All @@ -120,14 +129,21 @@ customElements.define('system-status', class extends HTMLElement {
<p>To finish installing Pear Runtime set your system path to</p>
<p><code>${BIN}</code></p>
<p>${!isWin? ' or click the button.' : ''}</p>
${!isWin ? '<p><button> Automatic Setup Completion </button><p>' : ''}
${!isWin ? '<p><button id="setup-button"> Automatic Setup Completion </button><p>' : ''}
`
}
</div>
`
this.shadowRoot.querySelector('button')?.addEventListener('click', () => {
this.shadowRoot.querySelector('#setup-button')?.addEventListener('click', () => {
this.#install().then(() => this.#render()).catch((err) => this.#error(err))
})

Pear.updates((update) => {
this.update = update
this.updateButton.style.display = ''
this.updateButton.removeEventListener('click', this.#updateButtonListener)
this.updateButton.addEventListener('click', this.#updateButtonListener)
})
}

#error (err) {
Expand Down Expand Up @@ -200,4 +216,8 @@ customElements.define('system-status', class extends HTMLElement {
process.env.PATH = `${BIN}:${process.env.PATH}`
return Promise.resolve()
}

#updateButtonListener () {
Pear.restart({ platform: this.update.app === false }).catch(console.error)
}
})

0 comments on commit d4cb2b3

Please sign in to comment.