Start native Context launch presence when title-bar status is hidden
This commit is contained in:
parent
be69dfed46
commit
d952eff042
@ -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:'<p>Context destination</p>'}));
|
||||
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');
|
||||
|
||||
@ -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');
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user