1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
|
import { ElNotification } from "element-plus";
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";
interface PullRequestStoreState {
searchValue: string,
pull_requests_launcher: PullsApiResponseElement[],
pull_requests_mods: PullsApiResponseElement[],
}
export const pullRequestModule = {
state: () => ({
pull_requests_launcher: [],
pull_requests_mods: [],
}),
mutations: {
async getPullRequests(state: PullRequestStoreState, pull_request_type: PullRequestType) {
await invoke<PullsApiResponseElement[]>("get_pull_requests_wrapper", { installType: pull_request_type })
.then((message) => {
switch (pull_request_type) {
case "MODS":
state.pull_requests_mods = message;
break;
case "LAUNCHER":
state.pull_requests_launcher = message;
break;
default:
console.error("We should never end up here");
}
})
.catch((error) => {
ElNotification({
title: 'Error',
message: error,
type: 'error',
position: 'bottom-right'
});
});
},
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) => {
ElNotification({
title: 'Error',
message: error,
type: 'error',
position: 'bottom-right'
});
});
},
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'
});
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'
});
})
.catch((error) => {
ElNotification({
title: 'Error',
message: error,
type: 'error',
position: 'bottom-right'
});
})
.finally(() => {
// Clear old notification
notification.close();
});
},
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'
});
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'
});
})
.catch((error) => {
ElNotification({
title: 'Error',
message: error,
type: 'error',
position: 'bottom-right'
});
})
.finally(() => {
// Clear old notification
notification.close();
});
},
}
}
|