From 9746d09928a520d67c7929da4c8f2f5b4a7b4267 Mon Sep 17 00:00:00 2001 From: Rohan Singh Date: Mon, 6 May 2024 10:52:28 -0400 Subject: [PATCH] Get rid of WebAssembly version of Pixlet UI This was added in #784, but was no longer being used or maintained. We may build a WASM version Pixlet again in the future, but it would probably just be the Starlark runtime. --- Makefile | 10 +- go.mod | 2 - go.sum | 4 - package.json | 4 +- server/browser/serve_js.go | 14 -- src/Main.jsx | 36 --- src/apps/cms.star | 273 ----------------------- src/features/controls/Controls.jsx | 2 +- src/features/preview/Preview.jsx | 5 +- src/features/preview/actions.js | 68 ++---- src/features/schema/FieldDetails.jsx | 3 - src/features/schema/fields/TextInput.jsx | 9 +- src/features/watcher/WatcherManager.jsx | 5 - src/index.js | 20 +- src/sw.js | 22 -- webpack.dev.js | 20 +- webpack.prod.js | 20 +- 17 files changed, 37 insertions(+), 480 deletions(-) delete mode 100644 server/browser/serve_js.go delete mode 100644 src/apps/cms.star delete mode 100644 src/sw.js diff --git a/Makefile b/Makefile index 115d47ec19..2f6ae1cd82 100644 --- a/Makefile +++ b/Makefile @@ -10,7 +10,7 @@ else TAGS = endif -all: build wasm +all: build test: go test $(TAGS) -v -cover ./... @@ -50,10 +50,4 @@ lint: @ buildifier --version >/dev/null 2>&1 || $(MAKE) install-buildifier buildifier -r ./ -format: lint - -wasm: - GOOS=js GOARCH=wasm go build -trimpath -ldflags="-s -w" -o ./src/pixlet.wasm tidbyt.dev/pixlet - mkdir -p ./src/go - cp -f $(shell go env GOROOT)/misc/wasm/wasm_exec.js ./src/go/wasm_exec.js - cp -f $(shell go list -m -f '{{.Dir}}' github.com/nlepage/go-wasm-http-server)/sw.js ./src/go/sw.js \ No newline at end of file +format: lint \ No newline at end of file diff --git a/go.mod b/go.mod index 228bc50f82..d3c574cd5a 100644 --- a/go.mod +++ b/go.mod @@ -26,7 +26,6 @@ require ( github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 github.com/nirasan/go-oauth-pkce-code-verifier v0.0.0-20220510032225-4f9f17eaec4c github.com/nlepage/go-tarfs v1.2.1 - github.com/nlepage/go-wasm-http-server v1.1.0 github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c github.com/qri-io/starlib v0.5.1-0.20220611014110-7fb7ff9ec804 github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e @@ -80,7 +79,6 @@ require ( github.com/mattn/go-isatty v0.0.20 // indirect github.com/mattn/go-runewidth v0.0.13 // indirect github.com/mitchellh/mapstructure v1.5.0 // indirect - github.com/nlepage/go-js-promise v1.0.0 // indirect github.com/pelletier/go-toml/v2 v2.1.0 // indirect github.com/pjbgf/sha1cd v0.3.0 // indirect github.com/pkg/errors v0.9.1 // indirect diff --git a/go.sum b/go.sum index 86b6fb1b2f..cca08bd37d 100644 --- a/go.sum +++ b/go.sum @@ -230,12 +230,8 @@ github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646/go.mod h1:jpp1/29i3P1S github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= github.com/nirasan/go-oauth-pkce-code-verifier v0.0.0-20220510032225-4f9f17eaec4c h1:4RYnE0ISVwRxm9Dfo7utw1dh0kdRDEmVYq2MFVLy5zI= github.com/nirasan/go-oauth-pkce-code-verifier v0.0.0-20220510032225-4f9f17eaec4c/go.mod h1:DvuJJ/w1Y59rG8UTDxsMk5U+UJXJwuvUgbiJSm9yhX8= -github.com/nlepage/go-js-promise v1.0.0 h1:K7OmJ3+0BgWJ2LfXchg2sI6RDr7AW/KWR8182epFwGQ= -github.com/nlepage/go-js-promise v1.0.0/go.mod h1:bdOP0wObXu34euibyK39K1hoBCtlgTKXGc56AGflaRo= github.com/nlepage/go-tarfs v1.2.1 h1:o37+JPA+ajllGKSPfy5+YpsNHDjZnAoyfvf5GsUa+Ks= github.com/nlepage/go-tarfs v1.2.1/go.mod h1:rno18mpMy9aEH1IiJVftFsqPyIpwqSUiAOpJYjlV2NA= -github.com/nlepage/go-wasm-http-server v1.1.0 h1:phw2NtSp71m/6NmGjE2veQ41PBPzWFcnE614cKucy5M= -github.com/nlepage/go-wasm-http-server v1.1.0/go.mod h1:xpffUeN97vuv8CTlMJ2oC5tPsftfPoG9HkAgI9gkiPI= github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U= github.com/onsi/gomega v1.27.10 h1:naR28SdDFlqrG6kScpT8VWpu1xWY5nJRCF3XaYyBjhI= github.com/onsi/gomega v1.27.10/go.mod h1:RsS8tutOdbdgzbPtzzATp12yT7kM5I5aElG3evPbQ0M= diff --git a/package.json b/package.json index 58ab54e08a..f015226b3e 100644 --- a/package.json +++ b/package.json @@ -9,9 +9,7 @@ }, "scripts": { "start": "webpack serve --config webpack.dev.js", - "start:wasm": "make wasm && PIXLET_BACKEND=wasm webpack serve --config webpack.dev.js", "build": "webpack --config webpack.prod.js", - "build:wasm": "make wasm && PIXLET_BACKEND=wasm webpack --config webpack.prod.js", "clean": "rm -rf dist/static/ && git restore dist/", "test": "echo \"Error: no test specified\" && exit 1" }, @@ -71,4 +69,4 @@ "react-router-dom": "6.23.0", "react-simple-oauth2-login": "0.5.4" } -} +} \ No newline at end of file diff --git a/server/browser/serve_js.go b/server/browser/serve_js.go deleted file mode 100644 index 61ae2350f5..0000000000 --- a/server/browser/serve_js.go +++ /dev/null @@ -1,14 +0,0 @@ -//go:build js && wasm - -package browser - -import ( - wasmhttp "github.com/nlepage/go-wasm-http-server" - "log" -) - -func (b *Browser) serveHTTP() error { - log.Printf("listening via wasmhttp") - wasmhttp.Serve(b.r) - return nil -} diff --git a/src/Main.jsx b/src/Main.jsx index f016507af1..efe7f2834b 100644 --- a/src/Main.jsx +++ b/src/Main.jsx @@ -25,42 +25,6 @@ export default function Main() { size = 8; } - function iOS() { - return [ - 'iPad Simulator', - 'iPhone Simulator', - 'iPod Simulator', - 'iPad', - 'iPhone', - 'iPod' - ].includes(navigator.platform) - }; - - if (PIXLET_WASM && iOS()) { - return ( - - - - - - - - Sorry, iOS is not supported. - - - - - Please try again on a desktop browser. - - - - - - - ); - } - - return ( diff --git a/src/apps/cms.star b/src/apps/cms.star deleted file mode 100644 index 38b447c9af..0000000000 --- a/src/apps/cms.star +++ /dev/null @@ -1,273 +0,0 @@ -""" -Applet: CMS -Summary: CMS Backend -Description: An app that supports creating a CMS display. -Author: Tidbyt -""" - -load("encoding/base64.star", "base64") -load("render.star", "render") -load("schema.star", "schema") - -DEFAULT_DISPLAY_TYPE = "horizontal" - -DEFAULT_BACKGROUND_COLOR = "#000000" - -DEFAULT_HEADING = "Example" -DEFAULT_HEADING_COLOR = "#7AB0FF" -DEFAULT_HIDE_HEADING = False - -DEFAULT_BODY = "Example body text that is a bit longer than the heading text." -DEFAULT_BODY_COLOR = "#FFFFFF" -DEFAULT_HIDE_BODY = False - -DEFAULT_HIDE_LOGO = False -DEFAULT_LOGO = """ -iVBORw0KGgoAAAANSUhEUgAAABAAAAASCAYAAABSO15qAAAACXBIWXMAAC4jAAAuIwF4pT92AAABFklE -QVQ4jZXTzU7CQBQF4K+kLBCRRCNCqkRf06fyPfxjQ2JcGk1cqRElYaF10ZlQYGjwJE2nt+eeOXPn3uzy -qtSAz/A+2EbIt8Q76KMXvgu8Y75ObCWSj/AQnogpHjFoEshwjAnGwUFEP7iY4CRwNwRK3OA04SpihNvA -XRHIgvK4ITmiCEJZXaCD67pyA8rA7bK8hRbOdkiObou4eXRQ4mNHAar+KOsC33azH1FiVhc4lu6JbWhh -GBcD3Gto1wT2cYdhjme0/5FMVcgRnnL8YIHf8LPEm82aZDi07MIM7Vx1/myN3EvEWE5nRJnjK0GcBkfR -RaY6ZrFOTI1zVzWRe2vxharQKy5SVzfHBV5Udz3DK87DegV/vJUy/l4a2gQAAAAASUVORK5CYII= -""" - -def main(config): - display_type = config.str("display_type", DEFAULT_DISPLAY_TYPE) - - if display_type == "horizontal": - return render_horizontal(config) - - return render_vertical(config) - -def render_horizontal(config): - background_color = config.str("background_color", DEFAULT_BACKGROUND_COLOR) - - heading = config.str("heading", DEFAULT_HEADING) - heading_color = config.str("heading_color", DEFAULT_HEADING_COLOR) - hide_heading = config.bool("hide_heading", DEFAULT_HIDE_HEADING) - - body = config.str("body", DEFAULT_BODY) - body_color = config.str("body_color", DEFAULT_BODY_COLOR) - hide_body = config.bool("hide_body", DEFAULT_HIDE_BODY) - - logo = config.str("logo", DEFAULT_LOGO) - hide_logo = config.bool("hide_logo", DEFAULT_HIDE_LOGO) - - row_one = [] - if not hide_logo: - row_one.append( - render.Image( - src = base64.decode(logo), - ), - ) - - if not hide_heading: - row_one.append( - render.Text( - content = heading, - color = heading_color, - ), - ) - - column_one = [] - if len(row_one) != 0: - column_one.append( - render.Row( - expanded = True, - main_align = "space_evenly", - cross_align = "center", - children = row_one, - ), - ) - - if not hide_body: - column_one.append( - render.Marquee( - width = 60, - child = render.Text( - content = body, - color = body_color, - ), - ), - ) - - if len(column_one) == 0: - return [] - - return render.Root( - show_full_animation = True, - child = render.Box( - padding = 2, - color = background_color, - child = render.Column( - expanded = True, - main_align = "space_around", - cross_align = "center", - children = column_one, - ), - ), - ) - -def render_vertical(config): - background_color = config.str("background_color", DEFAULT_BACKGROUND_COLOR) - - heading = config.str("heading", DEFAULT_HEADING) - heading_color = config.str("heading_color", DEFAULT_HEADING_COLOR) - hide_heading = config.bool("hide_heading", DEFAULT_HIDE_HEADING) - - body = config.str("body", DEFAULT_BODY) - body_color = config.str("body_color", DEFAULT_BODY_COLOR) - hide_body = config.bool("hide_body", DEFAULT_HIDE_BODY) - - logo = config.str("logo", DEFAULT_LOGO) - hide_logo = config.bool("hide_logo", DEFAULT_HIDE_LOGO) - - children = [] - if not hide_logo: - children.append( - render.Row( - cross_align = "center", - main_align = "space_around", - expanded = True, - children = [ - render.Image( - src = base64.decode(logo), - ), - ], - ), - ) - children.append(render.Box(height = 4)) - - if not hide_heading: - children.append( - render.Row( - cross_align = "center", - main_align = "space_around", - expanded = True, - children = [ - render.Text( - content = heading, - color = heading_color, - ), - ], - ), - ) - children.append(render.Box(height = 4)) - - if not hide_body: - children.append( - render.WrappedText(content = body, color = body_color), - ) - children.append(render.Box(height = 10, width = 1)) - - if len(children) == 0: - return [] - - return render.Root( - show_full_animation = True, - delay = 60, - child = render.Box( - color = background_color, - child = render.Marquee( - height = 32, - offset_start = 16, - offset_end = 32, - scroll_direction = "vertical", - child = render.Padding( - pad = 1, - child = render.Column( - main_align = "start", - children = children, - ), - ), - ), - ), - ) - -def get_schema(): - options = [ - schema.Option( - display = "Horizontal Scroll", - value = DEFAULT_DISPLAY_TYPE, - ), - schema.Option( - display = "Vertical Scroll", - value = "vertical", - ), - ] - - return schema.Schema( - version = "1", - fields = [ - schema.Dropdown( - id = "display_type", - name = "Display Type", - desc = "The type of display to use.", - icon = "display", - default = DEFAULT_DISPLAY_TYPE, - options = options, - ), - schema.Color( - id = "background_color", - name = "Background Color", - desc = "Background color for the display.", - icon = "brush", - default = DEFAULT_BACKGROUND_COLOR, - ), - schema.Text( - id = "heading", - name = "Heading Text", - desc = "The heading text to display", - icon = "textHeight", - default = DEFAULT_HEADING, - ), - schema.Color( - id = "heading_color", - name = "Heading Color", - desc = "Heading text color.", - icon = "brush", - default = DEFAULT_HEADING_COLOR, - ), - schema.Toggle( - id = "hide_heading", - name = "Hide Heading", - desc = "A toggle to hide the heading text.", - icon = "eyeSlash", - default = DEFAULT_HIDE_HEADING, - ), - schema.Text( - id = "body", - name = "Body Text", - desc = "The body text to display", - icon = "textHeight", - default = DEFAULT_BODY, - ), - schema.Color( - id = "body_color", - name = "Body Color", - desc = "Body text color.", - icon = "brush", - default = DEFAULT_BODY_COLOR, - ), - schema.Toggle( - id = "hide_body", - name = "Hide Body", - desc = "A toggle to hide the body text.", - icon = "eyeSlash", - default = DEFAULT_HIDE_BODY, - ), - schema.PhotoSelect( - id = "logo", - name = "Logo", - desc = "A logo to display.", - icon = "photoFilm", - ), - schema.Toggle( - id = "hide_logo", - name = "Hide Logo", - desc = "A toggle to hide the logo.", - icon = "eyeSlash", - default = DEFAULT_HIDE_LOGO, - ), - ], - ) diff --git a/src/features/controls/Controls.jsx b/src/features/controls/Controls.jsx index 8a9a0749e4..65ed4e3d8f 100644 --- a/src/features/controls/Controls.jsx +++ b/src/features/controls/Controls.jsx @@ -12,7 +12,7 @@ export default function Controls() { const dispatch = useDispatch(); let imageType = 'webp'; - if (PIXLET_WASM || preview.value.img_type === "gif") { + if (preview.value.img_type === "gif") { imageType = 'gif'; } diff --git a/src/features/preview/Preview.jsx b/src/features/preview/Preview.jsx index 2c44ac5b30..7b83798b7b 100644 --- a/src/features/preview/Preview.jsx +++ b/src/features/preview/Preview.jsx @@ -60,7 +60,7 @@ export default function Preview() { const preview = useSelector(state => state.preview); let displayType = 'data:image/webp;base64,'; - if (PIXLET_WASM || preview.value.img_type === "gif") { + if (preview.value.img_type === "gif") { displayType = 'data:image/gif;base64,'; } @@ -70,9 +70,6 @@ export default function Preview() { } let content = - if (preview.loading && PIXLET_WASM) { - content = - } return ( {content} diff --git a/src/features/preview/actions.js b/src/features/preview/actions.js index 80e9b3707c..f03d9acc61 100644 --- a/src/features/preview/actions.js +++ b/src/features/preview/actions.js @@ -16,52 +16,24 @@ export default function fetchPreview(formData) { }, }); - if (PIXLET_WASM) { - store.dispatch(loading(true)); - clearTimeout(timeout); - timeout = setTimeout(function () { - client.post(`${PIXLET_API_BASE}/api/v1/preview`, formData) - .then(res => { - store.dispatch(update(res.data)); - if ('error' in res.data) { - store.dispatch(setError({ id: res.data.error, message: res.data.error })); - } else { - store.dispatch(clearErrors()); - } - }) - .catch(err => { - if (err.response.status == 404) { - store.dispatch(setError({ id: err, message: "error with pixlet, please refresh page" })); - return; - } - store.dispatch(setError({ id: err, message: err })); - }) - .then(() => { - store.dispatch(loading(false)); - }) - }, 300); - - } else { - client.post(`${PIXLET_API_BASE}/api/v1/preview`, formData) - .then(res => { - document.title = res.data.title; - store.dispatch(update(res.data)); - if ('error' in res.data) { - store.dispatch(setError({ id: res.data.error, message: res.data.error })); - } else { - store.dispatch(clearErrors()); - } - }) - .catch(err => { - if (err.response.status == 404) { - store.dispatch(setError({ id: err, message: "error with pixlet, please refresh page" })); - return; - } - store.dispatch(setError({ id: err, message: err })); - }) - .then(() => { - store.dispatch(loading(false)); - }) - - } + client.post(`${PIXLET_API_BASE}/api/v1/preview`, formData) + .then(res => { + document.title = res.data.title; + store.dispatch(update(res.data)); + if ('error' in res.data) { + store.dispatch(setError({ id: res.data.error, message: res.data.error })); + } else { + store.dispatch(clearErrors()); + } + }) + .catch(err => { + if (err.response.status == 404) { + store.dispatch(setError({ id: err, message: "error with pixlet, please refresh page" })); + return; + } + store.dispatch(setError({ id: err, message: err })); + }) + .then(() => { + store.dispatch(loading(false)); + }) } \ No newline at end of file diff --git a/src/features/schema/FieldDetails.jsx b/src/features/schema/FieldDetails.jsx index 16650676a0..493094b426 100644 --- a/src/features/schema/FieldDetails.jsx +++ b/src/features/schema/FieldDetails.jsx @@ -27,9 +27,6 @@ export default function FieldDetails({ field }) { case 'oauth2': return case 'png': - if (PIXLET_WASM) { - return - } return case 'text': return diff --git a/src/features/schema/fields/TextInput.jsx b/src/features/schema/fields/TextInput.jsx index 286bfaa521..0c2376cf2e 100644 --- a/src/features/schema/fields/TextInput.jsx +++ b/src/features/schema/fields/TextInput.jsx @@ -45,14 +45,7 @@ export default function TextInput({ field }) { const onChange = (event) => { setValue(event.target.value); - if (PIXLET_WASM) { - dispatch(set({ - id: field.id, - value: event.target.value, - })); - } else { - debounceConfig(event); - } + debounceConfig(event); } const debounceConfig = useCallback( diff --git a/src/features/watcher/WatcherManager.jsx b/src/features/watcher/WatcherManager.jsx index da323d1db4..d4c13a70a3 100644 --- a/src/features/watcher/WatcherManager.jsx +++ b/src/features/watcher/WatcherManager.jsx @@ -4,11 +4,6 @@ import Watcher from './watcher'; export default function WatcherManager() { - if (PIXLET_WASM) { - // watcher isn't supported in the browser - return null; - } - useEffect(() => { new Watcher(); }, []); diff --git a/src/index.js b/src/index.js index 1da68cd559..a4ebf27a26 100644 --- a/src/index.js +++ b/src/index.js @@ -23,22 +23,4 @@ const App = () => { ) } -if (PIXLET_WASM && 'serviceWorker' in navigator) { - window.addEventListener('load', function () { - navigator.serviceWorker.getRegistrations().then(function (registrations) { - for (let registration of registrations) { - registration.unregister(); - } - navigator.serviceWorker.register(new URL('./sw.js', import.meta.url), { scope: "/" }).then(function (registration) { - // Registration was successful - console.log('ServiceWorker registration successful with scope: ', registration.scope); - ReactDOM.render(, document.getElementById('app')); - }, function (err) { - // registration failed :( - console.log('ServiceWorker registration failed: ', err); - }); - }); - }); -} else { - ReactDOM.render(, document.getElementById('app')); -} \ No newline at end of file +ReactDOM.render(, document.getElementById('app')); \ No newline at end of file diff --git a/src/sw.js b/src/sw.js deleted file mode 100644 index 0d67646e49..0000000000 --- a/src/sw.js +++ /dev/null @@ -1,22 +0,0 @@ -import cmsStarlark from './apps/cms.star'; - -importScripts(new URL('./go/wasm_exec.js', import.meta.url)); -importScripts(new URL('./go/sw.js', import.meta.url)); - -registerWasmHTTPListener( - new URL('./pixlet.wasm', import.meta.url), - { - 'base': 'pixlet', - 'args': ['serve', cmsStarlark], - } -); - -// Skip installed stage and jump to activating stage -addEventListener('install', (event) => { - event.waitUntil(skipWaiting()) -}); - -// Start controlling clients as soon as the SW is activated -addEventListener('activate', event => { - event.waitUntil(clients.claim()) -}); \ No newline at end of file diff --git a/webpack.dev.js b/webpack.dev.js index 5de5bae897..dcbfec94be 100644 --- a/webpack.dev.js +++ b/webpack.dev.js @@ -18,21 +18,11 @@ const copyPlugin = new CopyWebpackPlugin({ }); let plugins = [htmlPlugin, copyPlugin]; -if (process.env.PIXLET_BACKEND === "wasm") { - plugins.push( - new webpack.DefinePlugin({ - 'PIXLET_WASM': JSON.stringify(true), - 'PIXLET_API_BASE': JSON.stringify('pixlet'), - }) - ); -} else { - plugins.push( - new webpack.DefinePlugin({ - 'PIXLET_WASM': JSON.stringify(false), - 'PIXLET_API_BASE': JSON.stringify(''), - }) - ); -} +plugins.push( + new webpack.DefinePlugin({ + 'PIXLET_API_BASE': JSON.stringify(''), + }) +); module.exports = merge(common, { mode: 'development', diff --git a/webpack.prod.js b/webpack.prod.js index b001e9b4e0..e21663aac6 100644 --- a/webpack.prod.js +++ b/webpack.prod.js @@ -19,21 +19,11 @@ const copyPlugin = new CopyWebpackPlugin({ let plugins = [htmlPlugin, copyPlugin]; -if (process.env.PIXLET_BACKEND === "wasm") { - plugins.push( - new webpack.DefinePlugin({ - 'PIXLET_WASM': JSON.stringify(true), - 'PIXLET_API_BASE': JSON.stringify('pixlet'), - }) - ); -} else { - plugins.push( - new webpack.DefinePlugin({ - 'PIXLET_WASM': JSON.stringify(false), - 'PIXLET_API_BASE': JSON.stringify(''), - }) - ); -} +plugins.push( + new webpack.DefinePlugin({ + 'PIXLET_API_BASE': JSON.stringify(''), + }) +); module.exports = merge(common, { mode: 'production',