Skip to content

Commit

Permalink
v0.4.6 baby
Browse files Browse the repository at this point in the history
  • Loading branch information
kaii-lb committed Oct 21, 2023
1 parent 8772c05 commit 5a943ef
Show file tree
Hide file tree
Showing 12 changed files with 124 additions and 49 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
### Overskride Version 0.4.6
- renaming to duplicate names now adds an index to the dupe (eg: "headphones (1)")
- auto accept from trusted devices now works
- added warning for auto accept
- identified issue where obex agent gets removed after 1 complete transfer
- fixed issue where a non-identifiable download dir causes a crash
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "overskride"
version = "0.4.5"
version = "0.4.6"
edition = "2021"

[dependencies]
Expand Down
6 changes: 5 additions & 1 deletion data/io.github.kaii_lb.Overskride.gschema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
<default>""</default>
<summary>where the received files are stored</summary>
</key>
</schema>
<key name="first-auto-accept" type="b">
<default>true</default>
<summary>one time auto accept indicator</summary>
</key>
</schema>
</schemalist>

4 changes: 1 addition & 3 deletions meson.build
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
project('overskride', 'rust',
version: '0.4.5',
version: '0.4.6',
meson_version: '>= 0.62.0',
default_options: [ 'warning_level=2', 'werror=false', ],
)

i18n = import('i18n')
gnome = import('gnome')



subdir('data')
subdir('src')
subdir('po')
Expand Down
13 changes: 12 additions & 1 deletion src/bluetooth/agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,20 @@ pub async fn wait_for_dialog_exit() {
unsafe {
loop {
if !DISPLAYING_DIALOG {
// std::thread::sleep(std::time::Duration::from_secs(1));
std::thread::sleep(std::time::Duration::from_secs(1));
break;
}
}
}
}

#[tokio::main]
pub async fn register_bluetooth_agent(sender: Sender<Message>) -> bluer::Result<()> {
let session = bluer::Session::new().await?;
let agent = register_agent(&session, true, false, sender.clone()).await?;
println!("registered agent standalone {:?}", agent);

loop {
std::thread::sleep(std::time::Duration::from_secs(1));
}
}
6 changes: 1 addition & 5 deletions src/bluetooth/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use gtk::glib::Sender;
use tokio_util::sync::CancellationToken;
use uuid::uuid;

use crate::{message::Message, window::{DEVICES_LUT, CURRENT_ADDRESS, CONFIRMATION_AUTHORIZATION, DISPLAYING_DIALOG}, agent::{self, wait_for_dialog_exit}};
use crate::{message::Message, window::{DEVICES_LUT, CURRENT_ADDRESS, CONFIRMATION_AUTHORIZATION, DISPLAYING_DIALOG}, agent::wait_for_dialog_exit};

