wakeup focus & deep-link routing (#86)

* wakeup focus & deep-link routing

* conventionalize

* should be wakeups

* fix
This commit is contained in:
David Mark Clements
2024-03-07 02:42:15 +01:00
committed by GitHub
parent de7975a380
commit 7629756c38

View File

@@ -3,6 +3,7 @@ customElements.define('app-router', class AppRouter extends HTMLElement {
constructor () {
super()
this.routes = {}
this.page = null
}
unload () {
@@ -10,6 +11,8 @@ customElements.define('app-router', class AppRouter extends HTMLElement {
}
async load (pathname = '/', opts = {}) {
if (this.page === pathname) return
this.page = pathname
for (const [route, element] of Object.entries(this.routes)) {
if (pathname.startsWith(route)) {
const page = pathname.slice(route.length) || '/'
@@ -67,11 +70,14 @@ customElements.define('app-router', class AppRouter extends HTMLElement {
})
window.addEventListener('load', () => {
if (Pear.config.link.indexOf('pear://runtime/') === 0) {
this.load(Pear.config.link.slice(14)).catch(console.error)
} else {
this.load('/')
}
const page = '/' + (Pear.config.linkData || '')
console.log('load', page)
this.load(page).catch(console.error)
Pear.wakeups(({ data }) => {
Pear.Window.self.focus().catch(console.error)
const page = '/' + (data || '')
this.load(page).catch(console.error)
})
})
}
})