diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml deleted file mode 100644 index 461413d..0000000 --- a/.github/workflows/deploy.yml +++ /dev/null @@ -1,47 +0,0 @@ -name: Deploy to Cloudflare Pages - -on: - release: - types: - - published - workflow_dispatch: - -jobs: - deploy: - name: Deploy to Cloudflare Pages - runs-on: ubuntu-latest - environment: deploy - - steps: - - name: Checkout code - uses: actions/checkout@v3 - - - uses: jetli/wasm-pack-action@v0.4.0 - with: - version: "latest" - - - name: Install deps - run: | - sudo apt-get update - sudo apt-get install -y curl pkg-config libssl-dev build-essential - npm install -g wrangler - - - name: Build WASM - working-directory: wasm - run: wasm-pack build --release - - - name: Install Node.js dependencies - run: npm ci - - - name: Run build script - run: npm run build - - - name: Authenticate Wrangler - env: - CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} - run: wrangler whoami - - - name: Publish to Cloudflare Pages - env: - CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} - run: wrangler pages deploy ./dist --project-name dtekv diff --git a/CHANGELOG.md b/CHANGELOG.md index 7905006..c6fb4fa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,12 @@ Add new features here, everything will be added at the end to the changelog when --> +# v1.5.12 + +## Added + +- Automatic version detection + # v1.5.11 ## Fixed diff --git a/package.json b/package.json index 98413c6..1c75aa0 100644 --- a/package.json +++ b/package.json @@ -1,11 +1,11 @@ { "name": "dtekv-emulator-web", "private": true, - "version": "1.5.11", + "version": "1.5.12", "type": "module", "scripts": { "dev": "vite", - "build": "tsc -b && vite build", + "build": "tsc -b && vite build && echo -n \"$(cat package.json | jq -r '.version')\" > dist/version.txt", "lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0", "preview": "vite preview", "fmt": "prettier . --write", diff --git a/public/version.txt b/public/version.txt new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/public/version.txt @@ -0,0 +1 @@ + diff --git a/src/App.tsx b/src/App.tsx index d30f69e..b522e39 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,4 +1,4 @@ -import React from "react"; +import React, { useEffect, useState } from "react"; import useWindowDimension from "./hooks/useWindowDimensions"; import { MIN_WINDOW_HEIGHT, MIN_WINDOW_WIDTH } from "./consts"; @@ -8,17 +8,42 @@ import { store } from "./atoms"; import TooSmall from "./pages/TooSmall"; import Dialog from "./partials/Dialog"; import * as jotai from "jotai"; +import ShouldUpdate from "./pages/ShouldUpdate"; + +function fetchVersion(): Promise { + return fetch("/version.txt").then((res) => res.text()); +} function App() { + const [shouldUpdate, setShouldUpdate] = useState(false); const dimensions = useWindowDimension(); const isTooSmall = dimensions.width < MIN_WINDOW_WIDTH || dimensions.height < MIN_WINDOW_HEIGHT; + useEffect(() => { + updateVersion(); + + function updateVersion() { + fetchVersion().then((version) => { + if (version !== __APP_VERSION__) { + setShouldUpdate(true); + } + }); + } + + addEventListener("focus", updateVersion); + return () => removeEventListener("focus", updateVersion); + }, []); + return ( {(() => { + if (process.env.NODE_ENV !== "development" && shouldUpdate) { + return ; + } + if (isTooSmall) { return ; } else { diff --git a/src/pages/ShouldUpdate/ShouldUpdate.module.css b/src/pages/ShouldUpdate/ShouldUpdate.module.css new file mode 100644 index 0000000..7cc3575 --- /dev/null +++ b/src/pages/ShouldUpdate/ShouldUpdate.module.css @@ -0,0 +1,29 @@ +.root { + display: flex; + align-items: center; + justify-content: center; + flex-direction: column; + height: 100vh; + width: 100vw; + padding: 16px; +} + +.root h1 { + margin: 0; + margin-bottom: 16px; + text-align: center; +} + +.root p { + margin: 0; + text-align: center; +} + +.splitter { + height: 16px; +} + +.root a { + color: var(--color-text); + text-decoration: underline; +} diff --git a/src/pages/ShouldUpdate/index.tsx b/src/pages/ShouldUpdate/index.tsx new file mode 100644 index 0000000..f88f4cd --- /dev/null +++ b/src/pages/ShouldUpdate/index.tsx @@ -0,0 +1,18 @@ +import React from "react"; + +import styles from "./ShouldUpdate.module.css"; + +function ShouldUpdate() { + return ( +
+

New version is available

+

Refresh page to access the new version

+ + ); +} + +export default React.memo(ShouldUpdate);