Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src-tauri/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ fn main() {
let app_manifest = tauri_build::AppManifest::new().commands(&[
"get_app_state",
"get_switches",
"begin_switch_practice",
"get_switch_practice",
"end_switch_practice",
"get_remote_switches",
"save_remote_switches",
"save_switches",
Expand Down
3 changes: 3 additions & 0 deletions src-tauri/capabilities/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
"core:default",
"allow-get-app-state",
"allow-get-switches",
"allow-begin-switch-practice",
"allow-get-switch-practice",
"allow-end-switch-practice",
"allow-get-remote-switches",
"allow-save-remote-switches",
"allow-save-switches",
Expand Down
11 changes: 11 additions & 0 deletions src-tauri/permissions/autogenerated/begin_switch_practice.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Automatically generated - DO NOT EDIT!

[[permission]]
identifier = "allow-begin-switch-practice"
description = "Enables the begin_switch_practice command without any pre-configured scope."
commands.allow = ["begin_switch_practice"]

[[permission]]
identifier = "deny-begin-switch-practice"
description = "Denies the begin_switch_practice command without any pre-configured scope."
commands.deny = ["begin_switch_practice"]
11 changes: 11 additions & 0 deletions src-tauri/permissions/autogenerated/end_switch_practice.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Automatically generated - DO NOT EDIT!

[[permission]]
identifier = "allow-end-switch-practice"
description = "Enables the end_switch_practice command without any pre-configured scope."
commands.allow = ["end_switch_practice"]

[[permission]]
identifier = "deny-end-switch-practice"
description = "Denies the end_switch_practice command without any pre-configured scope."
commands.deny = ["end_switch_practice"]
11 changes: 11 additions & 0 deletions src-tauri/permissions/autogenerated/get_switch_practice.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Automatically generated - DO NOT EDIT!

[[permission]]
identifier = "allow-get-switch-practice"
description = "Enables the get_switch_practice command without any pre-configured scope."
commands.allow = ["get_switch_practice"]

[[permission]]
identifier = "deny-get-switch-practice"
description = "Denies the get_switch_practice command without any pre-configured scope."
commands.deny = ["get_switch_practice"]
52 changes: 51 additions & 1 deletion src-tauri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ mod state;
mod storage;
mod switch_gestures;
mod switch_input;
mod switch_practice;
mod switch_runtime;
mod switches;
mod telemetry;
Expand Down Expand Up @@ -1272,8 +1273,38 @@ fn save_remote_switches(
config: remote_scan::Config,
) -> Result<remote_scan::Config, String> {
require_main(&window)?;
if switch_practice::active(&app) {
return Err("Finish practice before changing switches.".into());
}
remote_scan::save(&app, config)
}
#[tauri::command]
fn begin_switch_practice(
window: tauri::WebviewWindow,
app: AppHandle,
remote: bool,
) -> Result<switch_practice::View, String> {
require_main(&window)?;
if !main_window_focused(&window)? {
return Err("Focus Switchify before testing switches.".into());
}
switch_practice::begin(&app, remote)
}
#[tauri::command]
fn get_switch_practice(
window: tauri::WebviewWindow,
app: AppHandle,
) -> Result<switch_practice::View, String> {
require_main(&window)?;
Ok(switch_practice::view(&app))
}
#[tauri::command]
fn end_switch_practice(window: tauri::WebviewWindow, app: AppHandle) -> Result<(), String> {
require_main(&window)?;
switch_practice::end(&app);
Ok(())
}

#[tauri::command]
fn get_switches(
window: tauri::WebviewWindow,
Expand All @@ -1289,6 +1320,9 @@ fn save_switches(
settings: switches::Settings,
) -> Result<switch_runtime::View, String> {
require_main(&window)?;
if switch_practice::active(&app) {
return Err("Finish practice before changing switches.".into());
}
// Sync commands run on the main thread, which pausing the overlay needs.
point_scan_runtime::pause(&app);
let view = app
Expand Down Expand Up @@ -1331,6 +1365,9 @@ fn set_switch_keyboard_entry(
require_main(&window)?;
let switches = app.state::<switch_runtime::Controller>();
if active {
if switch_practice::active(&app) {
return Err("Finish practice before typing with the keyboard.".into());
}
if !main_window_focused(&window)? {
return Err("Focus Switchify PC before typing with the keyboard.".into());
}
Expand Down Expand Up @@ -1362,7 +1399,12 @@ async fn configure_point_scan(
let (tx, rx) = tokio::sync::oneshot::channel();
let handle = app.clone();
app.run_on_main_thread(move || {
let _ = tx.send(point_scan_runtime::configure(&handle, config));
let result = if switch_practice::active(&handle) {
Err("Finish practice before changing scanning settings.".into())
} else {
point_scan_runtime::configure(&handle, config)
};
let _ = tx.send(result);
})
.map_err(|e| e.to_string())?;
rx.await
Expand All @@ -1376,6 +1418,9 @@ fn point_scan_ready(app: &AppHandle) -> Result<(), String> {
"Typing with the keyboard. Resume switch control in Switches when finished.".into(),
);
}
if switch_practice::active(app) {
return Err("Finish switch practice before scanning or editing switches.".into());
}
let state = app.state::<AppModel>().snapshot();
if state.bluetooth == state::BluetoothState::Connected && !remote_scan::active(app) {
return Err("Local scanning pauses while Android is connected.".into());
Expand Down Expand Up @@ -1439,6 +1484,7 @@ pub fn run() {
.manage(PendingProfileExit::default())
.manage(PendingNavigation::default())
.setup(move |app| {
app.manage(switch_practice::Controller::default());
switch_runtime::install(app.handle());
remote_scan::install(app.handle());
point_scan_runtime::install(app.handle());
Expand Down Expand Up @@ -1526,12 +1572,16 @@ pub fn run() {
}
}
if let tauri::WindowEvent::CloseRequested { api, .. } = event {
switch_practice::end(window.app_handle());
api.prevent_close();
request_profile_exit(window.app_handle(), ProfileExitAction::Hide);
}
})
.invoke_handler(tauri::generate_handler![
get_switches,
begin_switch_practice,
get_switch_practice,
end_switch_practice,
get_remote_switches,
save_remote_switches,
save_switches,
Expand Down
8 changes: 8 additions & 0 deletions src-tauri/src/remote_scan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,9 @@ pub fn input_available(session_active: bool, cleanup_required: bool) -> bool {
!session_active && !cleanup_required
}
pub fn allow_direct(app: &AppHandle) -> Result<(), String> {
if crate::switch_practice::active(app) {
return Err("Finish switch practice before using other PC controls.".into());
}
let c = app.state::<Controller>();
let d = c.data.lock().unwrap_or_else(|p| p.into_inner());
if !input_available(d.session.is_some(), d.cleanup_required) {
Expand Down Expand Up @@ -418,6 +421,11 @@ pub fn route(
command: &str,
payload: &Value,
) -> Option<Result<(), String>> {
if command == "switch.session.start" && crate::switch_practice::active(app) {
return Some(Err(
"Exit switch practice before starting forwarding.".into()
));
}
let scanning_start = command == "switch.session.start" && payload["profileId"] == PROFILE_ID;
if command == "switch.session.start" {
crate::point_scan_runtime::pause(app);
Expand Down
3 changes: 3 additions & 0 deletions src-tauri/src/scanning_runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,9 @@ fn render<A: Adapter>(
Ok(())
}
fn tick<A: Adapter>(app: &AppHandle) {
if crate::switch_practice::tick(app) {
return;
}
let c = app.state::<Controller<A>>();
let remote = crate::remote_scan::poll(app);
let (mut events, local_now, _) = app.state::<switch_runtime::Controller>().poll(app);
Expand Down
Loading
Loading