Skip to content

Commit

Permalink
Merge pull request #22 from jasonjmcghee/plock-10-fix-dropping-chars
Browse files Browse the repository at this point in the history
[plock-10]: Attempted fix for dropped chars
  • Loading branch information
jasonjmcghee authored Feb 3, 2024
2 parents 7f41a06 + 848041b commit 62a7d7e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 20 deletions.
46 changes: 28 additions & 18 deletions src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,12 +328,12 @@ fn trigger_action(
let mut did_exit = false;

{
while let Some(response) = response_stream.next().await {
'outer:while let Some(response) = response_stream.next().await {
whole_buffer.push(response.clone());
delta_buffer.push(response.clone());

let delta_output = {
if delta_buffer.len() > 4 && !response.starts_with('\n')
// workaround for a bug in enigo, it doesn't like leading newlines
{
if delta_buffer.len() > 4 {
let s = delta_buffer.clone().join("");
delta_buffer.clear();
s
Expand All @@ -342,20 +342,23 @@ fn trigger_action(
}
};

// move this to after the delta_output so we can not start a delta_buffer with a newline
whole_buffer.push(response.clone());
delta_buffer.push(response);

for step in trigger.next_steps.clone() {
if let Step::StreamTextToScreen = step {
enigo.text(&delta_output).expect("Failed to type out text");
if delta_output.is_empty() {
continue;
}
match step {
Step::StreamTextToScreen => {
for chunk in delta_output.chars().collect::<Vec<char>>().chunks(19) {
enigo.text(&String::from_iter(chunk).replace("\n", " \n")).expect("Failed to type out text");
// Exit loop if child process has finished or exit flag is set
if exit_flag_thread.load(Ordering::SeqCst) {
did_exit = true;
break 'outer;
}
}
}
_ => {}
}
}

// Exit loop if child process has finished or exit flag is set
if exit_flag_thread.load(Ordering::SeqCst) {
did_exit = true;
break;
}
}
}
Expand All @@ -366,11 +369,18 @@ fn trigger_action(
let whole_output = whole_buffer.join("");
println!("Whole output: {}", whole_output);

for step in trigger.next_steps {
'outer: for step in trigger.next_steps {
match step {
Step::StreamTextToScreen => {
if !delta_buffer.is_empty() {
enigo.text(&delta_output).expect("Failed to type out text");
for chunk in delta_output.chars().collect::<Vec<char>>().chunks(19) {
enigo.text(&String::from_iter(chunk).replace("\n", " \n")).expect("Failed to type out text");
// Exit loop if child process has finished or exit flag is set
if exit_flag_thread.load(Ordering::SeqCst) {
should_continue = false;
break 'outer;
}
}
}
}
Step::StoreAsEnvVar(key) => {
Expand Down
4 changes: 2 additions & 2 deletions src-tauri/tauri.conf.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"build": {
"beforeBuildCommand": "mkdir -p dist && npm run build",
"beforeDevCommand": "mkdir -p dist && npm run dev",
"beforeBuildCommand": "mkdir -p dist ; npm run build",
"beforeDevCommand": "mkdir -p dist ; npm run dev",
"devPath": "../dist",
"distDir": "../dist"
},
Expand Down

0 comments on commit 62a7d7e

Please sign in to comment.