static mut CANCELLATION_TOKEN: Option<CancellationToken> = None;
/// Set the associated with `address` device's state, between connected and not
Expand Down Expand Up @@ -249,12 +249,8 @@ pub async fn get_devices_continuous(sender: Sender<Message>, adapter_name: Strin

let mut all_change_events = SelectAll::new();

let session = bluer::Session::new().await?;
let sender_clone = sender.clone();

let agent = agent::register_agent(&session, true, false, sender_clone.clone()).await?;
println!("registered agent during discovery {:?}", agent);

let cancellation_token = CancellationToken::new();
unsafe {
CANCELLATION_TOKEN = Some(cancellation_token.clone());
Expand Down
2 changes: 1 addition & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pub static VERSION: &str = "0.4.5";
pub static VERSION: &str = "0.4.6";
pub static GETTEXT_PACKAGE: &str = "overskride";
pub static LOCALEDIR: &str = "/usr/share/locale";
pub static PKGDATADIR: &str = "/usr/share/overskride";
2 changes: 1 addition & 1 deletion src/gtk/window.blp
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ template $OverskrideWindow: Adw.ApplicationWindow {
Adw.SwitchRow auto_accept_trusted_row {
title: "Auto Accept";
subtitle: "auto accept files from trusted devices?";
sensitive: false;
// sensitive: false;
}

Adw.EntryRow file_save_location {
Expand Down
73 changes: 50 additions & 23 deletions src/obex/obex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,22 @@ use dbus_crossroads::Crossroads;
use gtk::glib::Sender;
use std::{time::Duration, collections::HashMap, sync::Mutex};
use dbus::channel::MatchingReceiver;
use std::str::FromStr;

use crate::{message::Message, obex_utils::{ObexAgentManager1, ObexTransfer1, ObexClient1, ObexObjectPush1}, window::{DISPLAYING_DIALOG, CONFIRMATION_AUTHORIZATION, SEND_FILES_PATH, STORE_FOLDER}, agent::wait_for_dialog_exit};
use crate::{message::Message, obex_utils::{ObexAgentManager1, ObexTransfer1, ObexClient1, ObexObjectPush1},
window::{DISPLAYING_DIALOG, CONFIRMATION_AUTHORIZATION, SEND_FILES_PATH, STORE_FOLDER, AUTO_ACCEPT_FROM_TRUSTED, CURRENT_ADAPTER},
agent::wait_for_dialog_exit};

const SESSION_INTERFACE: &str = "org.bluez.obex.Session1";
const TRANSFER_INTERFACE: &str = "org.bluez.obex.Transfer1";

static mut SESSION_BUS: Mutex<Option<Connection>> = Mutex::new(None);
static mut CURRENT_SESSION: String = String::new();
static mut CURRENT_TRANSFER: String = String::new();
static mut BREAKING: bool = false;
static mut CURRENT_FILE_SIZE: u64 = 0;
static mut CURRENT_FILE_NAME: String = String::new();
static mut CURRENT_SENDER: Option<Sender<Message>> = None;
static mut BREAKING: bool = false;
static mut OUTBOUND: bool = false;
pub static mut CANCEL: bool = false;

Expand All @@ -40,43 +43,35 @@ fn handle_properties_updated(interface: String, changed_properties: PropMap, tra
match dummy_status {
"active" => {
if unsafe { OUTBOUND } {
sender.send(Message::PopupError("obex-transfer-active-outbound".to_string(), adw::ToastPriority::Normal)).expect("cannot send message");
sender.send(Message::PopupError("obex-transfer-active-outbound".to_string(), adw::ToastPriority::Normal)).expect("cannot send message");
unsafe { BREAKING = false; }
}
else {
sender.send(Message::PopupError("obex-transfer-active-inbound".to_string(), adw::ToastPriority::Normal)).expect("cannot send message");
}
unsafe {
BREAKING = false;
}
},
"complete" => {
if unsafe { OUTBOUND } {
sender.send(Message::PopupError("obex-transfer-complete-outbound".to_string(), adw::ToastPriority::Normal)).expect("cannot send message");
unsafe { BREAKING = true; }
}
else {
sender.send(Message::PopupError("obex-transfer-complete-inbound".to_string(), adw::ToastPriority::Normal)).expect("cannot send message");
move_to_store_folder();
}
unsafe {
BREAKING = true;
}
},
"error" => {
if unsafe { OUTBOUND } {
sender.send(Message::PopupError("obex-transfer-error-outbound".to_string(), adw::ToastPriority::Normal)).expect("cannot send message");
unsafe { BREAKING = true; }
}
else {
sender.send(Message::PopupError("obex-transfer-error-inbound".to_string(), adw::ToastPriority::Normal)).expect("cannot send message");
}
unsafe {
BREAKING = true;
}
},
message => {
sender.send(Message::PopupError(message.to_string(), adw::ToastPriority::Normal)).expect("cannot send message");
unsafe {
BREAKING = false;
}
unsafe { BREAKING = false; }
}
}

Expand Down Expand Up @@ -186,7 +181,7 @@ fn serve(conn: &mut Connection, cr: Option<Crossroads>) -> Result<(), dbus::Erro

// Serve clients forever.
unsafe {
while !BREAKING {
loop {
// println!("serving");
conn.process(std::time::Duration::from_millis(1000))?;
if CANCEL {
Expand All @@ -209,22 +204,21 @@ fn serve(conn: &mut Connection, cr: Option<Crossroads>) -> Result<(), dbus::Erro
}
}
}

Ok(())
}

fn create_agent(cr: &mut Crossroads, sender: Sender<Message>) {
let agent = cr.register("org.bluez.obex.Agent1", |b| {
b.method("AuthorizePush", ("transfer",), ("filename",), move |_, _, (transfer,): (Path,)| {
println!("authorizing...");
let conn = Connection::new_session().expect("cannot create connection.");
let props = conn.with_proxy("org.bluez.obex", transfer.clone(), std::time::Duration::from_secs(1)).get_all(TRANSFER_INTERFACE);
let props = conn.with_proxy("org.bluez.obex", transfer.clone(), std::time::Duration::from_secs(5)).get_all(TRANSFER_INTERFACE);

if let Ok(all_props) = props {
// let filename = "/home/kaii/Downloads/file_test.mp4";
let filename = all_props.get("Name").expect("cannot get name of file.").0.as_str().unwrap().to_owned();
let filesize_holder = &*all_props.get("Size").expect("cannot get file size.").0;
let filesize = filesize_holder.as_u64().unwrap_or(9999);
let session = all_props.get("Session").expect("cannot get session for receive").0.as_str().unwrap_or("");

println!("all props is: {:?}", all_props);

Expand All @@ -235,10 +229,27 @@ fn create_agent(cr: &mut Crossroads, sender: Sender<Message>) {
}
let mb = ((filesize as f32 / 1000000.0) * 100.0).round() / 100.0;

if spawn_dialog(filename.clone(), &sender) {
let sender_props = conn.with_proxy("org.bluez.obex", session, std::time::Duration::from_secs(5)).get_all(SESSION_INTERFACE).unwrap();
let device = sender_props.get("Destination").expect("cannot get sender device").0.as_str().unwrap_or("00:00:00:00:00:00");

let (device_name, device_trusted) = if let Ok(props) = get_device_props(device) {
props
}
else {
return Err(MethodErr::from(("org.bluez.obex.Error.Canceled", "Request Canceled")));
};

if unsafe { AUTO_ACCEPT_FROM_TRUSTED } && device_trusted {
println!("transfer is: {:?}", transfer);
sender.send(Message::StartTransfer(transfer.to_string(), filename.clone(), 0.0, 0.0, mb, false)).expect("cannot send message");

return Ok((filename,));
}

if spawn_dialog(filename.clone(), &sender, device_name) {
println!("transfer is: {:?}", transfer);
sender.send(Message::StartTransfer(transfer.to_string(), filename.clone(), 0.0, 0.0, mb, false)).expect("cannot send message");

unsafe {
CONFIRMATION_AUTHORIZATION = false;
}
Expand Down Expand Up @@ -279,11 +290,11 @@ fn create_agent(cr: &mut Crossroads, sender: Sender<Message>) {
}

#[tokio::main]
async fn spawn_dialog(filename: String, sender: &Sender<Message>) -> bool {
async fn spawn_dialog(filename: String, sender: &Sender<Message>, device_name: String) -> bool {
println!("file receive request incoming!");

let title = "File Transfer Incoming".to_string();
let subtitle = "Accept <span font_weight='bold' color='#78aeed'>".to_string() + &filename + "</span> from a device";
let subtitle = "Accept <span font_weight='bold' color='#78aeed'>".to_string() + &filename + "</span> from <span font_weight='bold'>" + &device_name + "</span>";
let confirm = "Accept".to_string();
let response_type = adw::ResponseAppearance::Suggested;

Expand Down Expand Up @@ -392,6 +403,10 @@ fn send_file(source_file: String, session_path: Path, sender: Sender<Message>) {
}

pub fn move_to_store_folder() {
if unsafe { OUTBOUND } {
return;
}

let filename = unsafe {
CURRENT_FILE_NAME.clone()
};
Expand All @@ -416,4 +431,16 @@ pub fn move_to_store_folder() {
println!("file was not moved due to {:?}", err);
},
}
}
}

#[tokio::main]
async fn get_device_props(address_slice: &str) -> bluer::Result<(String, bool)> {
let adapter = bluer::Session::new().await?.adapter(unsafe { &CURRENT_ADAPTER })?;
let address = bluer::Address::from_str(address_slice).unwrap_or(bluer::Address::any());
let device = adapter.device(address)?;

let trusted = device.is_trusted().await?;
let name = device.alias().await?;

Ok((name, trusted))
}
3 changes: 2 additions & 1 deletion src/widgets/connected_switch_row.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ mod imp {
*self.active.borrow_mut() = active;
self.spinner.set_spinning(true);
}

/// return the current state of the row's spinner, ie: spinning, or not visible.
fn get_row_spinning(&self) -> bool {
self.spinner.is_spinning()
Expand All @@ -80,6 +80,7 @@ mod imp {

fn set_switch_active(&self, active: bool) {
self.switch.set_active(active);
*self.active.borrow_mut() = active;
}

}
Expand Down
Loading

0 comments on commit 5a943ef

Please sign in to comment.