-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathindex.js
More file actions
120 lines (100 loc) · 2.22 KB
/
index.js
File metadata and controls
120 lines (100 loc) · 2.22 KB
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
import { invoke } from '@tauri-apps/api/core';
import {
RESET_STATE,
SET_AUTO_UPDATE,
SET_CHECKED_FOR_UPDATES,
SET_COLOR_ON_DARK,
SET_DEFAULT_SORT_BY_STRENGTH,
SET_ERROR,
SET_LANGUAGE_INDEX,
SET_LANGUAGE_SELECTOR,
SET_LOADING,
SET_PAGE_INDEX,
SET_THEME_INDEX,
SET_THEME_TYPE,
SET_TIPS,
SET_UPDATE,
} from './actionTypes';
const normalizeErrorMessage = (error) => {
if (error === null || error === undefined) {
return null;
}
if (typeof error === 'string') {
return error;
}
if (error instanceof Error) {
return error.message;
}
if (
typeof error === 'object' &&
'message' in error &&
typeof error.message === 'string'
) {
return error.message;
}
return String(error);
};
export const setLanguageIndex = (index) => ({
type: SET_LANGUAGE_INDEX,
payload: index,
});
export const setThemeIndex = (index) => ({
type: SET_THEME_INDEX,
payload: index,
});
export const setThemeType = (type) => ({
type: SET_THEME_TYPE,
payload: type,
});
export const resetState = () => ({
type: RESET_STATE,
});
export const setPageIndex = (index) => ({
type: SET_PAGE_INDEX,
payload: index,
});
export const setAutoUpdate = (value) => ({
type: SET_AUTO_UPDATE,
payload: value,
});
export const openWebSite = (website) => {
if (window.__TAURI__) {
invoke('open_website', { website }).catch((e) => {
console.error(e);
});
} else {
window.open(website, '_blank'); // We're running in a browser
}
};
export const setUpdate = (update) => ({
type: SET_UPDATE,
payload: update,
});
export const setError = (error) => ({
type: SET_ERROR,
payload: normalizeErrorMessage(error),
});
export const setLanguageSelector = (value) => ({
type: SET_LANGUAGE_SELECTOR,
payload: value,
});
export const setLoading = (value) => ({
type: SET_LOADING,
payload: value,
});
export const setCheckedForUpdates = (value) => ({
type: SET_CHECKED_FOR_UPDATES,
payload: value,
});
export const setColorOnDark = (value) => ({
type: SET_COLOR_ON_DARK,
payload: value,
});
export const setTips = (value) => ({
type: SET_TIPS,
payload: value,
});
export const setDefaultSortByStrength = (value) => ({
type: SET_DEFAULT_SORT_BY_STRENGTH,
payload: value,
});