Skip to content

Commit

Permalink
1.2.1 update
Browse files Browse the repository at this point in the history
  • Loading branch information
nhjydywd committed Jan 10, 2025
1 parent 21534d8 commit 9d7a3d7
Show file tree
Hide file tree
Showing 7 changed files with 117 additions and 62 deletions.
3 changes: 0 additions & 3 deletions subocr-swiftui/privacy.README.md

This file was deleted.

4 changes: 2 additions & 2 deletions subocr-swiftui/subocr-macos/views/MainView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
66 changes: 41 additions & 25 deletions subocr-tauri-ui/src-tauri/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
76 changes: 49 additions & 27 deletions subocr-tauri-ui/src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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<u16> {
OsStr::new(s).encode_wide().collect()
}

#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion subocr-tauri-ui/src-tauri/src/subocr_abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
7 changes: 3 additions & 4 deletions subocr-tauri-ui/src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -23,7 +23,7 @@
},

"bundle": {
"active": false,
"active": true,
"icon": [
"icons/32x32.png",
"icons/128x128.png",
Expand All @@ -36,7 +36,6 @@
"alg-resources/models"
],
"windows": {
"nsis": null,
"webviewInstallMode": {
"type": "offlineInstaller"
},
Expand Down
21 changes: 21 additions & 0 deletions subocr-tauri-ui/src/MainView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,21 @@ function MainView() {
const [sliderValue, setSliderValue] = useState(0);

const [opened, setOpened] = useState(false);
// const [device, setDevice] = useState<number>(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<HTMLInputElement>) => {
// 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<HTMLInputElement>) => {
console.log(event.target.value);
const newValue = parseInt(event.target.value, 10);
Expand Down Expand Up @@ -470,6 +480,17 @@ function MainView() {
}
label="显示设置"
/>
{/* <Stack direction={"row"} alignItems={"center"} alignContent={"center"} style={{marginLeft:"2rem"}}>
<Typography>推理设备号: </Typography>
<TextField disabled={isInputDisabled}
variant="standard" size="small"
type="number"
className="custom-textfield"
value={device}
style={{maxWidth:"3rem", width: "2.5rem", marginLeft: "0.5rem"}}
onChange={handleDevice}
/>
</Stack> */}
</Stack>
<Collapse in={opened} style={{marginTop:"0.5rem",marginBottom:"0.5rem"}}>
<Card>
Expand Down

0 comments on commit 9d7a3d7

Please sign in to comment.