MCPcopy Create free account
hub / github.com/TechJeeper/Printventory / initPreviewModal

Function initPreviewModal

preview.js:56–110  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

54 const loading = document.getElementById('preview-loading');
55 if (!loading) return;
56 loading.style.display = 'flex';
57 loading.innerHTML = `
58 <div class="loader"></div>
59 <p>Loading model...</p>
60 `;
61 }
62
63 // Register preview-model listener (server mode WebSocket and normal IPC both dispatch here)
64 const previewCallback = (filePath) => {
65 console.log('[Preview] Received preview-model event for file:', filePath);
66 try {
67 openPreview(filePath);
68 } catch (error) {
69 console.error('[Preview] Error opening preview:', error);
70 }
71 };
72
73 const previewBundleCallback = (payload) => {
74 console.log('[Preview] Received preview-bundle-models event:', payload?.groupLabel, payload?.children?.length);
75 try {
76 if (typeof openBundlePreview === 'function') {
77 openBundlePreview(payload || {});
78 } else {
79 console.error('[Preview] openBundlePreview is not available yet');
80 }
81 } catch (error) {
82 console.error('[Preview] Error opening bundle preview:', error);
83 }
84 };
85
86 function registerPreviewChannel(channel, callback) {
87 if (window.electron && typeof window.electron.receive === 'function') {
88 console.log(`[Preview] Registering ${channel} listener via receive()`);
89 window.electron.receive(channel, callback);
90 return true;
91 }
92 if (window.electron && typeof window.electron.on === 'function') {
93 console.log(`[Preview] Registering ${channel} listener via on()`);
94 window.electron.on(channel, callback);
95 return true;
96 }
97 return false;
98 }
99
100 // Register listener - works in both normal mode and server mode (bridge does not register preview-model)
101 if (!registerPreviewChannel('preview-model', previewCallback) ||
102 !registerPreviewChannel('preview-bundle-models', previewBundleCallback)) {
103 console.warn('[Preview] window.electron not available yet, will retry');
104 const maxAttempts = 50;
105 let attempts = 0;
106 const retryInterval = setInterval(() => {
107 attempts++;
108 const modelOk = registerPreviewChannel('preview-model', previewCallback);
109 const bundleOk = registerPreviewChannel('preview-bundle-models', previewBundleCallback);
110 if (modelOk && bundleOk) {
111 clearInterval(retryInterval);
112 } else if (attempts >= maxAttempts) {
113 console.error('[Preview] Failed to register preview listeners after', attempts, 'attempts');

Callers 1

preview.jsFile · 0.85

Calls 4

closePreviewFunction · 0.85
resetPreviewViewFunction · 0.85
toggleWireframeFunction · 0.85
toggleAxesFunction · 0.85

Tested by

no test coverage detected