Skip to content

Commit

Permalink
Merge pull request #310 from nini22P/dev
Browse files Browse the repository at this point in the history
feat: improved notification of new version update
  • Loading branch information
MakinoharaShoko authored Sep 16, 2024
2 parents 27dcb83 + 7aa7c5c commit ea4d642
Show file tree
Hide file tree
Showing 11 changed files with 230 additions and 140 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/build-terre.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
GH_TOKEN: ${{ secrets.GH_TOKEN }}
run: sh release-linux.sh
- name: Upload Artifact
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: WebGAL_Terre_Linux
path: release
Expand Down Expand Up @@ -111,7 +111,7 @@ jobs:
rm -rf assets/templates/WebGAL_Android_Template/app/src/main/java/com
echo "WebGAL Terre is now ready to be deployed."
- name: Upload Artifact
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: WebGAL_Terre_Linux_Arm64
path: release
Expand All @@ -131,7 +131,7 @@ jobs:
GH_TOKEN: ${{ secrets.GH_TOKEN }}
run: sh release-mac.sh
- name: Upload Artifact
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: WebGAL_Terre_Mac
path: release
Expand All @@ -150,7 +150,7 @@ jobs:
shell: bash
run: ./release.sh
- name: Upload Artifact
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: WebGAL_Terre_Windows
path: release
Expand All @@ -172,7 +172,7 @@ jobs:
shell: bash
run: mkdir bundle && yarn nsis-bundle
- name: Upload Artifact
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: WebGAL_Terre_Windows_Setup
path: bundle/WebGal_Terre_Setup.exe
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/pr-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
GH_TOKEN: ${{ secrets.GH_TOKEN }}
run: sh release-linux.sh
- name: Upload Artifact
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: WebGAL_Terre_Linux
path: release
Expand Down Expand Up @@ -113,7 +113,7 @@ jobs:
rm -rf assets/templates/WebGAL_Android_Template/app/src/main/java/com
echo "WebGAL Terre is now ready to be deployed."
- name: Upload Artifact
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: WebGAL_Terre_Linux_Arm64
path: release
Expand All @@ -133,7 +133,7 @@ jobs:
GH_TOKEN: ${{ secrets.GH_TOKEN }}
run: sh release-mac.sh
- name: Upload Artifact
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: WebGAL_Terre_Mac
path: release
Expand All @@ -152,7 +152,7 @@ jobs:
shell: bash
run: ./release.sh
- name: Upload Artifact
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: WebGAL_Terre_Windows
path: release
Expand All @@ -174,7 +174,7 @@ jobs:
shell: bash
run: mkdir bundle && yarn nsis-bundle
- name: Upload Artifact
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: WebGAL_Terre_Windows_Setup
path: bundle/WebGal_Terre_Setup.exe
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
run: 7z a -tzip WebGAL_Terre_Linux.zip release/*

- name: Upload Artifact
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: WebGAL_Terre_Linux
path: WebGAL_Terre_Linux.zip
Expand Down Expand Up @@ -119,7 +119,7 @@ jobs:
- name: Compress
run: 7z a -tzip WebGAL_Terre_Linux_Arm64.zip release/*
- name: Upload Artifact
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: WebGAL_Terre_Linux_Arm64
path: WebGAL_Terre_Linux_Arm64.zip
Expand All @@ -141,7 +141,7 @@ jobs:
- name: Compress
run: 7z a -tzip WebGAL_Terre_Mac.zip release/*
- name: Upload Artifact
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: WebGAL_Terre_Mac
path: WebGAL_Terre_Mac.zip
Expand All @@ -162,7 +162,7 @@ jobs:
- name: Compress
run: 7z a -tzip WebGAL_Terre_Windows.zip release/*
- name: Upload Artifact
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: WebGAL_Terre_Windows
path: WebGAL_Terre_Windows.zip
Expand All @@ -184,7 +184,7 @@ jobs:
shell: bash
run: mkdir bundle && yarn nsis-bundle
- name: Upload Artifact
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: WebGAL_Terre_Windows_Setup
path: bundle/WebGal_Terre_Setup.exe
Expand Down
49 changes: 37 additions & 12 deletions packages/origine2/src/hooks/useRelease.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
import { __INFO } from "@/config/info";
import { logger } from "@/utils/logger";
import { useState, useEffect } from "react";
import useSWRImmutable from "swr/immutable";

export interface LatestRelease {
version: string,
releaseTime: string,
hasNewVersion: boolean;
}

export function useRelease() {

const webgalTerreLatestApiUrl = 'https://api.github.com/repos/MakinoharaShoko/WebGAL_Terre/releases/latest';
const webgalTerreLatestApiUrl = 'https://api.github.com/repos/OpenWebGAL/WebGAL_Terre/releases/latest';

const [latestRelease, setLatestRelease] = useState<LatestRelease | null>(null);

const getRelease = async (): Promise<LatestRelease | null> => {
const latestReleaseFetcher = async (): Promise<LatestRelease | null> => {
try {
const response = await fetch(webgalTerreLatestApiUrl);
switch (response.status) {
Expand All @@ -24,6 +23,7 @@ export function useRelease() {
return {
version: releasedata.tag_name,
releaseTime: releasedata.published_at,
hasNewVersion: compareVersion(releasedata.tag_name, __INFO.version) === 1,
};
} else {
logger.error("发布版本解析失败");
Expand All @@ -43,13 +43,38 @@ export function useRelease() {
};
};

useEffect(() => {
getRelease().then(
releasedata => setLatestRelease(
(releasedata?.version && releasedata?.releaseTime) ? releasedata : null
)
);
}, []);
const { data, error, isLoading } = useSWRImmutable('latest-release', latestReleaseFetcher);

const latestRelease = (data && !error && !isLoading) ? data : null;;

/**
* 比较版本号
* @param latestVersion 最新版本
* @param currentVersion 当前版本
* @returns 1: 最新版本比当前版本高, -1: 最新版本比当前版本低,0: 版本相同
*/
const compareVersion = (latestVersion: string, currentVersion: string) => {
const versionToArray = (version: string) => version?.split('.')?.map(v => Number(v))??[0];

const latestVersionArray = versionToArray(latestVersion);
const currentVersionArray = versionToArray(currentVersion);
const length = Math.max(latestVersionArray.length, currentVersionArray.length);

for (let i = 0; i < length; i++) {
if (!latestVersionArray[i]){
latestVersionArray[i] = 0;
}
if (!currentVersionArray[i]){
currentVersionArray[i] = 0;
}
if (latestVersionArray[i] > currentVersionArray[i]) {
return 1;
} else if (latestVersionArray[i] < currentVersionArray[i]) {
return -1;
}
}
return 0;
};

