Skip to content

Commit

Permalink
v1.2.0-dev.13
Browse files Browse the repository at this point in the history
  • Loading branch information
btjawa committed Aug 27, 2024
1 parent bd34945 commit c7e2495
Show file tree
Hide file tree
Showing 29 changed files with 917 additions and 607 deletions.
1 change: 0 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,5 @@
<div id="app"></div>
<script type="module" src="./src/lib/gt.0.4.9.js"></script>
<script type="module" src="./src/main.ts"></script>
<script type="module" src="./src/services/updater.ts"></script>
</body>
</html>
18 changes: 11 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bilitools",
"version": "1.1.2",
"version": "1.2.0-dev.12",
"description": "BiliTools - bilibili工具箱",
"type": "module",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bilitools"
version = "1.1.2"
version = "1.2.0-dev.12"
description = "BiliTools - bilibili工具箱"
authors = ["btjawa"]
edition = "2021"
Expand Down
14 changes: 14 additions & 0 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ use services::{*, storage::*};
#[cfg(target_os = "macos")]
use window_vibrancy::{apply_vibrancy, NSVisualEffectMaterial};

#[cfg(target_os = "windows")]
use window_vibrancy::{apply_acrylic, apply_blur};

lazy_static! {
static ref WORKING_DIR: PathBuf = dirs_next::data_local_dir().unwrap().join("com.btjawa.bilitools");
static ref DOWNLOAD_DIR: Arc<RwLock<PathBuf>> = Arc::new(RwLock::new(dirs_next::desktop_dir().unwrap()));
Expand Down Expand Up @@ -224,6 +227,17 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
});
#[cfg(target_os = "macos")]
apply_vibrancy(&window, NSVisualEffectMaterial::HudWindow, None, None)?;
#[cfg(target_os = "windows")]
match tauri_plugin_os::version() {
tauri_plugin_os::Version::Semantic(major, minor, build) => {
if build > 22000 || (major == 10 && build <= 18362) { // Windows 10 & 11 Early Version
apply_acrylic(&window, Some((18, 18, 18, 160)))?;
} else if (build > 18362 && build <= 22000) || (major == 6 && minor == 1) { // Windows 7 & Windows 10 v1903+ to Windows 11 22000
apply_blur(&window, Some((18, 18, 18, 160)))?;
}
},
_ => log::error!("Failed to determine OS version"),
}
Ok(())
})
.invoke_handler(tauri::generate_handler![ready, init, rw_config,
Expand Down
66 changes: 49 additions & 17 deletions src-tauri/src/services/aria2c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub struct VideoInfo {
pub output_path: PathBuf,
pub tasks: Vec<DownloadTask>,
pub action: String,
pub media_data: Value
pub queue_info: QueueInfo
}

#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, FromJsonQueryResult)]
Expand All @@ -41,6 +41,34 @@ pub struct DownloadTask {
pub file_type: String,
}

#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, FromJsonQueryResult)]
pub struct QueueInfo {
pub title: String,
pub display_name: String,
pub cover: String,
pub desc: String,
pub duration: i32,
pub id: i32,
pub cid: i32,
pub eid: i32,
pub ss_title: String,
pub urls: QueueInfoURLs,
pub time: String,
pub gids: Option<QueueInfoGIDs>
}

#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, FromJsonQueryResult)]
pub struct QueueInfoURLs {
video: Vec<String>,
audio: Vec<String>,
}

#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, FromJsonQueryResult)]
pub struct QueueInfoGIDs {
vgid: Option<String>,
agid: Option<String>,
}

pub fn init() -> Result<(), String> {
let start_port = 6800;
let end_port = 65535;
Expand Down Expand Up @@ -94,35 +122,39 @@ pub fn kill() -> Result<(), String> {
}

#[tauri::command]
pub async fn push_back_queue(
video_url: Option<Vec<String>>, audio_url: Option<Vec<String>>,
action: String, media_data: Value, date: String
) -> Result<Value, String> {
pub async fn push_back_queue(queue_info: QueueInfo) -> Result<Value, String> {
let mut tasks = vec![];
let client = init_client().await.map_err(|e| handle_err(e))?;
let ss_dir = &media_data.get("ss_title").unwrap().as_str().unwrap().to_string();
let display_name = media_data.get("display_name").unwrap().as_str().unwrap().to_string();
for (url, file_type) in vec![(video_url, "video"), (audio_url, "audio")].into_iter().filter_map(|(url, t)| url.map(|u| (u, t))) {
let ss_dir = &queue_info.ss_title;
let display_name = &queue_info.display_name;
let urls = queue_info.urls.clone();
let action = if !urls.video.is_empty() && !urls.audio.is_empty() { "media" }
else if !urls.video.is_empty() { "video" } else { "audio" }.into();

for (url, file_type) in vec![(urls.video, "video"), (urls.audio, "audio")].into_iter() {
let purl = reqwest::Url::parse(&url[0]).map_err(|e| handle_err(e))?;
let filename = purl.path_segments().unwrap().last().unwrap();
let path = TEMP_DIR.read().unwrap().join("com.btjawa.bilitools").join(format!("{}_{}", date, filename)).join(filename);
let path = TEMP_DIR.read().unwrap().join("com.btjawa.bilitools").join(format!("{}_{}", queue_info.time, filename)).join(filename);
let init_payload = json!({
"jsonrpc": "2.0",
"method": "aria2.addUri",
"id": "1",
"params": [
format!("token:{}", *SECRET.read().unwrap()),
url,
{"dir": path.parent().unwrap().to_str().unwrap(), "out": path.file_name().unwrap().to_str().unwrap()}
{
"dir": path.parent().unwrap().to_str().unwrap(),
"out": path.file_name().unwrap().to_str().unwrap()
}
]
});
let init_resp = client
let response = client
.post(format!("http://localhost:{}/jsonrpc", ARIA2C_PORT.read().unwrap()))
.json(&init_payload)
.send().await.map_err(|e| handle_err(e))?;

let init_resp_data: Value = init_resp.json().await.map_err(|e| handle_err(e))?;
let gid = init_resp_data["result"].as_str().unwrap().to_string();
let body: Value = response.json().await.map_err(|e| handle_err(e))?;
let gid = body["result"].as_str().unwrap().to_string();
handle_download(gid.clone(), "pause").await.map_err(|e| handle_err(e))?;
tasks.push(DownloadTask {
gid, url, path,
Expand All @@ -132,17 +164,17 @@ pub async fn push_back_queue(
}
let vgid = tasks.iter().find(|t| t.file_type == "video").map(|t| &*t.gid).unwrap_or_default();
let agid = tasks.iter().find(|t| t.file_type == "audio").map(|t| &*t.gid).unwrap_or_default();
let gid: Value = json!({"vgid": vgid, "agid": agid});
let gids: Value = json!({"vgid": vgid, "agid": agid});
let info = VideoInfo {
gid: gid.clone(),
gid: gids.clone(),
display_name: display_name.clone(),
video_path: tasks.iter().find(|t| t.file_type == "video").map(|t| t.path.clone()).unwrap_or_default(),
audio_path: tasks.iter().find(|t| t.file_type == "audio").map(|t| t.path.clone()).unwrap_or_default(),
output_path: DOWNLOAD_DIR.read().unwrap().join(ss_dir.clone()),
tasks, action, media_data
tasks, action, queue_info
};
update_queue("push", Some(info), None).await;
Ok(gid)
Ok(gids)
}

#[tauri::command]
Expand Down
4 changes: 2 additions & 2 deletions src-tauri/src/services/login.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ pub async fn refresh_cookie(refresh_csrf: &str) -> Result<String, String> {
return Ok("Successfully refreshed Cookie".into());
}
_ => {
log::error!("{}", response_data["data"]["message"]);
return Err(format!("{}", response_data["data"]["message"]).into());
log::error!("{}, {}", response_data["data"]["code"], response_data["data"]["message"]);
return Err(format!("{}, {}", response_data["data"]["code"], response_data["data"]["message"]).into());
},
}
}
Expand Down
12 changes: 0 additions & 12 deletions src-tauri/src/services/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,6 @@ lazy_static! {

pub async fn init(app_handle: AppHandle<Wry>) -> Result<(), Box<dyn Error>> {
APP_HANDLE.set(app_handle).unwrap();
#[cfg(target_os = "windows")]
match tauri_plugin_os::version() {
tauri_plugin_os::Version::Semantic(major, minor, build) => {
use window_vibrancy::{apply_acrylic, apply_blur};
if build > 22000 || (major == 10 && build <= 18362) { // Windows 10 & 11 Early Version
apply_acrylic(&window, Some((18, 18, 18, 160)))?;
} else if (build > 18362 && build <= 22000) || (major == 6 && minor == 1) { // Windows 7 & Windows 10 v1903+ to Windows 11 22000
apply_blur(&window, Some((18, 18, 18, 160)))?;
}
},
_ => log::error!("Failed to determine OS version"),
}
aria2c::init()?;
storage::init().await?;
login::init();
Expand Down
2 changes: 1 addition & 1 deletion src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"productName": "BiliTools",
"version": "1.1.2",
"version": "1.2.0-dev.12",
"identifier": "com.btjawa.bilitools",
"build": {
"beforeDevCommand": "npm run dev",
Expand Down
10 changes: 7 additions & 3 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,19 @@ export default {
},
methods: {
showMenu(e: MouseEvent) {
(this.$refs.contextMenu as any).showMenu(e);
(this.$refs.contextMenu as InstanceType<typeof ContextMenu>).showMenu(e);
}
},
mounted() {
this.$router.push("/");
this.$store.dispatch('init');
listen('headers', (e) => this.$store.commit('updateState', { 'data.headers': e.payload }));
listen('headers', (e) => {
this.$store.commit('updateState', { 'data.headers': e.payload });
});
listen('settings', (e) => {
this.$store.commit('updateState', { settings: e.payload })
});
listen('error', (e) => iziError(e.payload as string));
listen('settings', (e) => this.$store.commit('updateState', { settings: e.payload }) )
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/assets/css/fonts.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
@import url('../fonts/font-awesome/all.css');
@import url('../fonts/HarmonyOS_Sans_SC_Regular/font.min.css');
@import url('../fonts/bcc-iconfont/font.min.css');
@import url('../fonts/iconfont/font.min.css');
@import url('../fonts/bcc-iconfont/font.min.css');
3 changes: 2 additions & 1 deletion src/assets/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
:root {
--primary-color: rgb(212,78,125);
--content-color: rgb(233,233,233);
--block-color: #333;
--desc-color: #a2a7ae;
--block-radius: 8px;
--split-color: #c4c4c433;
--block-color: #333;
--section-color: #1f1f1f;
}

Expand All @@ -39,6 +39,7 @@ body {

* {
font-family: "HarmonyOS_Sans_SC_Regular";
/* font-family: ui-sans-serif, -apple-system, system-ui, "Segoe UI", Roboto, Ubuntu, Cantarell, "Noto Sans", sans-serif, Helvetica, "Apple Color Emoji", Arial, "Segoe UI Emoji", "Segoe UI Symbol"; */
box-sizing: border-box;
margin: 0;
padding: 0;
Expand Down
1 change: 0 additions & 1 deletion src/assets/fonts/iconfont/font.min.css

This file was deleted.

Binary file removed src/assets/fonts/iconfont/iconfont.ttf
Binary file not shown.
17 changes: 10 additions & 7 deletions src/components/ContextMenu.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<div ref="contextMenu" class="context-menu" v-show="active" @contextmenu.prevent
:style="{ opacity: opacity, top: pos.y + 'px', left: pos.x + 'px' }">
@transitionend.prevent :style="{ opacity, top: pos.y + 'px', left: pos.x + 'px' }">
<div @click="handleAction('cut')" class="context-menu-item cut">
<i class="fa-light fa-cut context-menu-item-icon"></i>
剪切<a class="context-menu-item-key">Ctrl+X</a>
Expand Down Expand Up @@ -37,20 +37,21 @@ export default defineComponent({
active: false,
pos: { x: 0, y: 0 },
opacity: 0,
activeElement: null as HTMLInputElement | HTMLTextAreaElement | null,
selection: '',
}
},
methods: {
async handleAction(action: string) {
const activeElement = document.activeElement as HTMLInputElement | HTMLTextAreaElement | null;
switch (action) {
case 'cut':
navigator.clipboard.writeText(this.handleTextUpdate(activeElement));
navigator.clipboard.writeText(this.handleTextUpdate(this.activeElement));
break;
case 'copy':
navigator.clipboard.writeText(window.getSelection()?.toString() || "");
navigator.clipboard.writeText(this.selection);
break;
case 'paste':
this.handleTextUpdate(activeElement, await navigator.clipboard.readText() || "");
this.handleTextUpdate(this.activeElement, await navigator.clipboard.readText() || "");
break;
case 'bilibili':
utils.bilibili(null, document.querySelector('.search__input'));
Expand All @@ -68,11 +69,13 @@ export default defineComponent({
element.value = element.value.substring(0, start) + text + element.value.substring(end);
const pos = start + text.length;
element.setSelectionRange(pos, pos);
return element.value.substring(start, end);
return element.value.substring(start, end) || this.selection;
}
return text;
},
showMenu(e: MouseEvent) {
this.activeElement = document.activeElement as HTMLInputElement | HTMLTextAreaElement | null;
this.selection = window.getSelection()?.toString() || "";
if (this.active) this.hideMenu();
requestAnimationFrame(() => {
this.active = true;
Expand All @@ -98,7 +101,7 @@ export default defineComponent({
border-radius: 8px;
background-color: #2c2c2c;
border: solid 1px #666666d3;
z-index: 10;
z-index: 99;
flex-direction: column;
flex-wrap: wrap;
position: fixed;
Expand Down
Loading

0 comments on commit c7e2495

Please sign in to comment.