From 7629756c38eaffbc480c4d4f8cfa9cc3c614a640 Mon Sep 17 00:00:00 2001 From: David Mark Clements Date: Thu, 7 Mar 2024 02:42:15 +0100 Subject: [PATCH] wakeup focus & deep-link routing (#86) * wakeup focus & deep-link routing * conventionalize * should be wakeups * fix --- lib/app-router.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/app-router.js b/lib/app-router.js index 4091102..d25423a 100644 --- a/lib/app-router.js +++ b/lib/app-router.js @@ -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) + }) }) } })