Skip to content

Commit

Permalink
feat: add check update option
Browse files Browse the repository at this point in the history
  • Loading branch information
Okabe-Rintarou-0 committed Sep 27, 2024
1 parent cf416cb commit f91a668
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
6 changes: 6 additions & 0 deletions src/components/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { ChangeLogModal } from './change_log_modal';
import { LuBookOpenCheck } from 'react-icons/lu';
import { useKeyPress } from '../lib/hooks';
import { FaPeopleGroup } from "react-icons/fa6";
import { checkForUpdates } from '../lib/utils';
import useMessage from 'antd/es/message/useMessage';
const { Content, Footer, Sider } = Layout;

export default function BasicLayout({ children }: React.PropsWithChildren) {
Expand Down Expand Up @@ -72,6 +74,8 @@ export default function BasicLayout({ children }: React.PropsWithChildren) {
token: { colorBgContainer, borderRadiusLG },
} = theme.useToken();

const [messageApi, contextHolder] = useMessage();

const [scale, setScale] = useState(1);

const zoomIn = () => {
Expand All @@ -87,6 +91,7 @@ export default function BasicLayout({ children }: React.PropsWithChildren) {
useKeyPress('-', zoomOut);

return <Layout style={{ minHeight: "100vh" }}>
{contextHolder}
<Sider theme="light" style={{ position: 'fixed', height: '100%' }}>
<Menu theme="light" mode="inline" defaultSelectedKeys={selectedKeys} items={items} />
</Sider>
Expand All @@ -111,6 +116,7 @@ export default function BasicLayout({ children }: React.PropsWithChildren) {
<Footer style={{ textAlign: 'center' }}>
<Space>
<span>当前版本:{version}</span>
<a onClick={() => checkForUpdates(messageApi)}>检查更新</a>
<a onClick={(e) => {
e.preventDefault();
setShowChangeLog(true);
Expand Down
2 changes: 1 addition & 1 deletion src/components/submit_modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export function SubmitModal({ open, onCancel, onSubmit, allowed_extensions, cour
key: "submitting",
type: "loading",
content: "正在提交中😄...请耐心等待!"
})
});
await invoke("submit_assignment", { courseId, assignmentId, filePaths, comment });
onSubmit?.();
} catch (e) {
Expand Down
22 changes: 21 additions & 1 deletion src/lib/utils.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { decode } from "js-base64";
import { getConfig } from "./store";
import dayjs, { Dayjs } from "dayjs"
import { checkUpdate } from '@tauri-apps/api/updater';
import { Assignment, AssignmentDate, Attachment, File as FileModel } from "./model";
import { PiMicrosoftExcelLogoFill, PiMicrosoftPowerpointLogoFill, PiMicrosoftWordLogoFill } from "react-icons/pi";
import { FaRegFilePdf, FaImage, FaFileCsv, FaRegFileArchive, FaRegFileVideo, FaRegFileAudio } from "react-icons/fa";
import { FileOutlined } from "@ant-design/icons"
import { invoke } from "@tauri-apps/api";
import { MessageInstance } from "antd/es/message/interface";

export function formatDate(inputDate: string | undefined | null): string {
if (!inputDate) {
Expand Down Expand Up @@ -224,4 +226,22 @@ export function getBigFileIcon(file: FileModel) {

export function scrollToTop() {
window.scrollTo(0, 0);
}
}

export async function checkForUpdates(messageApi: MessageInstance) {
try {
const messageKey = "checking";
messageApi.open({
key: messageKey,
type: "loading",
content: "检查中🚀..."
});
const { shouldUpdate } = await checkUpdate();
messageApi.destroy(messageKey);
if (!shouldUpdate) {
messageApi.warning("已经是最新版,无需更新😁");
}
} catch (error) {
messageApi.error("🥹出现错误:" + error);
}
}

0 comments on commit f91a668

Please sign in to comment.