{"id":18415806,"url":"https://github.com/equanox/gotron","last_synced_at":"2025-04-13T02:23:24.021Z","repository":{"id":57487364,"uuid":"86814802","full_name":"Equanox/gotron","owner":"Equanox","description":"Go Api for Electron","archived":false,"fork":false,"pushed_at":"2021-03-08T09:42:25.000Z","size":5377,"stargazers_count":786,"open_issues_count":22,"forks_count":63,"subscribers_count":42,"default_branch":"master","last_synced_at":"2025-04-04T04:12:45.284Z","etag":null,"topics":["electron","golang","gui"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Equanox.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-03-31T12:05:44.000Z","updated_at":"2024-12-05T05:55:50.000Z","dependencies_parsed_at":"2022-09-01T23:02:30.258Z","dependency_job_id":null,"html_url":"https://github.com/Equanox/gotron","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Equanox%2Fgotron","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Equanox%2Fgotron/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Equanox%2Fgotron/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Equanox%2Fgotron/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Equanox","download_url":"https://codeload.github.com/Equanox/gotron/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248655016,"owners_count":21140411,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["electron","golang","gui"],"created_at":"2024-11-06T03:55:53.780Z","updated_at":"2025-04-13T02:23:23.997Z","avatar_url":"https://github.com/Equanox.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://travis-ci.org/Equanox/gotron.svg?branch=master)](https://travis-ci.org/Equanox/gotron)\n\n# Gotron\nGo Api for Electron.\n\n### ⚠️  **[This project is no longer maintained.](https://github.com/pxgrid/aigis/issues/121)** ⚠️\nFeel free to fork and make your own changes if needed.\n\n## Example Projects\nA list of boilerplate projects using gotron.\n\n* https://github.com/Marlon-Monroy/gotron-react-boilerplate\n\n## Prerequisites\n**go1.11** with modules enabled, **nodejs** and **npm** must be available on your system.\n\n## Quick Start\nOn the first run it will download Electron and stores it in *.gotron* in your working directory.\n\n```go\npackage main\n\nimport (\n    \"github.com/Equanox/gotron\"\n)\n\nfunc main() {\n    // Create a new browser window instance\n    window, err := gotron.New()\n    if err != nil {\n        panic(err)\n    }\n\n    // Alter default window size and window title.\n    window.WindowOptions.Width = 1200\n    window.WindowOptions.Height = 980\n    window.WindowOptions.Title = \"Gotron\"\n\n    // Start the browser window.\n    // This will establish a golang \u003c=\u003e nodejs bridge using websockets,\n    // to control ElectronBrowserWindow with our window object.\n    done, err := window.Start()\n    if err != nil {\n        panic(err)\n    }\n    \n    // Open dev tools must be used after window.Start \n    // window.OpenDevTools()\n    \n    // Wait for the application to close\n    \u003c-done\n}\n```     \n\nWhen everything worked you should see this\n\n\u003cimg src=\"doc/hello_gotron.png\" alt=\"Hello Gotron\" width=\"400px\"/\u003e\n\n\n### Use Your Own WebUI\ngotron expects a folder containing your HTML/JS/CSS code and passes it to electronJS. make sure it contains at least a index.html as entrypoint.\n\nPass a path to your webUI on gotrons `New(uiFolder ...string)` function.\n```go\nwindow, err := gotron.New(\"path/to/your/webui\")\nif err != nil {\n    panic(err)\n}\n```\n\n### Communicate between backend and frontend\n\nFrontend to backend communication is realized through javascript like event driven apporach.\n\n#### Backend\n\nHandle incoming events\n```go\nwindow.On(\u0026gotron.Event{Event: \"event-name\"}, func(bin []byte) {\n\t//Handle event here\n}\n```\n\nSend event to frontend\n```go\n// Create a custom event struct that has a pointer to gotron.Event\ntype CustomEvent struct {\n    *gotron.Event\n    CustomAttribute string 'json:\"AtrNameInFrontend\"'\n}\n\nwindow.Send(\u0026CustomEvent{\n    Event: \u0026gotron.Event{Event: \"event-name\"},\n    CustomAttribute: \"Hello World!\",\n    })\n```\n\n#### Frontend\n\nIn frontend a websocket needs to be created. Adress is always localhost and port can be taken from global variable `global.backendPort`\n```javascript\nlet ws = new WebSocket(\"ws://localhost:\" + global.backendPort + \"/web/app/events\");\n```\n\nHandle incoming events\n```javascript\n// This is being called for all incoming messages\nws.onmessage = (message) =\u003e {\n    let obj = JSON.parse(message.data);\n    \n    // event name\n    console.log(obj.event);\n\n    // event data\n    console.log(obj.AtrNameInFrontend);\n}\n```\n\nSend event to backend\n\n```javascript\nws.send(JSON.stringify({\n    \"event\": \"event-name\",\n    \"AtrNameInFrontend\": \"Hello World!\",\n}))\n```\n\n## Distribution/Packaging\nTo package a go application together with electornjs use `gotron-builder`.    \n\n#### Install gotron-builder\nWe provide executables for Linux, MacOS and Windows.    \nDownload the newest release from [https://github.com/Equanox/gotron/releases](https://github.com/Equanox/gotron/releases) and add it to your $PATH.\n\n#### Using  gotron-builder\nIt expects...\n* a directory containing a golang main package \n* and a directory with a webUI containing at least a index.html\n\nBy default it will implicitly use...\n* golang main package from the current directory\n* webUI from *.gotron/assets*\n\nTo pack the code from **Quick Start** use\n```sh\ngotron-builder\n```\nin the root of your repo.\n\nPass your go code and webUI explicitly.\n```sh\ngotron-builder --go=your/go/dir --app=your/webapp/dir\n```\n\nFor cross compilation you can use the same flags as electron-builder would expect them\n```\ngotron-builder --win \n```\nRead about the requirements for cross-compilation in [electron-builders](https://github.com/electron-userland/electron-builder) documentation.\n\n## Tasks\n- [x] Basic js + webpack example\n- [x] React example\n- [x] Typescript-React example\n- [x] Vue.js example\n- [ ] Elm example\n- [ ] Flutter Hummingbird example\n- [X] Hide nodejs/Electron behind go api\n- [X] Create executables for Win, Linux, MacOS\n- [X] Hide nodejs/Electron behind go api\n- [ ] Msgs between golang and Electron renderer process,\n      abstracted in a javascript/typescript package\n- [ ] Implement complete BrowserWindow api see =\u003e [BrowserWindow.md](BrowserWindow.md)\n- [ ] Implement complete electron-builder api in gotron-builder\n\n## Sponsors\n\u003ca href=\"https://benchkram.de\"\u003e\u003cimg src=\"https://raw.githubusercontent.com/equanox/gotron/master/doc/benchkram.png\" alt=\"benchkram-logo\" width=\"50\"/\u003e\u003c/a\u003e\n\n# License\nMIT  \n\nExcept Roboto (ui/js/src/Roboto-Light.ttf , ui/react/src/Roboto-Light.ttf) which is licensed under Apache 2.0   \nhttps://github.com/google/roboto\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fequanox%2Fgotron","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fequanox%2Fgotron","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fequanox%2Fgotron/lists"}