From 9d7a3d7da31fd8ae94cff4dc759fb72d104714b8 Mon Sep 17 00:00:00 2001 From: Haojian Ning <670625410@qq.com> Date: Fri, 10 Jan 2025 12:50:18 +0800 Subject: [PATCH] 1.2.1 update --- subocr-swiftui/privacy.README.md | 3 - .../subocr-macos/views/MainView.swift | 4 +- subocr-tauri-ui/src-tauri/build.rs | 66 ++++++++++------ subocr-tauri-ui/src-tauri/src/lib.rs | 76 ++++++++++++------- subocr-tauri-ui/src-tauri/src/subocr_abi.rs | 2 +- subocr-tauri-ui/src-tauri/tauri.conf.json | 7 +- subocr-tauri-ui/src/MainView.tsx | 21 +++++ 7 files changed, 117 insertions(+), 62 deletions(-) delete mode 100644 subocr-swiftui/privacy.README.md diff --git a/subocr-swiftui/privacy.README.md b/subocr-swiftui/privacy.README.md deleted file mode 100644 index 1928d29..0000000 --- a/subocr-swiftui/privacy.README.md +++ /dev/null @@ -1,3 +0,0 @@ -privacy.md是一份来自模板的隐私政策文件,它含有许多与《望言OCR》无关的内容。 - -事实上,将privacy.md置于此处仅仅是因为应用商店审核流程需要。《望言OCR》是一个离线的APP,它涉及的信息读写仅包含您指定的视频和字幕文件,并且不会上传任何信息到网络。(明明一句话能说明白却要写满满两页纸,也是无语😅) \ No newline at end of file diff --git a/subocr-swiftui/subocr-macos/views/MainView.swift b/subocr-swiftui/subocr-macos/views/MainView.swift index c5839a0..47692a4 100644 --- a/subocr-swiftui/subocr-macos/views/MainView.swift +++ b/subocr-swiftui/subocr-macos/views/MainView.swift @@ -84,8 +84,8 @@ public struct MainView: View { public var body: some View{ VStack{ mainScrollView - Spacer() - Text("[Github: https://github.com/nhjydywd/SubtitleOCR](https://github.com/nhjydywd/SubtitleOCR)").font(.subheadline) +// Spacer() +// Text("[Github: https://github.com/nhjydywd/SubtitleOCR](https://github.com/nhjydywd/SubtitleOCR)").font(.subheadline) } .onDrop(of: [.movie], isTargeted: nil){ providers in if providers.count <= 0{ diff --git a/subocr-tauri-ui/src-tauri/build.rs b/subocr-tauri-ui/src-tauri/build.rs index ec53eca..95084e4 100755 --- a/subocr-tauri-ui/src-tauri/build.rs +++ b/subocr-tauri-ui/src-tauri/build.rs @@ -29,39 +29,55 @@ fn main() { - + let mut alg_dir = "C:\\Data\\Codes\\dev\\SubtitleOCR\\subocr-win-cli\\x64\\Debug"; // 算法库 if debug{ - let alg_debug_dir = "C:\\Data\\Codes\\dev\\SubtitleOCR\\SubtitleOCR\\subocr-alg\\build\\Debug"; - println!("cargo-rerun-if-changed={}", alg_debug_dir); - // copy_file(format!("{}/subocr.dll", alg_release_dir).as_str(), format!("{}/subocr.dll", out_dir).as_str()).unwrap(); - copy_file(format!("{}/subocr.dll", alg_debug_dir).as_str(), format!("{}/subocr.dll", out_dir).as_str()).unwrap(); - println!("cargo:rustc-link-lib=subocr"); + alg_dir = "C:\\Data\\Codes\\dev\\SubtitleOCR\\subocr-win-cli\\x64\\Debug"; + }else{ - let alg_release_dir = "C:\\Data\\Codes\\dev\\SubtitleOCR\\SubtitleOCR\\subocr-alg\\build\\Release"; - println!("cargo:rustc-link-search={}", alg_release_dir); - copy_file(format!("{}/subocr.dll", alg_release_dir).as_str(), format!("{}/subocr.dll", out_dir).as_str()).unwrap(); - println!("cargo:rustc-link-lib=subocr"); + alg_dir = "C:\\Data\\Codes\\dev\\SubtitleOCR\\subocr-win-cli\\x64\\Release"; + // let alg_release_dir = "C:\\Data\\Codes\\dev\\SubtitleOCR\\SubtitleOCR\\subocr-alg\\build\\Release"; + // println!("cargo:rustc-link-search={}", alg_release_dir); + // copy_file(format!("{}/subocr.dll", alg_release_dir).as_str(), format!("{}/subocr.dll", out_dir).as_str()).unwrap(); + // println!("cargo:rustc-link-lib=subocr"); } + println!("cargo-rerun-if-changed={}", alg_dir); + println!("cargo:rustc-link-search={}", alg_dir); + println!("cargo:rustc-link-lib=subocr"); + + + let entries = fs::read_dir(alg_dir).unwrap(); + for entry in entries { + let entry = entry.unwrap(); + let path = entry.path(); + let path = path.to_str().unwrap(); + let name = entry.file_name(); + let name = name.to_str().unwrap(); + println!("name: {}", name); + if !name.ends_with("dll") && !name.ends_with("lib"){ + continue; + } + copy_file(path, format!("{}/{}", out_dir, name).as_str()).unwrap(); + } // dll复制到可执行程序目录 // if debug{ - let dir_dll = "libs"; - println!("cargo-rerun-if-changed={}/", dir_dll); - let entries = fs::read_dir(dir_dll).unwrap(); - for entry in entries { - let entry = entry.unwrap(); - let path = entry.path(); - let path = path.to_str().unwrap(); - let name = entry.file_name(); - let name = name.to_str().unwrap(); - println!("name: {}", name); - if !name.ends_with("dll"){ - continue; - } - copy_file(path, format!("{}/{}", out_dir, name).as_str()).unwrap(); - } + // let dir_dll = "libs"; + // println!("cargo-rerun-if-changed={}/", dir_dll); + // let entries = fs::read_dir(dir_dll).unwrap(); + // for entry in entries { + // let entry = entry.unwrap(); + // let path = entry.path(); + // let path = path.to_str().unwrap(); + // let name = entry.file_name(); + // let name = name.to_str().unwrap(); + // println!("name: {}", name); + // if !name.ends_with("dll"){ + // continue; + // } + // copy_file(path, format!("{}/{}", out_dir, name).as_str()).unwrap(); + // } // } tauri_build::build() diff --git a/subocr-tauri-ui/src-tauri/src/lib.rs b/subocr-tauri-ui/src-tauri/src/lib.rs index 41114ed..f647469 100755 --- a/subocr-tauri-ui/src-tauri/src/lib.rs +++ b/subocr-tauri-ui/src-tauri/src/lib.rs @@ -26,25 +26,37 @@ static mut VDHEIGHT: i32 = 0; #[tauri::command] fn is_preinited()->bool{ + return true; + // let _lock = MTX.lock().expect("Failed to acquire lock"); + // unsafe{ + // let path_resources = PATH_RESOURCES.lock().unwrap(); + // let c_str = CString::new(path_resources.clone()).expect("CString::new failed"); + // let c_str_path_resources = c_str.as_ptr(); + // let res = subocr_is_preinited(c_str_path_resources); + // if res != 0 { + // return true; + // }else{ + // return false; + // } + // } +} + +#[tauri::command] +fn is_inited()->bool{ let _lock = MTX.lock().expect("Failed to acquire lock"); unsafe{ - let path_resources = PATH_RESOURCES.lock().unwrap(); - let c_str = CString::new(path_resources.clone()).expect("CString::new failed"); - let c_str_path_resources = c_str.as_ptr(); - let res = subocr_is_preinited(c_str_path_resources); - if res != 0 { - return true; - }else{ - return false; - } + return SUBOCR != null_mut(); } } #[tauri::command] -fn is_inited()->bool{ +fn set_device(device: i32){ let _lock = MTX.lock().expect("Failed to acquire lock"); unsafe{ - return SUBOCR != null_mut(); + subocr_deinit(SUBOCR); + let path_resources = PATH_RESOURCES.lock().unwrap(); + let c_str_path_resources = CString::new(path_resources.clone()).expect("CString::new failed"); + SUBOCR = subocr_init(c_str_path_resources.as_ptr(), device); } } @@ -289,6 +301,13 @@ extern "C" { } +use std::ffi::OsStr; +use std::os::windows::ffi::OsStrExt; +use std::slice; + +fn utf8_to_utf16(s: &str) -> Vec { + OsStr::new(s).encode_wide().collect() +} #[cfg_attr(mobile, tauri::mobile_entry_point)] pub fn run() { @@ -303,22 +322,25 @@ pub fn run() { let mut foo = PATH_RESOURCES.lock().unwrap(); *foo = str_path_resources; - std::thread::spawn(|| { - unsafe{ - let str_path:CString; - { - let path_resources = PATH_RESOURCES.lock().unwrap(); - str_path = CString::new(path_resources.clone()).expect("CString::new failed"); - } - let c_str_path_resources = str_path.as_ptr(); - println!("c_str_path_resources: {:?}", c_str_path_resources); - println!("str_path_resources: {:?}", str_path); - if subocr_is_preinited(c_str_path_resources) == 0{ - subocr_preinit(c_str_path_resources); - } - SUBOCR = subocr_init(c_str_path_resources); - } - }); + let c_str_path_resources = CString::new((*foo).clone()).expect("CString::new failed"); + SUBOCR = subocr_init(c_str_path_resources.as_ptr(), 0); + + // std::thread::spawn(|| { + // unsafe{ + // let str_path:CString; + // { + // let path_resources = PATH_RESOURCES.lock().unwrap(); + // str_path = CString::new(path_resources.clone()).expect("CString::new failed"); + // } + // let c_str_path_resources = str_path.as_ptr(); + // println!("c_str_path_resources: {:?}", c_str_path_resources); + // println!("str_path_resources: {:?}", str_path); + // if subocr_is_preinited(c_str_path_resources) == 0{ + // subocr_preinit(c_str_path_resources); + // } + // SUBOCR = subocr_init(c_str_path_resources); + // } + // }); println!("\n\n\nsetup finished!\n\n\n"); // let path_resources = app.path().resolve("alg-resources", BaseDirectory::Resource) diff --git a/subocr-tauri-ui/src-tauri/src/subocr_abi.rs b/subocr-tauri-ui/src-tauri/src/subocr_abi.rs index 3bc5e4b..2617785 100755 --- a/subocr-tauri-ui/src-tauri/src/subocr_abi.rs +++ b/subocr-tauri-ui/src-tauri/src/subocr_abi.rs @@ -260,7 +260,7 @@ unsafe extern "C" { pub fn subocr_preinit(pathResources: *const ::std::os::raw::c_char); } unsafe extern "C" { - pub fn subocr_init(pathResources: *const ::std::os::raw::c_char) -> *mut SubocrContext; + pub fn subocr_init(pathResources: *const ::std::os::raw::c_char, device: ::std::os::raw::c_int) -> *mut SubocrContext; } unsafe extern "C" { pub fn subocr_deinit(ctx: *mut SubocrContext); diff --git a/subocr-tauri-ui/src-tauri/tauri.conf.json b/subocr-tauri-ui/src-tauri/tauri.conf.json index 93c9c94..a170a95 100755 --- a/subocr-tauri-ui/src-tauri/tauri.conf.json +++ b/subocr-tauri-ui/src-tauri/tauri.conf.json @@ -1,7 +1,7 @@ { "$schema": "https://schema.tauri.app/config/2", - "productName": "SubtitleOCR", - "version": "1.2.0", + "productName": "望言OCR", + "version": "1.2.1", "identifier": "com.nhj.subocr", "build": { "beforeDevCommand": "yarn dev", @@ -23,7 +23,7 @@ }, "bundle": { - "active": false, + "active": true, "icon": [ "icons/32x32.png", "icons/128x128.png", @@ -36,7 +36,6 @@ "alg-resources/models" ], "windows": { - "nsis": null, "webviewInstallMode": { "type": "offlineInstaller" }, diff --git a/subocr-tauri-ui/src/MainView.tsx b/subocr-tauri-ui/src/MainView.tsx index 232e0d1..8b0ae28 100644 --- a/subocr-tauri-ui/src/MainView.tsx +++ b/subocr-tauri-ui/src/MainView.tsx @@ -86,11 +86,21 @@ function MainView() { const [sliderValue, setSliderValue] = useState(0); const [opened, setOpened] = useState(false); + // const [device, setDevice] = useState(0); const isInputDisabled = useMemo(() => videoUrl.length <= 0 || isPredetRunning || isPipelineRunning, [videoUrl, isPredetRunning, isPipelineRunning]); const isBeginDisabled = useMemo(() => anchors.length <= 0 || anchors.every(anchor => anchor.is_primary===0), [anchors]); + // const handleDevice = (event: React.ChangeEvent) => { + // const newValue = parseInt(event.target.value, 10); + // if (!isNaN(newValue)) { + // var value = Math.min(newValue, 999); + // value = Math.max(value, 0); + // setDevice(value); + // invoke("set_device", { device: value }); + // } + // } const handleFps = (event: React.ChangeEvent) => { console.log(event.target.value); const newValue = parseInt(event.target.value, 10); @@ -470,6 +480,17 @@ function MainView() { } label="显示设置" /> + {/* + 推理设备号: + + */}