Skip to content

Commit

Permalink
Improve debug, fix warn, trim code, enlarge window
Browse files Browse the repository at this point in the history
  • Loading branch information
retrixe committed Nov 10, 2024
1 parent df91191 commit 0bd9a30
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 14 deletions.
16 changes: 5 additions & 11 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,9 @@ var js string
// ParseToJsString takes a string, escapes slashes and double-quotes, adds newlines for multi-line
// strings and wraps it in double-quotes, allowing it to be passed to JavaScript.
func ParseToJsString(s string) string {
split := strings.Split(s, "\n")
result := `"` + strings.ReplaceAll(strings.ReplaceAll(split[0], `\`, `\\`), `"`, `\"`) + `"`
for _, line := range split[1:] {
result += ` + "\n` + strings.ReplaceAll(strings.ReplaceAll(line, `\`, `\\`), `"`, `\"`) + `"`
}
return result
return strings.ReplaceAll(
`"`+strings.ReplaceAll(strings.ReplaceAll(s, `\`, `\\`), `"`, `\"`)+`"`,
"\n", `\n`)
}

func main() {
Expand Down Expand Up @@ -78,15 +75,12 @@ func main() {
}
w = webview.New(debug)
defer w.Destroy()
w.SetSize(420, 210, webview.HintNone)
w.SetSize(540, 240, webview.HintNone)
w.SetTitle("Imprint " + version)

// Bind a function to inject JavaScript and CSS via webview.Eval.
w.Bind("initiate", func() {
w.Eval(`// inject <style> tag
const style = document.createElement('style')
style.textContent = ` + ParseToJsString(css) + `
document.head.appendChild(style)`)
w.Eval(`document.getElementById('inject-css').textContent = ` + ParseToJsString(css))
w.Eval(js)
})

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
"private": true,
"scripts": {
"lint": "eslint . && tsc --noEmit",
"dev": "parcel renderer/index.html & go run -ldflags=\"-s -w -X main.overrideUrl=http://localhost:1234/\" . & echo Starting...",
"start": "parcel build renderer/index.tsx && go run .",
"dev": "parcel renderer/index.html & DEBUG=true go run -ldflags=\"-s -w -X main.overrideUrl=http://localhost:1234/\" . & echo Starting...",
"start": "parcel build renderer/index.tsx && DEBUG=true go run .",
"build": "parcel build renderer/index.tsx --no-source-maps && yarn build:go",
"build:go": "run-script-os",
"build:go:default": "go build -ldflags=\"-s -w\" -o imprint -v",
Expand Down
4 changes: 3 additions & 1 deletion renderer/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ const App = (): JSX.Element => {
globalThis.setProgressReact = setProgress
globalThis.setFileSizeReact = setFileSize
globalThis.setSelectedDeviceReact = setSelectedDevice
useEffect(() => globalThis.refreshDevices(), [])
useEffect(() => {
globalThis.refreshDevices()
}, [])

const inProgress = typeof progress === 'number'
useEffect(() => setConfirm(false), [inProgress])
Expand Down
1 change: 1 addition & 0 deletions renderer/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
Ubuntu,Cantarell,Oxygen-Sans,"Helvetica Neue",Arial,Roboto,sans-serif;
}
</style>
<style id='inject-css'></style>
</head>
<body><div id="app"></div><script type="module" src="./index.tsx" /></body>
</html>

0 comments on commit 0bd9a30

Please sign in to comment.