diff options
author | GeckoEidechse <gecko.eidechse+git@pm.me> | 2023-04-26 21:58:55 +0200 |
---|---|---|
committer | GeckoEidechse <gecko.eidechse+git@pm.me> | 2023-04-26 21:58:55 +0200 |
commit | 10616b295eb23c8250a0d874fe05211f73a8ba81 (patch) | |
tree | aa9496bd16d973f69f6c4d9df7695cae469fad83 /src-vue/src/plugins/modules/pull_requests.ts | |
parent | 85bb5253657c16d9674a9be2f6c8090b413ca7fb (diff) | |
parent | e38ab60e1e4f565f0dafdb7b539e386a390594d7 (diff) | |
download | FlightCore-10616b295eb23c8250a0d874fe05211f73a8ba81.tar.gz FlightCore-10616b295eb23c8250a0d874fe05211f73a8ba81.zip |
Merge branch 'main' into fix/handle-failed-download
Diffstat (limited to 'src-vue/src/plugins/modules/pull_requests.ts')
-rw-r--r-- | src-vue/src/plugins/modules/pull_requests.ts | 79 |
1 files changed, 30 insertions, 49 deletions
diff --git a/src-vue/src/plugins/modules/pull_requests.ts b/src-vue/src/plugins/modules/pull_requests.ts index 573856ad..ff9ec322 100644 --- a/src-vue/src/plugins/modules/pull_requests.ts +++ b/src-vue/src/plugins/modules/pull_requests.ts @@ -1,8 +1,8 @@ -import { ElNotification } from "element-plus"; -import { invoke } from "@tauri-apps/api"; +import { invoke, shell } from "@tauri-apps/api"; import { PullsApiResponseElement } from "../../../../src-tauri/bindings/PullsApiResponseElement"; import { PullRequestType } from '../../../../src-tauri/bindings/PullRequestType'; import { store } from "../store"; +import { showErrorNotification, showNotification } from "../../utils/ui"; interface PullRequestStoreState { searchValue: string, @@ -20,11 +20,11 @@ export const pullRequestModule = { await invoke<PullsApiResponseElement[]>("get_pull_requests_wrapper", { installType: pull_request_type }) .then((message) => { switch (pull_request_type) { - case "MODS": + case "Mods": state.pull_requests_mods = message; break; - case "LAUNCHER": + case "Launcher": state.pull_requests_launcher = message; break; @@ -33,42 +33,35 @@ export const pullRequestModule = { } }) .catch((error) => { - ElNotification({ - title: 'Error', - message: error, - type: 'error', - position: 'bottom-right' - }); + showErrorNotification(error); }); }, + async downloadLauncherPR(state: PullRequestStoreState, pull_request: PullsApiResponseElement) { + await invoke<string>("get_launcher_download_link", { pullRequest: pull_request }) + .then((url) => { + // Open URL in default HTTPS handler (i.e. default browser) + shell.open(url); + }) + .catch((error) => { + showErrorNotification(error); + }); + }, + async downloadModsPR(state: PullRequestStoreState, pull_request: PullsApiResponseElement) { + let url = `https://github.com/${pull_request.head.repo.full_name}/archive/refs/heads/${pull_request.head.ref}.zip` + shell.open(url); + }, async installLauncherPR(state: PullRequestStoreState, pull_request: PullsApiResponseElement) { // Send notification telling the user to wait for the process to finish - const notification = ElNotification({ - title: `Installing launcher PR ${pull_request.number}`, - message: 'Please wait', - duration: 0, - type: 'info', - position: 'bottom-right' - }); + const notification = showNotification(`Installing launcher PR ${pull_request.number}`, 'Please wait', 'info', 0); await invoke("apply_launcher_pr", { pullRequest: pull_request, gameInstallPath: store.state.game_path }) .then((message) => { console.log(message); // Show user notification if mod install completed. - ElNotification({ - title: `Done`, - message: `Installed ${pull_request.number}: "${pull_request.title}"`, - type: 'success', - position: 'bottom-right' - }); + showNotification(`Done`, `Installed ${pull_request.number}: "${pull_request.title}"`); }) .catch((error) => { - ElNotification({ - title: 'Error', - message: error, - type: 'error', - position: 'bottom-right' - }); + showErrorNotification(error); }) .finally(() => { // Clear old notification @@ -77,32 +70,20 @@ export const pullRequestModule = { }, async installModsPR(state: PullRequestStoreState, pull_request: PullsApiResponseElement) { // Send notification telling the user to wait for the process to finish - const notification = ElNotification({ - title: `Installing mods PR ${pull_request.number}`, - message: 'Please wait', - duration: 0, - type: 'info', - position: 'bottom-right' - }); + const notification = showNotification(`Installing mods PR ${pull_request.number}`, 'Please wait', 'info', 0); await invoke("apply_mods_pr", { pullRequest: pull_request, gameInstallPath: store.state.game_path }) .then((message) => { // Show user notification if mod install completed. - ElNotification({ - title: `Done`, - message: `Installed ${pull_request.number}: "${pull_request.title}"\nMake sure to launch via batch file or by specifying correct profile!`, - type: 'success', - duration: 7_000, // in ms - position: 'bottom-right' - }); + showNotification( + `Done`, + `Installed ${pull_request.number}: "${pull_request.title}"\nMake sure to launch via batch file or by specifying correct profile!`, + 'success', + 7000 + ); }) .catch((error) => { - ElNotification({ - title: 'Error', - message: error, - type: 'error', - position: 'bottom-right' - }); + showErrorNotification(error); }) .finally(() => { // Clear old notification |