toast_svelte_cgo.go RawHistoryFolder
1//go:build webkit_cgo
2
3package webkit
4
5import (
6 "fmt"
7 "log"
8)
9
10// getToastScript returns the unified GUI bundle-based toast notification script with GTK theme integration.
11// This function is deprecated and should use the new unified approach via BrowserService.InjectToastSystem
12func getToastScript(assets interface{ ReadFile(string) ([]byte, error) }) string {
13 // Read the unified GUI bundle from assets
14 var guiBundle string
15 if assets != nil {
16 bundleBytes, err := assets.ReadFile("gui/gui.min.js")
17 if err != nil {
18 // Fallback to error message if file not found
19 guiBundle = `console.error("❌ Failed to load unified GUI bundle: ` + err.Error() + `");`
20 log.Printf("[webkit] Failed to read GUI bundle: %v", err)
21 } else {
22 guiBundle = string(bundleBytes)
23 log.Printf("[webkit] Successfully loaded unified GUI bundle (%d bytes)", len(bundleBytes))
24 }
25 } else {
26 guiBundle = `console.error("❌ Failed to load unified GUI bundle: assets not provided");`
27 log.Printf("[webkit] GUI bundle error: assets not provided")
28 }
29
30 // GTK Theme Integration with new unified approach
31 themeIntegration := `
32// Set up theme change listener for dynamic updates
33window.__dumber_setTheme = (theme) => {
34 window.__dumber_initial_theme = theme;
35 if (theme === 'dark') {
36 document.documentElement.classList.add('dark');
37 } else {
38 document.documentElement.classList.remove('dark');
39 }
40};
41`
42
43 // Use unified GUI bundle approach
44 return fmt.Sprintf(`(function() {
45 function initializeToast() {
46 try {
47 %s
48
49 %s
50
51 // Initialize toast system via unified GUI bundle
52 if (window.__dumber_gui && window.__dumber_gui.initializeToast) {
53 window.__dumber_gui.initializeToast().then(() => {
54 console.log('✅ Toast system initialized via unified GUI bundle');
55 }).catch((e) => {
56 console.error('❌ Toast initialization failed:', e);
57 });
58 } else {
59 console.error('❌ Unified GUI bundle not properly loaded');
60 }
61 } catch (e) {
62 console.error('❌ Failed to initialize toast system:', e);
63 }
64 }
65
66 // Ensure DOM is ready before initializing
67 if (document.readyState === 'loading') {
68 document.addEventListener('DOMContentLoaded', initializeToast);
69 } else {
70 initializeToast();
71 }
72})();`, themeIntegration, guiBundle)
73}