Skip to content

Commit

Permalink
feat: check update when start app
Browse files Browse the repository at this point in the history
  • Loading branch information
Serein207 committed Oct 19, 2024
1 parent 1dc7d2d commit a4098b0
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 37 deletions.
8 changes: 5 additions & 3 deletions src/Controller/View/AboutPage.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ void AboutPage::onCreate() {
self->on_open_web([this](slint::SharedString url) { openBrowser(std::string(url)); });
self->on_load_contributors([this] { loadContributors(); });
self->on_check_update([this] { checkUpdate(); });
checkUpdate(true);
}

void AboutPage::onShow() {
Expand Down Expand Up @@ -70,13 +71,13 @@ void AboutPage::loadContributors() {
});
}

void AboutPage::checkUpdate() {
void AboutPage::checkUpdate(bool quite) {
auto& self = *this;

self->set_check_update_status(PageState::Loading);

executor()->asyncExecute(
networkClient()->getLatestRelease(), [&self = *this](Result<ReleaseEntity> result) {
networkClient()->getLatestRelease(), [&self = *this, quite](Result<ReleaseEntity> result) {
if (result.isErr()) {
self->set_check_update_status(PageState::Normal);
self.bridge.getMessageManager().showMessage(result.unwrapErr().what(),
Expand All @@ -89,7 +90,8 @@ void AboutPage::checkUpdate() {
self->set_check_update_status(PageState::Normal);

if (std::string_view(VERSION_SEMANTIC).starts_with(entity.tag_name)) {
self.bridge.getMessageManager().showMessage("已是最新版本");
if (!quite)
self.bridge.getMessageManager().showMessage("已是最新版本");
return;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Controller/View/AboutPage.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class AboutPage : public BasicView, private GlobalAgent<AboutPageBridge> {
void onShow() override;

void loadContributors();
void checkUpdate();
void checkUpdate(bool quite = false);

std::vector<ContributorStruct> _contributors;
};
Expand Down
35 changes: 33 additions & 2 deletions ui/app.slint
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
//import "./assets/font/MiSans-Regular.ttf";
import { Token } from "./global.slint";
import { Button } from "std-widgets.slint";
import { Button, ScrollView } from "std-widgets.slint";
import {
Empty,
Toast
Toast,
ContentDialog
} from "./components/index.slint";
import {
ViewManagerBridge,
Expand Down Expand Up @@ -280,6 +281,36 @@ export component App inherits Window {
width: 100%;
}

popup := ContentDialog {
z: 999;
width: root.width;
height: root.height;
dialog-title: @tr("更新日志");
confirm-btn-text: @tr("更新");
cancel-btn-text: @tr("取消");
is-show <=> AboutPageBridge.show-popup;
ScrollView {
VerticalLayout {
text := Text {
width: 100%;
text: AboutPageBridge.update-log;
font-size: Token.font.body.large.size;
font-weight: Token.font.body.large.weight;
color: Token.color.on-surface;
wrap: TextWrap.char-wrap;
}
}
}

confirm => {
AboutPageBridge.open-web("https://github.com/NJUPT-SAST/sast-evento/releases/latest");
popup.close();
}
cancel => {
popup.close();
}
}

private property <length> toast-padding: 16px;
private property <length> toast-vertical-spacing: 8px;
private property <length> toast-height: 48px;
Expand Down
32 changes: 1 addition & 31 deletions ui/views/page/about.slint
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Token } from "../../global.slint";
import { Page, Empty, ContentDialog, PageState } from "../../components/index.slint";
import { Page, PageState } from "../../components/index.slint";
import { AboutSlint, ScrollView } from "std-widgets.slint";
import { MessageManager, MessageType } from "../../logic/index.slint";
import { Button, ButtonType, LoadingAnimation, StyledText } from "../../components/index.slint";
Expand Down Expand Up @@ -96,36 +96,6 @@ component Link {
}

export component AboutPage inherits Page {
popup := ContentDialog {
z: 999;
width: root.width;
height: root.height;
dialog-title: @tr("更新日志");
confirm-btn-text: @tr("更新");
cancel-btn-text: @tr("取消");
is-show <=> AboutPageBridge.show-popup;
ScrollView {
VerticalLayout {
text := Text {
width: 100%;
text: AboutPageBridge.update-log;
font-size: Token.font.body.large.size;
font-weight: Token.font.body.large.weight;
color: Token.color.on-surface;
wrap: TextWrap.char-wrap;
}
}
}

confirm => {
AboutPageBridge.open-web("https://github.com/NJUPT-SAST/sast-evento/releases/latest");
popup.close();
}
cancel => {
popup.close();
}
}

ScrollView {
verticallayout := VerticalLayout {
alignment: LayoutAlignment.start;
Expand Down

0 comments on commit a4098b0

Please sign in to comment.