Workplace Widget 5.10.8

This commit is contained in:
chris
2026-11-01 10:09:34 +00:00
parent 513550f58d
commit 180127e2ae
21 changed files with 397 additions and 26 deletions

View File

@@ -6,6 +6,8 @@ const screen=document.getElementById('display');
const notice=document.getElementById('state');
const BRIDGE_JAR='/app/backend/hmi/cheerpj/workplace-resize-bridge-v2.jar';
const WORKPLACE_MANIFEST='/backend/api/hmi/v1/cheerpj/workplace/manifest.jnlp';
// Writable, browser-local CheerpJ directory; never a GlassFish/server filesystem path.
const WORKPLACE_TMP_DIR='/files/itac-workplace/tmp';
let busy=false;
const trusted=(raw,base=location.href)=>{
const u=new URL(raw,base);
@@ -36,6 +38,18 @@ function readManifest(xml,jnlpUrl){
if(platformGroups.length)warnings.push('Plattformspezifische/native JNLP-Ressourcen werden nicht geladen.');
if(root.getElementsByTagName('nativelib').length)warnings.push('Native RXTX-/JNI-Treiber laufen nicht im Browser.');
if(jvm?.getAttribute('java-vm-args'))warnings.push('JNLP-JVM-Optionen werden nicht vollständig übernommen.');
const properties=groups.filter(g=>!g.hasAttribute('os')&&!g.hasAttribute('arch'))
.flatMap(g=>Array.from(g.getElementsByTagName('property')));
const clusterValues=properties.filter(p=>p.getAttribute('name')==='itac.artes.clusternodes')
.map(p=>String(p.getAttribute('value')||''));
if(clusterValues.length>1)throw Error('Mehrfache MES-Clusterkonfiguration ist nicht zulässig.');
let clusterNodes='';
if(clusterValues.length){
const target=new URL(clusterValues[0]);
if(!['http:','https:'].includes(target.protocol)||target.username||target.password||target.search||target.hash||target.pathname!=='/mes')
throw Error('Ungültige MES-Clusteradresse in der JNLP.');
clusterNodes=target.origin+'/mes';
}
const base=root.getAttribute('codebase')?trusted(root.getAttribute('codebase'),jnlpUrl):new URL('.',jnlpUrl);
const paths=jars.map(j=>{
const href=j.getAttribute('href');if(!href)throw Error('JAR ohne href.');
@@ -49,12 +63,35 @@ function readManifest(xml,jnlpUrl){
const args=Array.from(app.childNodes).filter(e=>e.nodeType===1&&e.localName==='argument').map(e=>e.textContent||'');
if(args.length>32||args.some(a=>a.length>2048))throw Error('Zu viele/lange JNLP-Argumente.');
if(!main&&paths.length>1)throw Error('JNLP mit mehreren JARs benötigt main-class für einen sicheren Klassenpfad.');
return {main,paths,args,required,warnings};
return {main,paths,args,required,warnings,clusterNodes};
}
/** Load a separate, unsigned iTAC-independent helper in the same CheerpJ runtime.
* Only the immutable, locally packaged Bridge JAR is loaded; no vendor JAR is modified.
* When the JVM has not created MesSuiteFrame yet, retry for a bounded startup window.
*/
async function ensureWorkplaceTempDirectory() {
// /app is read-only and /str is read-only to Java. CheerpJ's /files mount
// supports Java writes (IndexedDB, per-browser origin). Create via Java NIO,
// not JavaScript, because JS cannot write directly into /files.
if (typeof window.cheerpjRunLibrary !== 'function')
throw Error('CheerpJ Library Mode für die Temp-Verzeichnisanlage nicht verfügbar.');
const lib=await window.cheerpjRunLibrary('');
const Paths=await lib.java.nio.file.Paths;
const Files=await lib.java.nio.file.Files;
const path=await Paths.get(WORKPLACE_TMP_DIR);
try {
await Files.createDirectories(path, []);
if (await Files.isDirectory(path, []) !== true)
throw Error('Pfad ist kein Verzeichnis.');
// Checking the directory alone is not enough: verify actual write access.
const probe=await Files.createTempFile(path,'hmi-tmp-check-','.tmp',[]);
await Files.deleteIfExists(probe);
} catch(error) {
throw Error('CheerpJ-Temp-Verzeichnis '+WORKPLACE_TMP_DIR+' nicht verfügbar: '+
(error instanceof Error ? error.message : String(error)));
}
}
async function attachWorkplaceResize(container, classPath, mode) {
if (typeof window.cheerpjRunLibrary !== 'function')
throw Error('CheerpJ Library Mode für die ResizeBridge nicht verfügbar.');
@@ -121,7 +158,16 @@ async function start(e,data){
if(typeof window.cheerpjInit!=='function'){
await new Promise((resolve,reject)=>{let count=0;const timer=setInterval(()=>{if(typeof window.cheerpjInit==='function'){clearInterval(timer);resolve();}else if(++count>150){clearInterval(timer);reject(Error('CheerpJ CDN nicht erreichbar oder durch CSP blockiert.'));}},100);});
}
await window.cheerpjInit({version,status:'none'});
// JNLP URL query parameters are not Java system properties.
// CheerpJ 4.3 supplies -D equivalents through javaProperties.
const javaProperties=isWorkplace && manifest.clusterNodes
? ['itac.artes.clusternodes='+manifest.clusterNodes] : [];
if(isWorkplace)javaProperties.push('java.io.tmpdir='+WORKPLACE_TMP_DIR);
await window.cheerpjInit({version,status:'none',javaProperties});
if(isWorkplace){
status(id,'loading','Virtuelles Workplace-Temp-Verzeichnis wird vorbereitet …');
await ensureWorkplaceTempDirectory();
}
if(isWorkplace && displayMode==='original'){
document.body.classList.add('cheerpj-original-mode');
window.cheerpjCreateDisplay(1280,1024,screen);