Skip to content

Commit 3b9ddef

Browse files
[TMP] Preliminary support for PIN/passkey input
Signed-off-by: Muhammad Asif <thevancedgamer@mentallysanemainliners.org>
1 parent 73c7051 commit 3b9ddef

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

src/agent.vala

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,30 @@
11
[DBus (name = "org.bluez.Agent1")]
22
public class Agent: Object
33
{
4+
public GLib.Menu menu;
5+
public GLib.SimpleActionGroup actions;
6+
7+
private GLib.SimpleAction pin_action;
48
private MainLoop loop;
59
private Bluetooth bluetooth;
610

711
public Agent (Bluetooth bluez)
812
{
13+
// Menu
14+
menu = new GLib.Menu ();
15+
GLib.MenuItem item = new GLib.MenuItem ("PIN", "password");
16+
item.set_attribute_value ("x-canonical-type", new Variant.string ("com.canonical.snapdecision.textfield"));
17+
item.set_attribute_value ("x-echo-mode-password", new Variant.boolean (false));
18+
menu.append_item (item);
19+
20+
// Actions
21+
actions = new GLib.SimpleActionGroup ();
22+
pin_action = new GLib.SimpleAction.stateful ("password", null, new Variant.string (""));
23+
pin_action.change_state.connect ((value) => {
24+
warning ("HELLO!");
25+
});
26+
actions.add_action (pin_action);
27+
928
loop = new MainLoop (null, false);
1029
bluetooth = bluez;
1130
Notify.init ("ayatana-indicator-bluetooth");
@@ -22,6 +41,22 @@ public class Agent: Object
2241
{
2342
notification.set_hint ("x-lomiri-snap-decisions", true);
2443
notification.set_hint ("x-lomiri-private-affirmative-tint", "true");
44+
45+
VariantBuilder actions_builder = new VariantBuilder (new VariantType ("a{sv}"));
46+
actions_builder.add ("{sv}", "notifications", new Variant.string ("/agent/actions"));
47+
Variant actions = actions_builder.end ();
48+
49+
VariantBuilder builder = new VariantBuilder (new VariantType ("a{sv}"));
50+
builder.add ("{sv}", "busName", new Variant.string ("org.ayatana.indicator.bluetooth"));
51+
builder.add ("{sv}", "menuPath", new Variant.string ("/agent/menu"));
52+
builder.add ("{sv}", "actions", actions);
53+
Variant stuff = builder.end ();
54+
55+
notification.set_hint ("x-lomiri-private-menu-model", stuff);
56+
57+
string some_shit = actions.print(true);
58+
string other_shit = stuff.print(true);
59+
warning (@"we got some stuff! $some_shit $other_shit");
2560
}
2661

2762
notification.add_action("yes_id", "Yes", (notif, action) => {

src/service.vala

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,10 @@ public class Service: Object
3030
private SimpleActionGroup actions;
3131
private HashTable<string,Profile> profiles;
3232
private Bluetooth bluetooth;
33+
private Agent agent;
3334
private DBusConnection connection;
3435
private uint exported_action_id;
36+
private uint exported_agent_action_id;
3537
private const string OBJECT_PATH = "/org/ayatana/indicator/bluetooth";
3638

3739
private void unexport ()
@@ -54,6 +56,7 @@ public class Service: Object
5456
{
5557
actions = new SimpleActionGroup ();
5658
bluetooth = bluetooth_service;
59+
agent = new Agent (bluetooth);
5760

5861
profiles = new HashTable<string,Profile> (str_hash, str_equal);
5962
profiles.insert ("phone", new Phone (bluetooth, actions));
@@ -101,7 +104,7 @@ public class Service: Object
101104
{
102105
try
103106
{
104-
connection.register_object ("/agent", new Agent (bluetooth));
107+
connection.register_object ("/agent", agent);
105108
}
106109
catch (GLib.IOError pError)
107110
{
@@ -119,6 +122,10 @@ public class Service: Object
119122
debug (@"exporting action group '$(OBJECT_PATH)'");
120123
exported_action_id = connection.export_action_group (OBJECT_PATH,
121124
actions);
125+
126+
exported_agent_action_id = connection.export_action_group ("/agent/actions",
127+
agent.actions);
128+
connection.export_menu_model ("/agent/menu", agent.menu);
122129
}
123130
catch (Error e)
124131
{

0 commit comments

Comments
 (0)