From 975b6333cf77d49c4d21aa28aee095887c8de79f Mon Sep 17 00:00:00 2001 From: REDDY PRASAD Date: Wed, 3 Feb 2021 19:29:48 +0530 Subject: [PATCH] =?UTF-8?q?=F0=9F=92=85=F0=9F=8F=BC=20Check=20for=20update?= =?UTF-8?q?s=20feature=20(#10)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/release.yml | 6 +- .github/workflows/test.yml | 6 +- NOTES.md | 4 + README.md | 6 +- frontend/src/App.js | 140 ++++++++++++++----------------- frontend/src/App.scss | 19 +---- frontend/src/Footer.jsx | 45 ++++++++++ frontend/src/Footer.scss | 31 +++++++ frontend/src/GameList.scss | 8 +- frontend/src/translation/en.json | 3 +- frontend/src/translation/ru.json | 3 +- go.mod | 1 + main.go | 52 +++++++++++- 13 files changed, 218 insertions(+), 106 deletions(-) create mode 100644 frontend/src/Footer.jsx create mode 100644 frontend/src/Footer.scss diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index e6451cf..a97b4ed 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -44,6 +44,10 @@ jobs: if: ${{ matrix.os == 'ubuntu-20.04' }} - name: Checkout code uses: actions/checkout@v2 + - name: Vars + id: vars + run: echo ::set-output name=tag::${GITHUB_REF/refs\/tags\//} + shell: bash - name: Install Project Dep run: | go mod download @@ -66,7 +70,7 @@ jobs: - name: Setup Account run: mkdir -p ~/.wails && echo '{"email":"dev.drprasad@aim.com","name":"REDDY PRASAD"}' > ~/.wails/wails.json - name: Build GUI - run: wails build -p + run: wails build -p -ldflags "-X main.CurrentVersionStr=${{ steps.vars.outputs.tag }}" - name: Make DMG run: npx create-dmg ./build/hsk00.app ./build continue-on-error: true diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ad8cc93..11c3d2f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -27,6 +27,10 @@ jobs: if: ${{ matrix.os == 'ubuntu-20.04' }} - name: Checkout code uses: actions/checkout@v2 + - name: Vars + id: vars + run: echo ::set-output name=tag::${GITHUB_REF/refs\/tags\//} + shell: bash - name: Install Project Dep run: | go mod download @@ -49,7 +53,7 @@ jobs: - name: Setup Account run: mkdir -p ~/.wails && echo '{"email":"dev.drprasad@aim.com","name":"REDDY PRASAD"}' > ~/.wails/wails.json - name: Build GUI - run: wails build -p + run: wails build -p -ldflags "-X main.CurrentVersionStr=${{ steps.vars.outputs.tag }}" - name: Make DMG run: npx create-dmg ./build/hsk00.app ./build continue-on-error: true diff --git a/NOTES.md b/NOTES.md index efaf752..0213669 100644 --- a/NOTES.md +++ b/NOTES.md @@ -32,3 +32,7 @@ - online-convert.com - https://hackmii.com/2010/04/sunplus-the-biggest-chip-company-youve-never-heard-of/ - https://www.dl-sounds.com/royalty-free + +### DUMPS + +- https://yadi.sk/d/rTNU4YlXHUIRyg diff --git a/README.md b/README.md index 00c9bf4..cfd970d 100644 --- a/README.md +++ b/README.md @@ -14,9 +14,9 @@ Add/Replace games to your "Data Frog Y2 (568 in 1)" console. There is no install step. You just download and run. -- [Mac OS X GUI](https://github.com/dev-drprasad/hsk00/releases/download/latest/hsk00-osx.dmg) -- [Windows GUI](https://github.com/dev-drprasad/hsk00/releases/download/latest/hsk00-windows.exe) (require windows7 SP1 or later) -- [Linux GUI](https://github.com/dev-drprasad/hsk00/releases/download/latest/hsk00-linux-gui.tar.gz) (Should work with all popular distros) +- [Mac OS X GUI](https://github.com/dev-drprasad/hsk00/releases/latest/download/hsk00-osx.dmg) +- [Windows GUI](https://github.com/dev-drprasad/hsk00/releases/latest/download/hsk00-windows.exe) (require windows7 SP1 or later) +- [Linux GUI](https://github.com/dev-drprasad/hsk00/releases/latest/download/hsk00-linux-gui.tar.gz) (Should work with all popular distros) ### Can't launch ? diff --git a/frontend/src/App.js b/frontend/src/App.js index 95c372f..6579a28 100644 --- a/frontend/src/App.js +++ b/frontend/src/App.js @@ -1,10 +1,11 @@ import React, { useCallback, useEffect, useState } from "react"; import "./App.scss"; import Alert from "./Alert"; -import GitHubIcon from "./GitHubIcon"; import { ReactComponent as Spinner } from "./spinner.svg"; import { useTranslation } from "react-i18next"; +import Footer from "./Footer"; import GameList from "./GameList"; + const initialState = { rootDir: "", modified: false, @@ -81,10 +82,6 @@ function App() { .catch(setError); }, [rootDir, categoryID]); - const handleGHClick = () => { - window.backend.Runtime.OpenURL("https://github.com/dev-drprasad/hsk00/"); - }; - const handleGameToggleDelete = (id) => () => { const g = { ...games[id], deleted: !games[id].deleted }; if (g.hsk) { @@ -156,82 +153,75 @@ function App() { ].map((c, i) => ({ label: `${t("Category")} ${i + 1} (${c})`, value: i })); return ( - -
-
-
- {t("Choose root directory")} : -
-
- - -
- {errors.rootDir} +
+
+
+ {t("Choose root directory")} : +
+
+ +
-
-
- {t("Select game category")} : -
-
- -
- {errors.rootDir} + {errors.rootDir} +
+
+
+ {t("Select game category")} :
-
- -
- - -
- - {errors.rootDir} +
+
- -
-
+
+ +
+ +
+ + {errors.rootDir}
- - - - - + +
+ +
+ +
i18n.changeLanguage(l)} /> +
); } diff --git a/frontend/src/App.scss b/frontend/src/App.scss index bcb0bfb..2400e61 100644 --- a/frontend/src/App.scss +++ b/frontend/src/App.scss @@ -1,16 +1,8 @@ @import "variables.scss"; -.github-link { - position: absolute; - bottom: 0.5rem; - right: 1rem; - font-size: 1.2rem; - color: #cccccc; -} - .App { padding: 0.5rem 1rem; - height: 100%; + height: 100vh; position: relative; } .group > :first-child { @@ -172,12 +164,3 @@ border-radius: 0.5em; outline: none; } - -.language-select { - position: absolute; - bottom: 0.5rem; - left: 1rem; - - width: 20%; - color: #cccccc; -} diff --git a/frontend/src/Footer.jsx b/frontend/src/Footer.jsx new file mode 100644 index 0000000..b45f5ef --- /dev/null +++ b/frontend/src/Footer.jsx @@ -0,0 +1,45 @@ +import React, { useEffect, useState } from "react"; +import { useTranslation } from "react-i18next"; +import GitHubIcon from "./GitHubIcon"; +import "./Footer.scss"; + +function Footer({ onLangChange }) { + const { t } = useTranslation("translation"); + const [version, setVersion] = useState({ current: undefined, latest: undefined, hasUpdate: false }); + + const handleUpdateClick = (e) => { + e.preventDefault(); + window.backend.Runtime.OpenURL("https://github.com/dev-drprasad/hsk00/releases/latest"); + }; + + const handleGHClick = () => { + window.backend.Runtime.OpenURL("https://github.com/dev-drprasad/hsk00/"); + }; + + useEffect(() => { + window.backend.Runtime.GetVersion().then(setVersion).catch(console.error); + }, []); + + return ( + <> + + + + {version.current}{" "} + {version.hasUpdate && ( + + ({"🎉"} {t("update available")} : {version.latest}) + + )} + + + + + + ); +} + +export default Footer; diff --git a/frontend/src/Footer.scss b/frontend/src/Footer.scss new file mode 100644 index 0000000..e6967e4 --- /dev/null +++ b/frontend/src/Footer.scss @@ -0,0 +1,31 @@ +@import "variables.scss"; + +.language-select { + bottom: 0.5rem; + left: 1rem; + width: 20%; + color: #cccccc; + position: absolute; +} + +.version { + position: absolute; + bottom: 0.5rem; + width: 100%; + text-align: center; + line-height: 1.3rem; + font-size: 0.85em; + z-index: -1; + + > a { + color: inherit; + } +} + +.github-link { + position: absolute; + bottom: 0.5rem; + right: 1rem; + font-size: 1.2rem; + color: #cccccc; +} diff --git a/frontend/src/GameList.scss b/frontend/src/GameList.scss index c49ef24..f9e31e8 100644 --- a/frontend/src/GameList.scss +++ b/frontend/src/GameList.scss @@ -7,14 +7,12 @@ > ul { margin: 0; overflow: auto; - height: 14.4rem; + height: 14rem; // 7 items * height of li > li { - list-style: none; padding: 0 1rem; - height: 2.4rem; - line-height: 2.4rem; + height: 2rem; + line-height: 2rem; position: relative; - z-index: 10000; &.unsaved { font-weight: 700; diff --git a/frontend/src/translation/en.json b/frontend/src/translation/en.json index c9cf808..64466a7 100644 --- a/frontend/src/translation/en.json +++ b/frontend/src/translation/en.json @@ -16,5 +16,6 @@ "Fight Game": "Fight Game", "Racing Game": "Racing Game", "Puzzle Game": "Puzzle Game", - "unsaved": "unsaved" + "unsaved": "unsaved", + "update available": "update available" } diff --git a/frontend/src/translation/ru.json b/frontend/src/translation/ru.json index e10ff2b..3e284e1 100644 --- a/frontend/src/translation/ru.json +++ b/frontend/src/translation/ru.json @@ -17,5 +17,6 @@ "Racing Game": "Racing Game", "Puzzle Game": "Puzzle Game", "unsaved": "неспасенный", - "Category": "Категория" + "Category": "Категория", + "update available": "обновления доступны" } diff --git a/go.mod b/go.mod index 3f9a27b..1636ef5 100644 --- a/go.mod +++ b/go.mod @@ -3,6 +3,7 @@ module github.com/dev-drprasad/hsk00 go 1.15 require ( + github.com/Masterminds/semver v1.4.2 github.com/dev-drprasad/qt v1.0.4 github.com/fogleman/gg v1.3.0 github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 diff --git a/main.go b/main.go index 5eddc52..0b287db 100644 --- a/main.go +++ b/main.go @@ -1,11 +1,14 @@ package main import ( + "encoding/json" "fmt" "log" + "net/http" "path/filepath" "runtime" + "github.com/Masterminds/semver" "github.com/dev-drprasad/hsk00/pkg" "github.com/leaanthony/mewn" "github.com/ncruces/zenity" @@ -13,6 +16,9 @@ import ( "github.com/wailsapp/wails" ) +// CurrentVersionStr will be assigned using -ldflags +var CurrentVersionStr string + type Runtime struct { runtime *wails.Runtime } @@ -66,7 +72,7 @@ func (r *Runtime) Save(rootDir string, categoryID int, gamesIn []interface{}) ([ } games = append(games, &g) } - pkg.Debug = true + return pkg.Save(rootDir, categoryID, games, "", "") } @@ -82,6 +88,50 @@ func (r *Runtime) OpenURL(URL string) error { return browser.OpenURL(URL) } +type Version struct { + Current string `json:"current"` + Latest string `json:"latest"` + HasUpdate bool `json:"hasUpdate"` +} + +func (r *Runtime) GetVersion() *Version { + v := &Version{Current: CurrentVersionStr} + resp, err := http.Get("https://api.github.com/repos/dev-drprasad/hsk00/releases/latest") + if err != nil { + fmt.Println(err) + return v + } + t := struct { + Draft bool `json:"draft"` + Prerelease bool `json:"prerelease"` + TagName string `json:"tag_name"` + }{} + + if err := json.NewDecoder(resp.Body).Decode(&t); err != nil { + fmt.Println(err) + return v + } + + latestVersion, err := semver.NewVersion(t.TagName) + if err != nil { + fmt.Println(err) + return v + } + v.Latest = t.TagName + + currentVersion, err := semver.NewVersion(CurrentVersionStr) + if err != nil { + fmt.Println(err) + return v + } + + if latestVersion.GreaterThan(currentVersion) && !t.Draft && !t.Prerelease { + v.HasUpdate = true + } + + return v +} + func main() { js := mewn.String("./frontend/build/static/js/main.js")