Thread overview
How to use Dbus to detect application uniqueness in D?
Sep 27, 2019
Hossain Adnan
Sep 28, 2019
Kagamin
Sep 29, 2019
Hossain Adnan
Sep 30, 2019
Kagamin
Sep 30, 2019
Kagamin
September 27, 2019
Hi I need to detect application uniqueness using dbus. I have a working code in Rust:

fn run_as_unique_instance() {
    println!("First instance detected. Doing work...");
    loop {}
}

fn run_as_nonunique_instance() {
    println!("Another instance is already running. Quiting...");
    std::process::exit(0);
}

fn main() {
    let session =
        dbus::blocking::Connection::new_session().expect("Cannot setup a new dbus session");

    match session.request_name("com.localserver.app.bus", false, false, false) {
        Ok(dbus::blocking::stdintf::org_freedesktop_dbus::RequestNameReply::PrimaryOwner) => {
            run_as_unique_instance()
        }
        Ok(_) => run_as_nonunique_instance(), // RequestNameReply::InQueue
        Err(_) => panic!("Error in session name request."),
    }
}


This creates a new session in dbus and then requests name. If the response is "PrimaryOwner" it means the application is unique. However I can't find the similar symbols in ddbus.

https://ddbus.dpldocs.info/search-results.html#!session
https://ddbus.dpldocs.info/search-results.html#!Connection

Returns nothing.
September 28, 2019
https://ddbus.dpldocs.info/ddbus.bus.requestName.html
September 29, 2019
On Saturday, 28 September 2019 at 13:37:12 UTC, Kagamin wrote:
> https://ddbus.dpldocs.info/ddbus.bus.requestName.html

It requires a Connection type which I cannot find in the API.
September 30, 2019
On Sunday, 29 September 2019 at 02:09:56 UTC, Hossain Adnan wrote:
> On Saturday, 28 September 2019 at 13:37:12 UTC, Kagamin wrote:
>> https://ddbus.dpldocs.info/ddbus.bus.requestName.html
>
> It requires a Connection type which I cannot find in the API.

It's in ddbus.thin, missing documentation comment, see unittest: https://ddbus.dpldocs.info/source/ddbus.bus.d.html#L46
September 30, 2019
On Sunday, 29 September 2019 at 02:09:56 UTC, Hossain Adnan wrote:
> On Saturday, 28 September 2019 at 13:37:12 UTC, Kagamin wrote:
>> https://ddbus.dpldocs.info/ddbus.bus.requestName.html
>
> It requires a Connection type which I cannot find in the API.

It's in ddbus.thin, missing documentation comment, see unittest: https://ddbus.dpldocs.info/source/ddbus.bus.d.html#L46 and usage example at http://code.dlang.org/packages/ddbus