-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebview_nocgo.go
More file actions
56 lines (46 loc) · 1.46 KB
/
webview_nocgo.go
File metadata and controls
56 lines (46 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
//go:build !cgo || windows
package main
import (
"fmt"
"os"
"os/exec"
"path/filepath"
"runtime"
)
// OpenNoteInWebview opens a note in the default system browser as fallback
func OpenNoteInWebview(title, htmlContent string) error {
// Create a temporary HTML file
tempDir := os.TempDir()
tempFile := filepath.Join(tempDir, fmt.Sprintf("vimango_%s.html", title))
// Write HTML content to temp file
err := os.WriteFile(tempFile, []byte(htmlContent), 0644)
if err != nil {
return fmt.Errorf("failed to create temporary HTML file: %v", err)
}
// Open in default browser
var cmd *exec.Cmd
switch runtime.GOOS {
case "linux":
cmd = exec.Command("xdg-open", tempFile)
case "darwin":
cmd = exec.Command("open", tempFile)
case "windows":
cmd = exec.Command("cmd", "/c", "start", tempFile)
default:
return fmt.Errorf("unsupported operating system: %s", runtime.GOOS)
}
return cmd.Start()
}
// CloseWebview returns an error for non-CGO builds (can't close browser programmatically)
func CloseWebview() error {
return fmt.Errorf("webview close not available (browser was opened instead)")
}
// IsWebviewRunning returns false for non-CGO builds
func IsWebviewRunning() bool {
return isWebviewRunning
}
// ShowWebviewUnavailableMessage shows a message when webview is not available
func ShowWebviewUnavailableMessage() {
fmt.Println("Webview is not available in this build (requires CGO).")
fmt.Println("Note will be opened in your default browser instead.")
}