+ Context
+ Checking your Context windows for this book…
+
+
+@section Scripts {
+
+}
diff --git a/PlotLine/wwwroot/js/context-windows.js b/PlotLine/wwwroot/js/context-windows.js
index ee28662f..5d10c55f 100644
--- a/PlotLine/wwwroot/js/context-windows.js
+++ b/PlotLine/wwwroot/js/context-windows.js
@@ -31,6 +31,7 @@
}catch{fallback(node,command,'unavailable');}}
function complete(node,command,status){if(!node?.isConnected)return;if(status==='focused')node.textContent='Reference focused in the selected tool. Word position is unchanged.';else fallback(node,command,status);}
connection?.on('ContextWindowsChanged',()=>void discover());
+ connection?.on('ContextWindowRequested',()=>{window.focus();});
connection?.on('ContextInteraction',async delivery=>{let status='unavailable';try{if(delivery.command.bookID===controller.announcement.bookID)status=await controller.receiveInteraction(delivery);}catch{status='unavailable';}void connection.invoke('CompleteContextInteraction',delivery.commandID,status).catch(()=>{});});
connection?.on('ContextInteractionResult',result=>{const item=pending.get(result.commandID);if(item?.node){complete(item.node,item.command,result.status);pending.delete(result.commandID);}else pending.set(result.commandID,{status:result.status,expires:Date.now()+20000});});
root.addEventListener('context-connection-ready',()=>{pending.clear();void register();});
diff --git a/PlotLine/wwwroot/js/native-context-launch.js b/PlotLine/wwwroot/js/native-context-launch.js
new file mode 100644
index 00000000..3d2419a7
--- /dev/null
+++ b/PlotLine/wwwroot/js/native-context-launch.js
@@ -0,0 +1,28 @@
+// Reuse My Windows in this authenticated browser environment. Opening never publishes focus.
+(() => {
+ 'use strict';
+ const root=document.querySelector('[data-native-context-launch]');if(!root)return;
+ const message=root.querySelector('[data-context-launch-status]'),retry=root.querySelector('[data-context-launch-retry]');
+ const windowID=crypto.randomUUID(),bookID=Number(root.dataset.book);let running=false,finished=false;
+ async function open(){
+ const connection=window.PlotDirectorPresenceConnection,environmentID=window.PlotDirectorContextEnvironment;
+ if(running||finished||connection?.state!=='Connected')return;
+ if(!environmentID){message.textContent='Context window discovery requires browser storage. No additional window was opened.';return;}
+ running=true;retry.hidden=true;
+ try{
+ await connection.invoke('RegisterContextWindow',{version:1,bookID,windowID,environmentID,panes:[]});
+ const result=await connection.invoke('OpenContextWindow',bookID);
+ if(result==='open'){
+ const url=new URL('/Writing/Context',location.origin);
+ for(const key of ['book','project','instance','session'])if(root.dataset[key])url.searchParams.set(key+'Id',root.dataset[key]);
+ finished=true;location.replace(url.href);
+ }else if(result==='reused'||result==='pending'){
+ finished=true;message.textContent=result==='reused'?'Context is already open. Its layout, tools, Hold and position were retained.':'A Context window is already opening for this book.';
+ window.close();
+ }
+ }catch{message.textContent='Context window discovery is unavailable. Reconnect and retry; no other window was changed.';retry.hidden=false;}
+ finally{running=false;}
+ }
+ document.addEventListener('pd-presence-ready',()=>void open());
+ retry.addEventListener('click',()=>void open());void open();
+})();