Skip to content

Commit c67334c

Browse files
fix audio. possible fix strings
1 parent 2529196 commit c67334c

File tree

6 files changed

+63
-18
lines changed

6 files changed

+63
-18
lines changed

cef/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ edition = "2018"
66

77
[dependencies]
88
cef-sys = { path = "../cef-sys" }
9+
widestring = "0.4.3"
910

1011
[dev-dependencies]
1112
testdrop = "0.1.2"

cef/src/types/string.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use cef_sys::cef_string_userfree_t;
1+
use cef_sys::{_cef_string_utf16_t, cef_string_userfree_t};
22
pub use cef_sys::{
33
cef_string_t, cef_string_utf16_clear, cef_string_utf16_to_utf8, cef_string_utf8_to_utf16,
44
};
@@ -98,3 +98,23 @@ impl From<cef_string_userfree_t> for CefString {
9898
cefstr
9999
}
100100
}
101+
102+
pub fn into_cef_string(string: &str) -> cef_string_t {
103+
extern "C" fn free(ptr: *mut u16) {
104+
if ptr.is_null() {
105+
return;
106+
}
107+
108+
unsafe {
109+
widestring::U16CString::from_raw(ptr);
110+
}
111+
}
112+
113+
let wide = widestring::U16CString::from_str(string).unwrap();
114+
115+
_cef_string_utf16_t {
116+
length: wide.len(),
117+
str: wide.into_raw(),
118+
dtor: Some(free),
119+
}
120+
}

client/src/browser/cef.rs

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -54,32 +54,52 @@ pub fn initialize(event_tx: Sender<Event>) {
5454

5555
let mut settings = unsafe { std::mem::zeroed::<cef_sys::cef_settings_t>() };
5656

57-
let cache_path = crate::utils::documents_path();
57+
// let cache_path = crate::utils::documents_path();
5858
let cef_dir = crate::utils::cef_dir();
59+
let cache_path = cef_dir.join("cache");
5960

60-
log::trace!("cache_path: {:?}", cache_path);
61+
// log::trace!("cache_path: {:?}", cache_path);
6162
log::trace!("cef_dir: {:?}", cef_dir);
6263

63-
let path = CefString::new(&cef_dir.join("renderer.exe").to_string_lossy());
64-
let cache_path = CefString::new(&cache_path.to_string_lossy());
65-
let locales_dir_path = CefString::new(&cef_dir.join("locales").to_string_lossy());
66-
let resources_dir_path = CefString::new(&cef_dir.to_string_lossy());
64+
// let path = CefString::new(&cef_dir.join("renderer.exe").to_string_lossy());
65+
// let cache_path = CefString::new(&cache_path.to_string_lossy());
66+
// let locales_dir_path = CefString::new(&cef_dir.join("locales").to_string_lossy());
67+
// let resources_dir_path = CefString::new(&cef_dir.to_string_lossy());
68+
// let root_cache_path = CefString::new(&cef_dir.to_string_lossy());
69+
// let log_file = CefString::new(&cef_dir.join("cef.log").to_string_lossy());
70+
71+
let path = cef::types::string::into_cef_string(&cef_dir.join("renderer.exe").to_string_lossy());
72+
let cache_path = cef::types::string::into_cef_string(&cache_path.to_string_lossy());
73+
let locales_dir_path =
74+
cef::types::string::into_cef_string(&cef_dir.join("locales").to_string_lossy());
75+
let resources_dir_path = cef::types::string::into_cef_string(&cef_dir.to_string_lossy());
76+
let root_cache_path = cef::types::string::into_cef_string(&cef_dir.to_string_lossy());
77+
let log_file = cef::types::string::into_cef_string(&cef_dir.join("cef.log").to_string_lossy());
78+
let user_data =
79+
cef::types::string::into_cef_string(&cef_dir.join("user_data").to_string_lossy());
80+
81+
log::trace!("{:?}", cef_dir.join("cef.log"));
6782

6883
settings.size = std::mem::size_of::<cef_sys::cef_settings_t>();
6984
settings.no_sandbox = 1;
70-
settings.browser_subprocess_path = path.to_cef_string();
85+
settings.browser_subprocess_path = path;
7186
settings.windowless_rendering_enabled = 1;
7287
settings.multi_threaded_message_loop = 1;
7388
settings.log_severity = 0;
74-
settings.cache_path = cache_path.to_cef_string();
75-
settings.locales_dir_path = locales_dir_path.to_cef_string();
76-
settings.resources_dir_path = resources_dir_path.to_cef_string();
89+
settings.cache_path = cache_path;
90+
settings.locales_dir_path = locales_dir_path;
91+
settings.resources_dir_path = resources_dir_path;
92+
settings.ignore_certificate_errors = 1;
93+
settings.command_line_args_disabled = 1;
94+
settings.log_file = log_file;
95+
settings.user_data_path = user_data;
7796

7897
let app = Arc::new(DefaultApp { event_tx });
7998

8099
log::trace!("PRE cef::initialize");
81-
// cef::initialize(None, &settings, Some(app));
100+
82101
cef::initialize(Some(&main_args), &settings, Some(app));
102+
83103
log::trace!("POST cef::initialize");
84104
}
85105

client/src/browser/client.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,10 @@ impl RenderHandler for WebClient {
271271
self: &Arc<Self>, _: Browser, paint_type: PaintElement, mut dirty_rects: DirtyRects,
272272
buffer: &[u8], width: usize, height: usize,
273273
) {
274-
if self.closing.load(Ordering::SeqCst) {
274+
// TODO: тест hidden
275+
if
276+
/*self.hidden.load(Ordering::SeqCst) ||*/
277+
self.closing.load(Ordering::SeqCst) {
275278
return;
276279
}
277280

client/src/rodio_audio.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -489,10 +489,11 @@ impl AudioInner {
489489
fn set_sinks_gain(&mut self, gain: f32) {
490490
self.streams.values_mut().for_each(|stream| {
491491
stream.iter_mut().for_each(|stream| {
492-
stream
493-
.sources
494-
.values()
495-
.for_each(|source| source.sink.set_volume(gain));
492+
stream.sources.values().for_each(|source| {
493+
if !source.muted {
494+
source.sink.set_volume(gain);
495+
}
496+
});
496497
});
497498
});
498499
}

loader/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ pub extern "stdcall" fn DllMain(_instance: u32, reason: u32, _reserved: u32) ->
4343
winapi::um::winbase::SetDllDirectoryW(search_dir.as_ptr());
4444
}
4545

46-
if let Ok(lib) = Library::new("client.dll") {
46+
if let Ok(lib) = Library::new(path.join("cef\\client.dll")) {
4747
unsafe {
4848
LIBRARY = Some(lib);
4949
}

0 commit comments

Comments
 (0)