-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
190 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { Channel, invoke } from "@tauri-apps/api/core"; | ||
import { ref } from "vue"; | ||
|
||
export const is_download = ref(false); | ||
export const download_percent = ref(0); | ||
|
||
type DownloadEvent = | ||
| { | ||
event: "started"; | ||
data: { | ||
newVersion: boolean; | ||
}; | ||
} | ||
| { | ||
event: "progress"; | ||
data: { | ||
downloaded: number; | ||
contentLength: number; | ||
}; | ||
} | ||
| { | ||
event: "finished"; | ||
data: { | ||
finished: boolean; | ||
}; | ||
}; | ||
|
||
const onEvent = new Channel<DownloadEvent>(); | ||
onEvent.onmessage = (message) => { | ||
if (message.event === "started") { | ||
is_download.value = message.data.newVersion; // 这没有意义 | ||
} else if (message.event === "progress") { | ||
download_percent.value = | ||
parseFloat( | ||
(message.data.downloaded / message.data.contentLength).toFixed(2) | ||
) * 100; | ||
} | ||
}; | ||
|
||
export const check_update = async (manually: boolean) => { | ||
await invoke("manually_check_update", { | ||
manually, | ||
onEvent, | ||
}).catch((err) => console.log(err)); | ||
}; |