From bc7689e16c03c507278815202352fb2cb46aeebe Mon Sep 17 00:00:00 2001 From: dmc Date: Wed, 6 Mar 2024 15:33:32 +0100 Subject: [PATCH] wakeup focus & deep-link routing --- lib/app-router.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/app-router.js b/lib/app-router.js index 4091102..ee656ce 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 = '/' } 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,16 @@ 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) + if (Pear.config.linkData) { + this.load('/' + Pear.config.linkData).catch(console.error) } else { this.load('/') } + Pear.wakeup(({ data }) => { + Pear.Window.self.focus().catch(console.error) + const page = '/' + (data || '') + this.load(page).catch(console.error) + }) }) } })