From 5b157a2979cc3fcd86ee985c825582e5fa7e8b9a Mon Sep 17 00:00:00 2001 From: Ibrahim Ansari Date: Tue, 5 Nov 2024 19:45:31 +0530 Subject: [PATCH] Switch to CSS modules from Emotion --- .babelrc | 5 - .yarnrc.yml | 3 + main.go | 32 +- package.json | 7 +- renderer/App.module.scss | 32 + renderer/App.tsx | 56 +- renderer/Dialog.module.scss | 39 ++ renderer/Dialog.tsx | 49 +- renderer/global.d.ts | 1 + renderer/index.tsx | 1 - tsconfig.json | 5 +- yarn.lock | 1203 +++++++---------------------------- 12 files changed, 352 insertions(+), 1081 deletions(-) delete mode 100644 .babelrc create mode 100644 renderer/App.module.scss create mode 100644 renderer/Dialog.module.scss create mode 100644 renderer/global.d.ts diff --git a/.babelrc b/.babelrc deleted file mode 100644 index eb3b510..0000000 --- a/.babelrc +++ /dev/null @@ -1,5 +0,0 @@ -{ - "plugins": [ - "@emotion/babel-plugin" - ] -} diff --git a/.yarnrc.yml b/.yarnrc.yml index f2bd681..2feb8a3 100644 --- a/.yarnrc.yml +++ b/.yarnrc.yml @@ -5,3 +5,6 @@ packageExtensions: "@parcel/node-resolver-core@*": dependencies: "@parcel/core": 2.12.0 + "@parcel/workers@*": + dependencies: + "@parcel/core": 2.12.0 diff --git a/main.go b/main.go index 3540ca4..a5e461d 100644 --- a/main.go +++ b/main.go @@ -30,18 +30,23 @@ var w webview.WebView var html string var overrideUrl = "" +//go:embed dist/index.css +var css string + //go:embed dist/index.js var js string -// ParseToJsString takes a string and escapes slashes and double-quotes, -// and converts it to a string that can be passed to JavaScript. +// 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 { - return "\"" + strings.ReplaceAll(strings.ReplaceAll(s, "\\", "\\\\"), "\"", "\\\"") + "\"" + 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 } -// SetFile sets the value of the file variable in both Go and React. -// func SetFile(value string) {file = value;w.Eval("setFileReact(" + ParseToJsString(value) + ")")} - func main() { if len(os.Args) >= 2 && (os.Args[1] == "-v" || os.Args[1] == "--version") { println("imprint version v" + version) @@ -76,11 +81,14 @@ func main() { w.SetSize(420, 210, webview.HintNone) w.SetTitle("Imprint " + version) - // Bind variables. - // w.Bind("setFileGo", func(newFile string) {file = newFile}) - - // Bind a function to initiate React via webview.Eval. - w.Bind("initiateReact", func() { w.Eval(js) }) + // Bind a function to inject JavaScript and CSS via webview.Eval. + w.Bind("initiate", func() { + w.Eval(`// inject