return latestRelease;
};
47 changes: 27 additions & 20 deletions packages/origine2/src/locales/en.po
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,6 @@ msgstr "Upload"
msgid "上传资源"
msgstr "Upload asset"

#: src/pages/dashboard/About.tsx:88
msgid "下载最新版本"
msgstr "Download Latest Version"

#: src/pages/editor/GraphicalEditor/SentenceEditor/PixiPerform.tsx:14
msgid "下雨"
msgstr "Rain"
Expand Down Expand Up @@ -337,8 +333,8 @@ msgstr "Full-screen text"
msgid "全屏显示一段文字,用于独白或引出场景"
msgstr "Show some texts on Full-screen"

#: src/pages/dashboard/About.tsx:65
#: src/pages/dashboard/About.tsx:66
#: src/pages/dashboard/About.tsx:32
#: src/pages/dashboard/About.tsx:33
msgid "关于"
msgstr "About"

Expand Down Expand Up @@ -394,7 +390,8 @@ msgstr "Min Width"
msgid "最小高度"
msgstr "Min Height"

#: src/pages/dashboard/About.tsx:81
#: src/pages/dashboard/About.tsx:48
#: src/pages/dashboard/DashBoard.tsx:190
msgid "最新版本"
msgstr "Latest Version"

Expand Down Expand Up @@ -514,6 +511,10 @@ msgstr "Single line comment"
msgid "反射电影滤镜"
msgstr "Reflection film filter"

#: src/pages/dashboard/DashBoard.tsx:185
msgid "发现新版本"
msgstr "New version detected"

