Skip to content

Commit

Permalink
Set scratch dir via interpreter command
Browse files Browse the repository at this point in the history
  • Loading branch information
ales-tsurko committed Oct 28, 2024
1 parent bfc284c commit d7b326e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 18 deletions.
4 changes: 3 additions & 1 deletion src/app/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ pub fn update(state: &mut State, message: Message) -> Task<Message> {
if let Some(value) = pick_directory("Choose scratch folder") {
interpreter::INTERPRETER_WORKER
.interp_sender
.send_blocking(interpreter::Message::SetScratchDir(value))
.send_blocking(interpreter::Message::SendCmd(format!("apdir x {value}")))
.expect("the channel is unbound");
}
}
Expand Down Expand Up @@ -173,6 +173,8 @@ pub fn update(state: &mut State, message: Message) -> Task<Message> {
interpreter::Message::Error(output) | interpreter::Message::PythonError(output) => {
state.answer = "".to_owned();
state.output.push(Output::Error(output));

return text_input::focus(state.input_id.clone());
}
interpreter::Message::Ask(prompt) => {
state.answer = "".to_owned();
Expand Down
17 changes: 0 additions & 17 deletions src/interpreter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,6 @@ impl InterpreterWorker {
Message::GetScratchDir => {
interpreter.scratch_dir().map(Message::ScratchDir)
}
Message::SetScratchDir(value) => interpreter
.set_scratch_dir(&value)
.map(|_| Message::ScratchDir(value)),
_ => continue,
}
.into();
Expand Down Expand Up @@ -96,8 +93,6 @@ pub enum Message {
LoadMidi(String),
/// Get scratch dir.
GetScratchDir,
/// Set scratch dir.
SetScratchDir(String),
/// The result of `Self::GetScratchDir`.
ScratchDir(String),
}
Expand Down Expand Up @@ -173,18 +168,6 @@ interp"#
})
}

fn set_scratch_dir(&self, path: &str) -> InterpreterResult<()> {
self.py_interpreter.enter(|vm| -> InterpreterResult<()> {
let external = vm
.get_attribute_opt(self.ath_object.clone(), "external")
.try_py()?
.expect("external attribute is always available on AthenaObject");
vm.call_method(&external, "writePref", ("athena", "fpScratchDir", path))
.try_py()?;
Ok(())
})
}

fn scratch_dir(&self) -> InterpreterResult<String> {
self.py_interpreter
.enter(|vm| -> InterpreterResult<String> {
Expand Down

0 comments on commit d7b326e

Please sign in to comment.