From d094e2001852a5056e6355739be9f29f3f12e18c Mon Sep 17 00:00:00 2001 From: rafapaezbas <15270736+rafapaezbas@users.noreply.github.com> Date: Tue, 27 Feb 2024 09:21:45 +0100 Subject: [PATCH] implemented update button (#75) * implemented update button * update button changes text on hover * fixed update button functionality --------- Co-authored-by: rafapaezbas --- lib/system-status.js | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/lib/system-status.js b/lib/system-status.js index 7f2ee60..cc0edf2 100644 --- a/lib/system-status.js +++ b/lib/system-status.js @@ -72,6 +72,7 @@ customElements.define('system-status', class extends HTMLElement { this.stmtrx = new RegExp(`^export PATH="${BIN}":\\$PATH$`, 'm') this.shellProfiles = null this.root = this.attachShadow({ mode: 'open' }) + this.update = null this.#render() } @@ -98,6 +99,12 @@ customElements.define('system-status', class extends HTMLElement { #tip { margin-top: 3rem; } + #update-button { + position: fixed; + left: 893px; + top: 170px; + width: 171px; + } h1 { padding: 0.5rem; display: inline-block; @@ -110,6 +117,7 @@ customElements.define('system-status', class extends HTMLElement { }

System Status

+ ${ this.#installed() ? '' @@ -120,14 +128,37 @@ customElements.define('system-status', class extends HTMLElement {

To finish installing Pear Runtime set your system path to

${BIN}

${!isWin ? ' or click the button.' : ''}

- ${!isWin ? '

' : ''} + ${!isWin ? '

' : ''} ` } ` - this.shadowRoot.querySelector('button')?.addEventListener('click', () => { + + this.updateButton = this.shadowRoot.querySelector('#update-button') + this.updateButton.style.display = 'none' + + this.updateButton.addEventListener('mouseenter', (e) => { + e.target.innerText = 'Click to Restart' + }) + this.updateButton.addEventListener('mouseout', (e) => { + e.target.innerText = 'Update Available' + }) + + 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 = '' + + if (this.updateButtonListener) { + this.updateButton.removeEventListener('click', this.updateButtonListener) + } + + this.updateButtonListener = () => Pear.restart({ platform: this.update.app === false }).catch(console.error) + this.updateButton.addEventListener('click', this.updateButtonListener) + }) } #error (err) {