#: src/pages/editor/ChooseFile/ChooseFile.tsx:55
msgid "取消"
msgstr "Cancel"
Expand Down Expand Up @@ -735,7 +736,7 @@ msgstr "Left side figure"
msgid "左对齐"
msgstr "Left align"

#: src/pages/dashboard/DashBoard.tsx:126
#: src/pages/dashboard/DashBoard.tsx:141
msgid "已创建"
msgstr "Created"

Expand Down Expand Up @@ -780,10 +781,15 @@ msgstr "Delay time (seconds)"
msgid "张开嘴"
msgstr "Open mouth"

#: src/pages/dashboard/About.tsx:77
#: src/pages/dashboard/About.tsx:44
#: src/pages/dashboard/DashBoard.tsx:189
msgid "当前版本"
msgstr "Current version"

#: src/pages/dashboard/DashBoard.tsx:199
msgid "忽略此版本"
msgstr "Ignore this version"

#: src/pages/dashboard/GameElement.tsx:148
msgid "我确定要删除游戏"
msgstr "I'm sure to delete the game"
Expand Down Expand Up @@ -978,7 +984,7 @@ msgstr "Text length (em)"
msgid "文本阴影"
msgstr "Text Shadow"

#: src/pages/dashboard/About.tsx:106
#: src/pages/dashboard/About.tsx:73
msgid "文档"
msgstr "Document"

Expand Down Expand Up @@ -1144,11 +1150,7 @@ msgstr "Title background music"
msgid "根文本长度 (rem)"
msgstr "Root Font Size (rem)"

#: src/pages/dashboard/About.tsx:66
msgid "检测到新版本"
msgstr "New version detected"

#: src/pages/dashboard/DashBoard.tsx:176
#: src/pages/dashboard/DashBoard.tsx:247
#: src/pages/editor/EditorSidebar/EditorSidebar.tsx:110
msgid "模板"
msgstr "Template"
Expand Down Expand Up @@ -1243,7 +1245,7 @@ msgstr "Clear special effects of current stage"
msgid "清除特效"
msgstr "Clear effects"

#: src/pages/dashboard/DashBoard.tsx:174
#: src/pages/dashboard/DashBoard.tsx:245
msgid "游戏"
msgstr "Games"

Expand Down Expand Up @@ -1324,7 +1326,7 @@ msgstr "Confirm button text"
msgid "视图"
msgstr "View"

#: src/pages/dashboard/About.tsx:75
#: src/pages/dashboard/About.tsx:42
msgid "视觉小说编辑,再进化"
msgstr "Visual novel editing, evolved"

Expand Down Expand Up @@ -1493,6 +1495,11 @@ msgstr "Custom effect name"
msgid "舞台对象控制"
msgstr "Stage object control"

#: src/pages/dashboard/About.tsx:55
#: src/pages/dashboard/DashBoard.tsx:195
msgid "获取最新版本"
msgstr "Download Latest Version"

#: src/pages/editor/GraphicalEditor/SentenceEditor/index.tsx:248
msgid "获取来自用户的字符输入"
msgstr "Get character input from user"
Expand Down Expand Up @@ -1595,8 +1602,8 @@ msgstr "This command is not recognized, please open script editing mode to edit
msgid "该文件类型不支持预览"
msgstr "This file type does not support preview"

#: src/pages/dashboard/DashBoard.tsx:157
#: src/pages/dashboard/DashBoard.tsx:158
#: src/pages/dashboard/DashBoard.tsx:228
#: src/pages/dashboard/DashBoard.tsx:229
#: src/pages/editor/Topbar/tabs/Settings/SettingsTab.tsx:40
#: src/pages/editor/Topbar/tabs/Settings/SettingsTab.tsx:46
msgid "语言"
Expand Down Expand Up @@ -1806,7 +1813,7 @@ msgstr "Left"
msgid "音乐"
msgstr "Music"

#: src/pages/dashboard/About.tsx:103
#: src/pages/dashboard/About.tsx:70
msgid "项目主页"
msgstr "Project Homepage"

Expand Down
Loading

0 comments on commit ea4d642

Please sign in to comment.