mirror of
https://github.com/Grasscutters/Cultivation.git
synced 2025-12-12 15:14:35 +01:00
Merge pull request #23 from Seeker14491/ci
Set up GitHub Actions lints and checks
This commit is contained in:
@@ -13,6 +13,8 @@ trim_trailing_whitespace = false
|
|||||||
[*.rs]
|
[*.rs]
|
||||||
max_line_length = 100
|
max_line_length = 100
|
||||||
indent_size = 2
|
indent_size = 2
|
||||||
|
insert_final_newline = true
|
||||||
|
trim_trailing_whitespace = true
|
||||||
|
|
||||||
[{*.ats,*.cts,*.mts,*.ts}]
|
[{*.ats,*.cts,*.mts,*.ts}]
|
||||||
indent_size = 2
|
indent_size = 2
|
||||||
|
|||||||
@@ -33,6 +33,27 @@
|
|||||||
"semi": [
|
"semi": [
|
||||||
"error",
|
"error",
|
||||||
"never"
|
"never"
|
||||||
|
],
|
||||||
|
"@typescript-eslint/ban-types": [
|
||||||
|
"warn",
|
||||||
|
{
|
||||||
|
"extendDefaults": true,
|
||||||
|
"types": {
|
||||||
|
"{}": false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"@typescript-eslint/no-unused-vars": [
|
||||||
|
"warn",
|
||||||
|
{
|
||||||
|
"argsIgnorePattern": "^_",
|
||||||
|
"varsIgnorePattern": "^_"
|
||||||
|
}
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
"settings": {
|
||||||
|
"react": {
|
||||||
|
"version": "detect"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
62
.github/workflows/backend-checks.yml
vendored
Normal file
62
.github/workflows/backend-checks.yml
vendored
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
name: Check backend
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
paths:
|
||||||
|
- ".github/workflows/backend-checks.yml"
|
||||||
|
- "src-tauri/**"
|
||||||
|
pull_request:
|
||||||
|
paths:
|
||||||
|
- ".github/workflows/backend-checks.yml"
|
||||||
|
- "src-tauri/**"
|
||||||
|
|
||||||
|
concurrency:
|
||||||
|
group: ${{ github.ref }}-${{ github.workflow }}
|
||||||
|
cancel-in-progress: true
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
rustfmt:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- uses: actions-rs/cargo@v1
|
||||||
|
with:
|
||||||
|
command: fmt
|
||||||
|
args: --manifest-path ./src-tauri/Cargo.toml --all -- --check
|
||||||
|
|
||||||
|
clippy:
|
||||||
|
runs-on: ${{ matrix.platform }}
|
||||||
|
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
platform: [windows-latest, ubuntu-latest, macos-latest]
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Install Linux dependencies
|
||||||
|
if: matrix.platform == 'ubuntu-latest'
|
||||||
|
run: |
|
||||||
|
sudo apt-get update
|
||||||
|
sudo apt-get install -y libwebkit2gtk-4.0-dev \
|
||||||
|
build-essential \
|
||||||
|
curl \
|
||||||
|
wget \
|
||||||
|
libssl-dev \
|
||||||
|
libgtk-3-dev \
|
||||||
|
libayatana-appindicator3-dev \
|
||||||
|
librsvg2-dev
|
||||||
|
|
||||||
|
- uses: Swatinem/rust-cache@v1
|
||||||
|
with:
|
||||||
|
working-directory: src-tauri
|
||||||
|
|
||||||
|
- uses: actions-rs/clippy-check@v1
|
||||||
|
with:
|
||||||
|
name: clippy (${{ runner.os }})
|
||||||
|
token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
args: --manifest-path ./src-tauri/Cargo.toml --no-default-features -- -D warnings
|
||||||
|
|
||||||
37
.github/workflows/frontend-checks.yml
vendored
Normal file
37
.github/workflows/frontend-checks.yml
vendored
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
name: Check frontend
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
paths:
|
||||||
|
- ".github/workflows/frontend-checks.yml"
|
||||||
|
- "src/**"
|
||||||
|
- ".eslintrc.json"
|
||||||
|
- "package.json"
|
||||||
|
- "tsconfig.json"
|
||||||
|
- "yarn.lock"
|
||||||
|
pull_request:
|
||||||
|
paths:
|
||||||
|
- ".github/workflows/frontend-checks.yml"
|
||||||
|
- "src/**"
|
||||||
|
- ".eslintrc.json"
|
||||||
|
- "package.json"
|
||||||
|
- "tsconfig.json"
|
||||||
|
- "yarn.lock"
|
||||||
|
|
||||||
|
concurrency:
|
||||||
|
group: ${{ github.ref }}-${{ github.workflow }}
|
||||||
|
cancel-in-progress: true
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
tsc-eslint-checks:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Install modules
|
||||||
|
run: yarn
|
||||||
|
- name: Run tsc
|
||||||
|
run: yarn tsc --noEmit
|
||||||
|
- name: Run ESLint
|
||||||
|
run: yarn eslint src
|
||||||
|
|
||||||
@@ -42,6 +42,10 @@ Once downloaded, extract somewhere and open as administrator.
|
|||||||
|
|
||||||
Add `--release` or `--debug` depending on what release you are creating. This defaults to `--release`
|
Add `--release` or `--debug` depending on what release you are creating. This defaults to `--release`
|
||||||
|
|
||||||
|
### Code Formatting and Linting
|
||||||
|
|
||||||
|
Format the code with `npm format` or `yarn format`. Run the lints with `npm lint` or `yarn lint`.
|
||||||
|
|
||||||
### Updating
|
### Updating
|
||||||
* Add the `TAURI_PRIVATE_KEY` as an environment variable with a path to your private key.
|
* Add the `TAURI_PRIVATE_KEY` as an environment variable with a path to your private key.
|
||||||
* Add the `TAURI_KEY_PASSWORD` as an environment variable with the password for your private key.
|
* Add the `TAURI_KEY_PASSWORD` as an environment variable with the password for your private key.
|
||||||
|
|||||||
@@ -27,7 +27,9 @@
|
|||||||
"test": "react-scripts test",
|
"test": "react-scripts test",
|
||||||
"eject": "react-scripts eject",
|
"eject": "react-scripts eject",
|
||||||
"tauri": "tauri",
|
"tauri": "tauri",
|
||||||
"start:dev": "tauri dev"
|
"start:dev": "tauri dev",
|
||||||
|
"format": "cargo fmt --manifest-path ./src-tauri/Cargo.toml --all",
|
||||||
|
"lint": "cargo clippy --manifest-path ./src-tauri/Cargo.toml --no-default-features && yarn tsc --noEmit && yarn eslint src"
|
||||||
},
|
},
|
||||||
"eslintConfig": {
|
"eslintConfig": {
|
||||||
"extends": [
|
"extends": [
|
||||||
|
|||||||
3
src-tauri/rustfmt.toml
Normal file
3
src-tauri/rustfmt.toml
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
tab_spaces = 2
|
||||||
|
use_field_init_shorthand = true
|
||||||
|
use_try_shorthand = true
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
use once_cell::sync::Lazy;
|
use once_cell::sync::Lazy;
|
||||||
|
|
||||||
use std::sync::Mutex;
|
|
||||||
use std::cmp::min;
|
use std::cmp::min;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
|
use std::sync::Mutex;
|
||||||
|
|
||||||
use futures_util::StreamExt;
|
use futures_util::StreamExt;
|
||||||
|
|
||||||
@@ -15,17 +15,14 @@ static DOWNLOADS: Lazy<Mutex<Vec<String>>> = Lazy::new(|| Mutex::new(Vec::new())
|
|||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub async fn download_file(window: tauri::Window, url: &str, path: &str) -> Result<(), String> {
|
pub async fn download_file(window: tauri::Window, url: &str, path: &str) -> Result<(), String> {
|
||||||
// Reqwest setup
|
// Reqwest setup
|
||||||
let res = match reqwest::get(url)
|
let res = match reqwest::get(url).await {
|
||||||
.await {
|
|
||||||
Ok(r) => r,
|
Ok(r) => r,
|
||||||
Err(_e) => {
|
Err(_e) => {
|
||||||
emit_download_err(window, format!("Failed to request {}", url), path);
|
emit_download_err(window, format!("Failed to request {}", url), path);
|
||||||
return Err(format!("Failed to request {}", url));
|
return Err(format!("Failed to request {}", url));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let total_size = res
|
let total_size = res.content_length().unwrap_or(0);
|
||||||
.content_length()
|
|
||||||
.unwrap_or(0);
|
|
||||||
|
|
||||||
// Create file path
|
// Create file path
|
||||||
let mut file = match File::create(path) {
|
let mut file = match File::create(path) {
|
||||||
@@ -77,25 +74,10 @@ pub async fn download_file(window: tauri::Window, url: &str, path: &str) -> Resu
|
|||||||
|
|
||||||
let mut res_hash = std::collections::HashMap::new();
|
let mut res_hash = std::collections::HashMap::new();
|
||||||
|
|
||||||
res_hash.insert(
|
res_hash.insert("downloaded".to_string(), downloaded.to_string());
|
||||||
"downloaded".to_string(),
|
res_hash.insert("total".to_string(), total_size.to_string());
|
||||||
downloaded.to_string(),
|
res_hash.insert("path".to_string(), path.to_string());
|
||||||
);
|
res_hash.insert("total_downloaded".to_string(), total_downloaded.to_string());
|
||||||
|
|
||||||
res_hash.insert(
|
|
||||||
"total".to_string(),
|
|
||||||
total_size.to_string(),
|
|
||||||
);
|
|
||||||
|
|
||||||
res_hash.insert(
|
|
||||||
"path".to_string(),
|
|
||||||
path.to_string(),
|
|
||||||
);
|
|
||||||
|
|
||||||
res_hash.insert(
|
|
||||||
"total_downloaded".to_string(),
|
|
||||||
total_downloaded.to_string(),
|
|
||||||
);
|
|
||||||
|
|
||||||
// Create event to send to frontend
|
// Create event to send to frontend
|
||||||
window.emit("download_progress", &res_hash).unwrap();
|
window.emit("download_progress", &res_hash).unwrap();
|
||||||
@@ -111,15 +93,8 @@ pub async fn download_file(window: tauri::Window, url: &str, path: &str) -> Resu
|
|||||||
pub fn emit_download_err(window: tauri::Window, msg: String, path: &str) {
|
pub fn emit_download_err(window: tauri::Window, msg: String, path: &str) {
|
||||||
let mut res_hash = std::collections::HashMap::new();
|
let mut res_hash = std::collections::HashMap::new();
|
||||||
|
|
||||||
res_hash.insert(
|
res_hash.insert("error".to_string(), msg);
|
||||||
"error".to_string(),
|
res_hash.insert("path".to_string(), path.to_string());
|
||||||
msg,
|
|
||||||
);
|
|
||||||
|
|
||||||
res_hash.insert(
|
|
||||||
"path".to_string(),
|
|
||||||
path.to_string(),
|
|
||||||
);
|
|
||||||
|
|
||||||
window.emit("download_error", &res_hash).unwrap();
|
window.emit("download_error", &res_hash).unwrap();
|
||||||
}
|
}
|
||||||
@@ -139,4 +114,4 @@ pub fn stop_download(path: String) {
|
|||||||
if let Err(_e) = std::fs::remove_file(&path) {
|
if let Err(_e) = std::fs::remove_file(&path) {
|
||||||
// Do nothing
|
// Do nothing
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ pub fn dir_delete(path: &str) {
|
|||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub fn copy_file(path: String, new_path: String) -> bool {
|
pub fn copy_file(path: String, new_path: String) -> bool {
|
||||||
let filename = &path.split("/").last().unwrap();
|
let filename = &path.split('/').last().unwrap();
|
||||||
let mut new_path_buf = std::path::PathBuf::from(&new_path);
|
let mut new_path_buf = std::path::PathBuf::from(&new_path);
|
||||||
|
|
||||||
// If the new path doesn't exist, create it.
|
// If the new path doesn't exist, create it.
|
||||||
|
|||||||
@@ -1,12 +1,14 @@
|
|||||||
use std::path::{Path, PathBuf};
|
|
||||||
use crate::system_helpers::*;
|
use crate::system_helpers::*;
|
||||||
|
use std::path::{Path, PathBuf};
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub async fn get_lang(window: tauri::Window, lang: String) -> String {
|
pub async fn get_lang(window: tauri::Window, lang: String) -> String {
|
||||||
let lang = lang.to_lowercase();
|
let lang = lang.to_lowercase();
|
||||||
|
|
||||||
// Send contents of language file back
|
// Send contents of language file back
|
||||||
let lang_path: PathBuf = [&install_location(), "lang", &format!("{}.json", lang)].iter().collect();
|
let lang_path: PathBuf = [&install_location(), "lang", &format!("{}.json", lang)]
|
||||||
|
.iter()
|
||||||
|
.collect();
|
||||||
match std::fs::read_to_string(&lang_path) {
|
match std::fs::read_to_string(&lang_path) {
|
||||||
Ok(x) => x,
|
Ok(x) => x,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
@@ -45,10 +47,7 @@ pub async fn get_languages() -> std::collections::HashMap<String, String> {
|
|||||||
pub fn emit_lang_err(window: tauri::Window, msg: String) {
|
pub fn emit_lang_err(window: tauri::Window, msg: String) {
|
||||||
let mut res_hash = std::collections::HashMap::new();
|
let mut res_hash = std::collections::HashMap::new();
|
||||||
|
|
||||||
res_hash.insert(
|
res_hash.insert("error".to_string(), msg);
|
||||||
"error".to_string(),
|
|
||||||
msg,
|
|
||||||
);
|
|
||||||
|
|
||||||
window.emit("lang_error", &res_hash).unwrap();
|
window.emit("lang_error", &res_hash).unwrap();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,22 +1,22 @@
|
|||||||
#![cfg_attr(
|
#![cfg_attr(
|
||||||
all(not(debug_assertions), target_os = "windows"),
|
all(not(debug_assertions), target_os = "windows"),
|
||||||
windows_subsystem = "windows"
|
windows_subsystem = "windows"
|
||||||
)]
|
)]
|
||||||
|
|
||||||
use once_cell::sync::Lazy;
|
use once_cell::sync::Lazy;
|
||||||
use std::{sync::Mutex, collections::HashMap};
|
use std::{collections::HashMap, sync::Mutex};
|
||||||
|
|
||||||
use std::thread;
|
use std::thread;
|
||||||
|
use structs::APIQuery;
|
||||||
use sysinfo::{System, SystemExt};
|
use sysinfo::{System, SystemExt};
|
||||||
use structs::{APIQuery};
|
|
||||||
|
|
||||||
mod structs;
|
|
||||||
mod system_helpers;
|
|
||||||
mod file_helpers;
|
|
||||||
mod unzip;
|
|
||||||
mod downloader;
|
mod downloader;
|
||||||
|
mod file_helpers;
|
||||||
mod lang;
|
mod lang;
|
||||||
mod proxy;
|
mod proxy;
|
||||||
|
mod structs;
|
||||||
|
mod system_helpers;
|
||||||
|
mod unzip;
|
||||||
mod web;
|
mod web;
|
||||||
|
|
||||||
static WATCH_GAME_PROCESS: Lazy<Mutex<String>> = Lazy::new(|| Mutex::new(String::new()));
|
static WATCH_GAME_PROCESS: Lazy<Mutex<String>> = Lazy::new(|| Mutex::new(String::new()));
|
||||||
@@ -156,7 +156,7 @@ async fn get_theme_list(data_dir: String) -> Vec<HashMap<String, String>> {
|
|||||||
|
|
||||||
map.insert("json".to_string(), theme_json);
|
map.insert("json".to_string(), theme_json);
|
||||||
map.insert("path".to_string(), path.to_str().unwrap().to_string());
|
map.insert("path".to_string(), path.to_str().unwrap().to_string());
|
||||||
|
|
||||||
// Push key-value pair containing "json" and "path"
|
// Push key-value pair containing "json" and "path"
|
||||||
themes.push(map);
|
themes.push(map);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,15 +4,15 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
use once_cell::sync::Lazy;
|
use once_cell::sync::Lazy;
|
||||||
use std::{sync::Mutex, str::FromStr};
|
use std::{str::FromStr, sync::Mutex};
|
||||||
|
|
||||||
use rcgen::*;
|
|
||||||
use hudsucker::{
|
use hudsucker::{
|
||||||
async_trait::async_trait,
|
async_trait::async_trait,
|
||||||
certificate_authority::RcgenAuthority,
|
certificate_authority::RcgenAuthority,
|
||||||
hyper::{Body, Request, Response},
|
hyper::{Body, Request, Response},
|
||||||
*,
|
*,
|
||||||
};
|
};
|
||||||
|
use rcgen::*;
|
||||||
|
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::net::SocketAddr;
|
use std::net::SocketAddr;
|
||||||
@@ -22,10 +22,11 @@ use rustls_pemfile as pemfile;
|
|||||||
use tauri::http::Uri;
|
use tauri::http::Uri;
|
||||||
|
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
use registry::{Hive, Data, Security};
|
use registry::{Data, Hive, Security};
|
||||||
|
|
||||||
async fn shutdown_signal() {
|
async fn shutdown_signal() {
|
||||||
tokio::signal::ctrl_c().await
|
tokio::signal::ctrl_c()
|
||||||
|
.await
|
||||||
.expect("Failed to install CTRL+C signal handler");
|
.expect("Failed to install CTRL+C signal handler");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -42,16 +43,18 @@ pub fn set_proxy_addr(addr: String) {
|
|||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl HttpHandler for ProxyHandler {
|
impl HttpHandler for ProxyHandler {
|
||||||
async fn handle_request(&mut self,
|
async fn handle_request(
|
||||||
_context: &HttpContext,
|
&mut self,
|
||||||
mut request: Request<Body>,
|
_context: &HttpContext,
|
||||||
|
mut request: Request<Body>,
|
||||||
) -> RequestOrResponse {
|
) -> RequestOrResponse {
|
||||||
let uri = request.uri().to_string();
|
let uri = request.uri().to_string();
|
||||||
let uri_path = request.uri().path();
|
let uri_path = request.uri().path();
|
||||||
|
|
||||||
if uri.contains("hoyoverse.com") || uri.contains("mihoyo.com") || uri.contains("yuanshen.com") {
|
if uri.contains("hoyoverse.com") || uri.contains("mihoyo.com") || uri.contains("yuanshen.com") {
|
||||||
// Create new URI.
|
// Create new URI.
|
||||||
let new_uri = Uri::from_str(format!("{}{}", SERVER.lock().unwrap(), uri_path).as_str()).unwrap();
|
let new_uri =
|
||||||
|
Uri::from_str(format!("{}{}", SERVER.lock().unwrap(), uri_path).as_str()).unwrap();
|
||||||
// Set request URI to the new one.
|
// Set request URI to the new one.
|
||||||
*request.uri_mut() = new_uri;
|
*request.uri_mut() = new_uri;
|
||||||
}
|
}
|
||||||
@@ -59,10 +62,13 @@ impl HttpHandler for ProxyHandler {
|
|||||||
RequestOrResponse::Request(request)
|
RequestOrResponse::Request(request)
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn handle_response(&mut self,
|
async fn handle_response(
|
||||||
_context: &HttpContext,
|
&mut self,
|
||||||
response: Response<Body>,
|
_context: &HttpContext,
|
||||||
) -> Response<Body> { response }
|
response: Response<Body>,
|
||||||
|
) -> Response<Body> {
|
||||||
|
response
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -70,20 +76,22 @@ impl HttpHandler for ProxyHandler {
|
|||||||
*/
|
*/
|
||||||
pub async fn create_proxy(proxy_port: u16, certificate_path: String) {
|
pub async fn create_proxy(proxy_port: u16, certificate_path: String) {
|
||||||
// Get the certificate and private key.
|
// Get the certificate and private key.
|
||||||
let mut private_key_bytes: &[u8] = &fs::read(format!("{}\\private.key", certificate_path)).expect("Could not read private key");
|
let mut private_key_bytes: &[u8] =
|
||||||
let mut ca_cert_bytes: &[u8] = &fs::read(format!("{}\\cert.crt", certificate_path)).expect("Could not read certificate");
|
&fs::read(format!("{}\\private.key", certificate_path)).expect("Could not read private key");
|
||||||
|
let mut ca_cert_bytes: &[u8] =
|
||||||
|
&fs::read(format!("{}\\cert.crt", certificate_path)).expect("Could not read certificate");
|
||||||
|
|
||||||
// Parse the private key and certificate.
|
// Parse the private key and certificate.
|
||||||
let private_key = rustls::PrivateKey(
|
let private_key = rustls::PrivateKey(
|
||||||
pemfile::pkcs8_private_keys(&mut private_key_bytes)
|
pemfile::pkcs8_private_keys(&mut private_key_bytes)
|
||||||
.expect("Failed to parse private key")
|
.expect("Failed to parse private key")
|
||||||
.remove(0)
|
.remove(0),
|
||||||
);
|
);
|
||||||
|
|
||||||
let ca_cert = rustls::Certificate(
|
let ca_cert = rustls::Certificate(
|
||||||
pemfile::certs(&mut ca_cert_bytes)
|
pemfile::certs(&mut ca_cert_bytes)
|
||||||
.expect("Failed to parse CA certificate")
|
.expect("Failed to parse CA certificate")
|
||||||
.remove(0)
|
.remove(0),
|
||||||
);
|
);
|
||||||
|
|
||||||
// Create the certificate authority.
|
// Create the certificate authority.
|
||||||
@@ -108,13 +116,23 @@ pub async fn create_proxy(proxy_port: u16, certificate_path: String) {
|
|||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
pub fn connect_to_proxy(proxy_port: u16) {
|
pub fn connect_to_proxy(proxy_port: u16) {
|
||||||
// Create 'ProxyServer' string.
|
// Create 'ProxyServer' string.
|
||||||
let server_string: String = format!("http=127.0.0.1:{};https=127.0.0.1:{}", proxy_port, proxy_port);
|
let server_string: String = format!(
|
||||||
|
"http=127.0.0.1:{};https=127.0.0.1:{}",
|
||||||
|
proxy_port, proxy_port
|
||||||
|
);
|
||||||
|
|
||||||
// Fetch the 'Internet Settings' registry key.
|
// Fetch the 'Internet Settings' registry key.
|
||||||
let settings = Hive::CurrentUser.open(r"Software\Microsoft\Windows\CurrentVersion\Internet Settings", Security::Write).unwrap();
|
let settings = Hive::CurrentUser
|
||||||
|
.open(
|
||||||
|
r"Software\Microsoft\Windows\CurrentVersion\Internet Settings",
|
||||||
|
Security::Write,
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
// Set registry values.
|
// Set registry values.
|
||||||
settings.set_value("ProxyServer", &Data::String(server_string.parse().unwrap())).unwrap();
|
settings
|
||||||
|
.set_value("ProxyServer", &Data::String(server_string.parse().unwrap()))
|
||||||
|
.unwrap();
|
||||||
settings.set_value("ProxyEnable", &Data::U32(1)).unwrap();
|
settings.set_value("ProxyEnable", &Data::U32(1)).unwrap();
|
||||||
|
|
||||||
println!("Connected to the proxy.");
|
println!("Connected to the proxy.");
|
||||||
@@ -131,7 +149,12 @@ pub fn connect_to_proxy(_proxy_port: u16) {
|
|||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
pub fn disconnect_from_proxy() {
|
pub fn disconnect_from_proxy() {
|
||||||
// Fetch the 'Internet Settings' registry key.
|
// Fetch the 'Internet Settings' registry key.
|
||||||
let settings = Hive::CurrentUser.open(r"Software\Microsoft\Windows\CurrentVersion\Internet Settings", Security::Write).unwrap();
|
let settings = Hive::CurrentUser
|
||||||
|
.open(
|
||||||
|
r"Software\Microsoft\Windows\CurrentVersion\Internet Settings",
|
||||||
|
Security::Write,
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
// Set registry values.
|
// Set registry values.
|
||||||
settings.set_value("ProxyEnable", &Data::U32(0)).unwrap();
|
settings.set_value("ProxyEnable", &Data::U32(0)).unwrap();
|
||||||
@@ -157,7 +180,7 @@ pub fn generate_ca_files(path: &Path) {
|
|||||||
details.push(DnType::OrganizationName, "Grasscutters");
|
details.push(DnType::OrganizationName, "Grasscutters");
|
||||||
details.push(DnType::CountryName, "CN");
|
details.push(DnType::CountryName, "CN");
|
||||||
details.push(DnType::LocalityName, "CN");
|
details.push(DnType::LocalityName, "CN");
|
||||||
|
|
||||||
// Set details in the parameter.
|
// Set details in the parameter.
|
||||||
params.distinguished_name = details;
|
params.distinguished_name = details;
|
||||||
// Set other properties.
|
// Set other properties.
|
||||||
@@ -165,9 +188,9 @@ pub fn generate_ca_files(path: &Path) {
|
|||||||
params.key_usages = vec![
|
params.key_usages = vec![
|
||||||
KeyUsagePurpose::DigitalSignature,
|
KeyUsagePurpose::DigitalSignature,
|
||||||
KeyUsagePurpose::KeyCertSign,
|
KeyUsagePurpose::KeyCertSign,
|
||||||
KeyUsagePurpose::CrlSign
|
KeyUsagePurpose::CrlSign,
|
||||||
];
|
];
|
||||||
|
|
||||||
// Create certificate.
|
// Create certificate.
|
||||||
let cert = Certificate::from_params(params).unwrap();
|
let cert = Certificate::from_params(params).unwrap();
|
||||||
let cert_crt = cert.serialize_pem().unwrap();
|
let cert_crt = cert.serialize_pem().unwrap();
|
||||||
@@ -176,26 +199,37 @@ pub fn generate_ca_files(path: &Path) {
|
|||||||
// Make certificate directory.
|
// Make certificate directory.
|
||||||
let cert_dir = path.join("ca");
|
let cert_dir = path.join("ca");
|
||||||
match fs::create_dir(&cert_dir) {
|
match fs::create_dir(&cert_dir) {
|
||||||
Ok(_) => {},
|
Ok(_) => {}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
println!("{}", e);
|
println!("{}", e);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Write the certificate to a file.
|
// Write the certificate to a file.
|
||||||
let cert_path = cert_dir.join("cert.crt");
|
let cert_path = cert_dir.join("cert.crt");
|
||||||
match fs::write(&cert_path, cert_crt) {
|
match fs::write(&cert_path, cert_crt) {
|
||||||
Ok(_) => println!("Wrote certificate to {}", cert_path.to_str().unwrap()),
|
Ok(_) => println!("Wrote certificate to {}", cert_path.to_str().unwrap()),
|
||||||
Err(e) => println!("Error writing certificate to {}: {}", cert_path.to_str().unwrap(), e),
|
Err(e) => println!(
|
||||||
|
"Error writing certificate to {}: {}",
|
||||||
|
cert_path.to_str().unwrap(),
|
||||||
|
e
|
||||||
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write the private key to a file.
|
// Write the private key to a file.
|
||||||
let private_key_path = cert_dir.join("private.key");
|
let private_key_path = cert_dir.join("private.key");
|
||||||
match fs::write(&private_key_path, private_key) {
|
match fs::write(&private_key_path, private_key) {
|
||||||
Ok(_) => println!("Wrote private key to {}", private_key_path.to_str().unwrap()),
|
Ok(_) => println!(
|
||||||
Err(e) => println!("Error writing private key to {}: {}", private_key_path.to_str().unwrap(), e),
|
"Wrote private key to {}",
|
||||||
|
private_key_path.to_str().unwrap()
|
||||||
|
),
|
||||||
|
Err(e) => println!(
|
||||||
|
"Error writing private key to {}: {}",
|
||||||
|
private_key_path.to_str().unwrap(),
|
||||||
|
e
|
||||||
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
// Install certificate into the system's Root CA store.
|
// Install certificate into the system's Root CA store.
|
||||||
install_ca_files(&cert_path);
|
install_ca_files(&cert_path);
|
||||||
}
|
}
|
||||||
@@ -205,13 +239,27 @@ pub fn generate_ca_files(path: &Path) {
|
|||||||
*/
|
*/
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
pub fn install_ca_files(cert_path: &Path) {
|
pub fn install_ca_files(cert_path: &Path) {
|
||||||
crate::system_helpers::run_command("certutil", vec!["-user", "-addstore", "Root", cert_path.to_str().unwrap()]);
|
crate::system_helpers::run_command(
|
||||||
|
"certutil",
|
||||||
|
vec!["-user", "-addstore", "Root", cert_path.to_str().unwrap()],
|
||||||
|
);
|
||||||
println!("Installed certificate.");
|
println!("Installed certificate.");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
pub fn install_ca_files(cert_path: &Path) {
|
pub fn install_ca_files(cert_path: &Path) {
|
||||||
crate::system_helpers::run_command("security", vec!["add-trusted-cert", "-d", "-r", "trustRoot", "-k", "/Library/Keychains/System.keychain", cert_path.to_str().unwrap()]);
|
crate::system_helpers::run_command(
|
||||||
|
"security",
|
||||||
|
vec![
|
||||||
|
"add-trusted-cert",
|
||||||
|
"-d",
|
||||||
|
"-r",
|
||||||
|
"trustRoot",
|
||||||
|
"-k",
|
||||||
|
"/Library/Keychains/System.keychain",
|
||||||
|
cert_path.to_str().unwrap(),
|
||||||
|
],
|
||||||
|
);
|
||||||
println!("Installed certificate.");
|
println!("Installed certificate.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,4 +5,4 @@ use serde::Deserialize;
|
|||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
pub(crate) struct APIQuery {
|
pub(crate) struct APIQuery {
|
||||||
pub bg_file: String,
|
pub bg_file: String,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,8 +11,7 @@ pub fn run_program(path: String) {
|
|||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub fn run_command(program: &str, args: Vec<&str>) {
|
pub fn run_command(program: &str, args: Vec<&str>) {
|
||||||
cmd(program, args).run()
|
cmd(program, args).run().expect("Failed to run command");
|
||||||
.expect("Failed to run command");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
@@ -24,7 +23,10 @@ pub fn run_jar(path: String, execute_in: String, java_path: String) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Open the program from the specified path.
|
// Open the program from the specified path.
|
||||||
match open::with(format!("/k cd /D \"{}\" & {}", &execute_in, &command), "C:\\Windows\\System32\\cmd.exe") {
|
match open::with(
|
||||||
|
format!("/k cd /D \"{}\" & {}", &execute_in, &command),
|
||||||
|
"C:\\Windows\\System32\\cmd.exe",
|
||||||
|
) {
|
||||||
Ok(_) => (),
|
Ok(_) => (),
|
||||||
Err(e) => println!("Failed to open jar ({} from {}): {}", &path, &execute_in, e),
|
Err(e) => println!("Failed to open jar ({} from {}): {}", &path, &execute_in, e),
|
||||||
};
|
};
|
||||||
@@ -39,7 +41,6 @@ pub fn open_in_browser(url: String) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
pub fn install_location() -> String {
|
pub fn install_location() -> String {
|
||||||
let mut exe_path = std::env::current_exe().unwrap();
|
let mut exe_path = std::env::current_exe().unwrap();
|
||||||
|
|||||||
@@ -23,21 +23,18 @@ pub fn unzip(window: tauri::Window, zipfile: String, destpath: String) {
|
|||||||
|
|
||||||
match zip_extract::extract(&f, &full_path, true) {
|
match zip_extract::extract(&f, &full_path, true) {
|
||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
println!("Extracted zip file to: {}", full_path.to_str().unwrap_or("Error"));
|
println!(
|
||||||
|
"Extracted zip file to: {}",
|
||||||
|
full_path.to_str().unwrap_or("Error")
|
||||||
|
);
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
println!("Failed to extract zip file: {}", e);
|
println!("Failed to extract zip file: {}", e);
|
||||||
let mut res_hash = std::collections::HashMap::new();
|
let mut res_hash = std::collections::HashMap::new();
|
||||||
|
|
||||||
res_hash.insert(
|
res_hash.insert("error".to_string(), e.to_string());
|
||||||
"error".to_string(),
|
|
||||||
e.to_string(),
|
|
||||||
);
|
|
||||||
|
|
||||||
res_hash.insert(
|
res_hash.insert("path".to_string(), zipfile.to_string());
|
||||||
"path".to_string(),
|
|
||||||
zipfile.to_string(),
|
|
||||||
);
|
|
||||||
|
|
||||||
window.emit("download_error", &res_hash).unwrap();
|
window.emit("download_error", &res_hash).unwrap();
|
||||||
}
|
}
|
||||||
@@ -50,7 +47,9 @@ pub fn unzip(window: tauri::Window, zipfile: String, destpath: String) {
|
|||||||
|
|
||||||
// If the contents is a jar file, emit that we have extracted a new jar file
|
// If the contents is a jar file, emit that we have extracted a new jar file
|
||||||
if name.ends_with(".jar") {
|
if name.ends_with(".jar") {
|
||||||
window.emit("jar_extracted", destpath.to_string() + name).unwrap();
|
window
|
||||||
|
.emit("jar_extracted", destpath.to_string() + name)
|
||||||
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete zip file
|
// Delete zip file
|
||||||
@@ -65,4 +64,4 @@ pub fn unzip(window: tauri::Window, zipfile: String, destpath: String) {
|
|||||||
|
|
||||||
window.emit("extract_end", &zipfile).unwrap();
|
window.emit("extract_end", &zipfile).unwrap();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,12 @@ use reqwest::header::USER_AGENT;
|
|||||||
pub(crate) async fn query(site: &str) -> String {
|
pub(crate) async fn query(site: &str) -> String {
|
||||||
let client = reqwest::Client::new();
|
let client = reqwest::Client::new();
|
||||||
|
|
||||||
let response = client.get(site).header(USER_AGENT, "cultivation").send().await.unwrap();
|
let response = client
|
||||||
|
.get(site)
|
||||||
|
.header(USER_AGENT, "cultivation")
|
||||||
|
.send()
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
response.text().await.unwrap()
|
response.text().await.unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -12,7 +17,12 @@ pub(crate) async fn valid_url(url: String) -> bool {
|
|||||||
// Check if we get a 200 response
|
// Check if we get a 200 response
|
||||||
let client = reqwest::Client::new();
|
let client = reqwest::Client::new();
|
||||||
|
|
||||||
let response = client.get(url).header(USER_AGENT, "cultivation").send().await.unwrap();
|
let response = client
|
||||||
|
.get(url)
|
||||||
|
.header(USER_AGENT, "cultivation")
|
||||||
|
.send()
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
response.status().as_str() == "200"
|
response.status().as_str() == "200"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ class App extends React.Component<IProps, IState> {
|
|||||||
console.log(payload)
|
console.log(payload)
|
||||||
})
|
})
|
||||||
|
|
||||||
listen('jar_extracted', ({ payload }) => {
|
listen('jar_extracted', ({ payload }: { payload: string}) => {
|
||||||
setConfigOption('grasscutter_path', payload)
|
setConfigOption('grasscutter_path', payload)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ function none() {
|
|||||||
alert('none')
|
alert('none')
|
||||||
}
|
}
|
||||||
|
|
||||||
class Debug extends React.Component<any, any>{
|
class Debug extends React.Component{
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<div className="App">
|
<div className="App">
|
||||||
|
|||||||
@@ -13,10 +13,6 @@ import Akebi from '../../resources/icons/akebi.svg'
|
|||||||
import './ServerLaunchSection.css'
|
import './ServerLaunchSection.css'
|
||||||
import {dataDir} from '@tauri-apps/api/path'
|
import {dataDir} from '@tauri-apps/api/path'
|
||||||
|
|
||||||
interface IProps {
|
|
||||||
[key: string]: any
|
|
||||||
}
|
|
||||||
|
|
||||||
interface IState {
|
interface IState {
|
||||||
grasscutterEnabled: boolean;
|
grasscutterEnabled: boolean;
|
||||||
buttonLabel: string;
|
buttonLabel: string;
|
||||||
@@ -35,8 +31,8 @@ interface IState {
|
|||||||
swag: boolean;
|
swag: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class ServerLaunchSection extends React.Component<IProps, IState> {
|
export default class ServerLaunchSection extends React.Component<{}, IState> {
|
||||||
constructor(props: IProps) {
|
constructor(props: {}) {
|
||||||
super(props)
|
super(props)
|
||||||
|
|
||||||
this.state = {
|
this.state = {
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import closeIcon from '../../resources/icons/close.svg'
|
|||||||
import minIcon from '../../resources/icons/min.svg'
|
import minIcon from '../../resources/icons/min.svg'
|
||||||
import cogBtn from '../../resources/icons/cog.svg'
|
import cogBtn from '../../resources/icons/cog.svg'
|
||||||
import downBtn from '../../resources/icons/download.svg'
|
import downBtn from '../../resources/icons/download.svg'
|
||||||
import gameBtn from '../../resources/icons/game.svg'
|
|
||||||
|
|
||||||
import Tr from '../../utils/language'
|
import Tr from '../../utils/language'
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import './BigButton.css'
|
|||||||
|
|
||||||
interface IProps {
|
interface IProps {
|
||||||
children: React.ReactNode;
|
children: React.ReactNode;
|
||||||
onClick: () => any;
|
onClick: () => unknown;
|
||||||
id: string;
|
id: string;
|
||||||
disabled?: boolean;
|
disabled?: boolean;
|
||||||
}
|
}
|
||||||
@@ -23,7 +23,7 @@ export default class BigButton extends React.Component<IProps, IState> {
|
|||||||
this.handleClick = this.handleClick.bind(this)
|
this.handleClick = this.handleClick.bind(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
static getDerivedStateFromProps(props: IProps, state: IState) {
|
static getDerivedStateFromProps(props: IProps, _state: IState) {
|
||||||
return {
|
return {
|
||||||
disabled: props.disabled
|
disabled: props.disabled
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,9 +12,7 @@ interface IProps {
|
|||||||
id?: string;
|
id?: string;
|
||||||
clearable?: boolean;
|
clearable?: boolean;
|
||||||
customClearBehaviour?: () => void;
|
customClearBehaviour?: () => void;
|
||||||
style?: {
|
style?: React.CSSProperties;
|
||||||
[key: string]: any;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
interface IState {
|
interface IState {
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import { dataDir } from '@tauri-apps/api/path'
|
|||||||
|
|
||||||
import './Downloads.css'
|
import './Downloads.css'
|
||||||
import Divider from './Divider'
|
import Divider from './Divider'
|
||||||
import { getConfigOption, setConfigOption } from '../../../utils/configuration'
|
import { getConfigOption } from '../../../utils/configuration'
|
||||||
import { invoke } from '@tauri-apps/api'
|
import { invoke } from '@tauri-apps/api'
|
||||||
import { listen } from '@tauri-apps/api/event'
|
import { listen } from '@tauri-apps/api/event'
|
||||||
import HelpButton from '../common/HelpButton'
|
import HelpButton from '../common/HelpButton'
|
||||||
@@ -183,7 +183,7 @@ export default class Downloads extends React.Component<IProps, IState> {
|
|||||||
grasscutter_downloading: this.props.downloadManager.downloadingJar(),
|
grasscutter_downloading: this.props.downloadManager.downloadingJar(),
|
||||||
resources_downloading: this.props.downloadManager.downloadingResources(),
|
resources_downloading: this.props.downloadManager.downloadingResources(),
|
||||||
repo_downloading: this.props.downloadManager.downloadingRepo(),
|
repo_downloading: this.props.downloadManager.downloadingRepo(),
|
||||||
grasscutter_set: gc_path && gc_path !== '',
|
grasscutter_set: gc_path !== '',
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,8 +11,28 @@ interface IProps {
|
|||||||
|
|
||||||
interface IState {
|
interface IState {
|
||||||
selected: string;
|
selected: string;
|
||||||
news: any;
|
news?: JSX.Element;
|
||||||
commitList: any;
|
commitList?: JSX.Element[];
|
||||||
|
}
|
||||||
|
|
||||||
|
interface GrasscutterAPIResponse {
|
||||||
|
commits: {
|
||||||
|
gc_stable: CommitResponse[];
|
||||||
|
gc_dev: CommitResponse[];
|
||||||
|
cultivation: CommitResponse[];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
interface CommitResponse {
|
||||||
|
sha: string;
|
||||||
|
commit: Commit;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Commit {
|
||||||
|
author: {
|
||||||
|
name: string;
|
||||||
|
};
|
||||||
|
message: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default class NewsSection extends React.Component<IProps, IState> {
|
export default class NewsSection extends React.Component<IProps, IState> {
|
||||||
@@ -21,8 +41,6 @@ export default class NewsSection extends React.Component<IProps, IState> {
|
|||||||
|
|
||||||
this.state = {
|
this.state = {
|
||||||
selected: props.selected || 'commits',
|
selected: props.selected || 'commits',
|
||||||
news: null,
|
|
||||||
commitList: null
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.setSelected = this.setSelected.bind(this)
|
this.setSelected = this.setSelected.bind(this)
|
||||||
@@ -42,40 +60,41 @@ export default class NewsSection extends React.Component<IProps, IState> {
|
|||||||
|
|
||||||
async showLatestCommits() {
|
async showLatestCommits() {
|
||||||
if (!this.state.commitList) {
|
if (!this.state.commitList) {
|
||||||
const commits: string = await invoke('req_get', { url: 'https://api.grasscutter.io/cultivation/query' })
|
const response: string = await invoke('req_get', { url: 'https://api.grasscutter.io/cultivation/query' })
|
||||||
let obj
|
let grasscutterApiResponse: GrasscutterAPIResponse | null = null
|
||||||
|
|
||||||
try {
|
try {
|
||||||
obj = JSON.parse(commits)
|
grasscutterApiResponse = JSON.parse(response)
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
obj = {}
|
grasscutterApiResponse = null
|
||||||
}
|
}
|
||||||
|
|
||||||
// If it didn't work, use official API
|
let commits: CommitResponse[]
|
||||||
if (!obj.commits) {
|
if (grasscutterApiResponse?.commits == null) {
|
||||||
const commits: string = await invoke('req_get', { url: 'https://api.github.com/repos/Grasscutters/Grasscutter/commits' })
|
// If it didn't work, use official API
|
||||||
obj = JSON.parse(commits)
|
const response: string = await invoke('req_get', { url: 'https://api.github.com/repos/Grasscutters/Grasscutter/commits' })
|
||||||
|
commits = JSON.parse(response)
|
||||||
} else {
|
} else {
|
||||||
obj = obj.commits.gc_stable
|
commits = grasscutterApiResponse.commits.gc_stable
|
||||||
}
|
}
|
||||||
|
|
||||||
// Probably rate-limited
|
// Probably rate-limited
|
||||||
if (!Array.isArray(obj)) return
|
if (!Array.isArray(commits)) return
|
||||||
|
|
||||||
// Get only first 5
|
// Get only first 5
|
||||||
const commitsList = obj.slice(0, 10)
|
const commitsList = commits.slice(0, 10)
|
||||||
const commitsListHtml = commitsList.map((commit: any) => {
|
const commitsListHtml = commitsList.map((commitResponse: CommitResponse) => {
|
||||||
return (
|
return (
|
||||||
<tr className="Commit" id="newsCommitsTable" key={commit.sha}>
|
<tr className="Commit" id="newsCommitsTable" key={commitResponse.sha}>
|
||||||
<td className="CommitAuthor"><span>{commit.commit.author.name}</span></td>
|
<td className="CommitAuthor"><span>{commitResponse.commit.author.name}</span></td>
|
||||||
<td className="CommitMessage"><span>{commit.commit.message}</span></td>
|
<td className="CommitMessage"><span>{commitResponse.commit.message}</span></td>
|
||||||
</tr>
|
</tr>
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
this.setState({
|
this.setState({
|
||||||
commitList: commitsListHtml,
|
commitList: commitsListHtml,
|
||||||
news: commitsListHtml
|
news: <>{commitsListHtml}</>
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -83,12 +102,16 @@ export default class NewsSection extends React.Component<IProps, IState> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async showNews() {
|
async showNews() {
|
||||||
let news = <tr></tr>
|
let news: JSX.Element | JSX.Element[] = <tr></tr>
|
||||||
|
|
||||||
switch(this.state.selected) {
|
switch(this.state.selected) {
|
||||||
case 'commits':
|
case 'commits': {
|
||||||
news = await this.showLatestCommits()
|
const commits = await this.showLatestCommits()
|
||||||
|
if (commits != null) {
|
||||||
|
news = commits
|
||||||
|
}
|
||||||
break
|
break
|
||||||
|
}
|
||||||
|
|
||||||
case 'latest_version':
|
case 'latest_version':
|
||||||
news = <tr><td>Latest version</td></tr>
|
news = <tr><td>Latest version</td></tr>
|
||||||
@@ -100,7 +123,7 @@ export default class NewsSection extends React.Component<IProps, IState> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.setState({
|
this.setState({
|
||||||
news
|
news: <>{news}</>
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -49,16 +49,16 @@ export interface Configuration {
|
|||||||
akebi_path?: string
|
akebi_path?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function setConfigOption(key: string, value: any): Promise<void> {
|
export async function setConfigOption<K extends keyof Configuration>(key: K, value: Configuration[K]): Promise<void> {
|
||||||
const config: any = await getConfig()
|
const config = await getConfig()
|
||||||
config[key] = value
|
config[key] = value
|
||||||
|
|
||||||
await saveConfig(<Configuration> config)
|
await saveConfig(<Configuration> config)
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getConfigOption(key: string): Promise<any> {
|
export async function getConfigOption<K extends keyof Configuration>(key: K): Promise<Configuration[K]> {
|
||||||
const config: any = await getConfig()
|
const config = await getConfig()
|
||||||
const defaults: any = defaultConfig
|
const defaults = defaultConfig
|
||||||
|
|
||||||
return config[key] || defaults[key]
|
return config[key] || defaults[key]
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user