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

implemented update button #75

Merged
merged 4 commits into from
Feb 27, 2024
Merged
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
35 changes: 33 additions & 2 deletions lib/system-status.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand All @@ -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;
Expand All @@ -110,6 +117,7 @@ customElements.define('system-status', class extends HTMLElement {
}
</style>
<h1>System Status</h1>
<button id="update-button"> Update Available </button>
${
this.#installed()
? '<pear-welcome></pear-welcome>'
Expand All @@ -120,14 +128,37 @@ 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.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) {
Expand Down
Loading