From d952eff042e50eaedbcf2f49de6dfe831c0aed39 Mon Sep 17 00:00:00 2001 From: nick Date: Mon, 23 Nov 2026 15:13:06 +0000 Subject: [PATCH] Start native Context launch presence when title-bar status is hidden --- PlotLine.Tests/Browser/native-context-launch.cjs | 14 ++++++++++---- PlotLine/wwwroot/js/native-companion-status.js | 5 +++-- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/PlotLine.Tests/Browser/native-context-launch.cjs b/PlotLine.Tests/Browser/native-context-launch.cjs index 87aeb1de..2885b220 100644 --- a/PlotLine.Tests/Browser/native-context-launch.cjs +++ b/PlotLine.Tests/Browser/native-context-launch.cjs @@ -2,10 +2,11 @@ const {chromium}=require('playwright'); const fs=require('node:fs'),path=require('node:path'),assert=require('node:assert/strict'); const script=fs.readFileSync(path.join(__dirname,'../../PlotLine/wwwroot/js/native-context-launch.js'),'utf8'); +const statusScript=fs.readFileSync(path.join(__dirname,'../../PlotLine/wwwroot/js/native-companion-status.js'),'utf8'); (async()=>{ const browser=await chromium.launch(); try{ - for(const outcome of ['open','reused','pending','failure','no-storage']){ + for(const outcome of ['open','reused','pending','failure','no-storage','no-titlebar']){ const context=await browser.newContext(),page=await context.newPage(); await page.route('https://fixture.invalid/**',route=>route.fulfill({contentType:'text/html',body:'

Context destination

'})); await page.goto('https://fixture.invalid/launch'); @@ -13,12 +14,17 @@ const script=fs.readFileSync(path.join(__dirname,'../../PlotLine/wwwroot/js/nati await page.evaluate(outcome=>{ window.calls=[];window.closedByLaunch=false;window.close=()=>{window.closedByLaunch=true;}; window.PlotDirectorContextEnvironment=outcome==='no-storage'?null:'browser-profile'; - window.PlotDirectorPresenceConnection={state:'Connected',invoke:async(name,...args)=>{ - window.calls.push([name,...args]);if(name==='OpenContextWindow'){if(outcome==='failure')throw new Error('offline');return outcome;} + const connection={state:'Connected',on:()=>{},onreconnected:()=>{},start:async()=>{},stop:async()=>{},invoke:async(name,...args)=>{ + window.calls.push([name,...args]);if(name==='OpenContextWindow'){if(outcome==='failure')throw new Error('offline');return outcome==='no-titlebar'?'open':outcome;} }}; + if(outcome==='no-titlebar'){ + window.fetch=async()=>({ok:true,json:async()=>[]}); + window.signalR={HubConnectionBuilder:class{withUrl(){return this;}withAutomaticReconnect(){return this;}build(){return connection;}}}; + }else window.PlotDirectorPresenceConnection=connection; },outcome); + if(outcome==='no-titlebar')await page.addScriptTag({content:statusScript}); await page.addScriptTag({content:script}); - if(outcome==='open'){ + if(outcome==='open'||outcome==='no-titlebar'){ await page.waitForURL('**/Writing/Context?**');const url=new URL(page.url()); assert.equal(url.searchParams.get('bookId'),'12');assert.equal(url.searchParams.get('sessionId'),'session'); assert.equal(url.searchParams.has('sceneId'),false,'opening cannot force a scene selection'); diff --git a/PlotLine/wwwroot/js/native-companion-status.js b/PlotLine/wwwroot/js/native-companion-status.js index 254978f0..597429a4 100644 --- a/PlotLine/wwwroot/js/native-companion-status.js +++ b/PlotLine/wwwroot/js/native-companion-status.js @@ -1,7 +1,8 @@ (() => { 'use strict';let root=document.querySelector('#native-companion-status'); - // The title-bar presence preference must not disable Writer's shared status stream. - if(!root&&document.querySelector('[data-writer-word]')){root=document.createElement('span');root.id='native-companion-status';root.hidden=true;const label=document.createElement('span');label.id='native-companion-status-text';root.append(label);document.querySelector('[data-writer-word]').append(root);} + // The title-bar preference must not disable Writer or native Context launch's shared status stream. + const statusOwner=document.querySelector('[data-writer-word],[data-native-context-launch]'); + if(!root&&statusOwner){root=document.createElement('span');root.id='native-companion-status';root.hidden=true;const label=document.createElement('span');label.id='native-companion-status-text';root.append(label);statusOwner.append(root);} if(!root||root.nativeStatusStarted)return;root.nativeStatusStarted=true; const text=root.querySelector('#native-companion-status-text');let pending=false,seen=false,refreshAgain=false,reconnectPending=false; const details=document.querySelector('#writing-connection-details'), documents=details?.querySelector('#writing-word-document');