Skip to content

Commit 8ffb7eb

Browse files
committed
port: Location
1 parent 28e2d80 commit 8ffb7eb

File tree

1 file changed

+29
-17
lines changed

1 file changed

+29
-17
lines changed

src/Location/main.ts

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
import Adw from "gi://Adw";
12
import Gio from "gi://Gio";
3+
import Gtk from "gi://Gtk?version=4.0";
24
import Xdp from "gi://Xdp";
35
import XdpGtk from "gi://XdpGtk4";
46

@@ -11,23 +13,31 @@ Gio._promisify(
1113
const portal = new Xdp.Portal();
1214
const parent = XdpGtk.parent_new_gtk(workbench.window);
1315

14-
const revealer = workbench.builder.get_object("revealer");
15-
const start = workbench.builder.get_object("start");
16-
const close = workbench.builder.get_object("close");
17-
const distance_threshold = workbench.builder.get_object("distance_threshold");
18-
const time_threshold = workbench.builder.get_object("time_threshold");
19-
const accuracy_button = workbench.builder.get_object("accuracy_button");
16+
const revealer = workbench.builder.get_object<Gtk.Revealer>("revealer");
17+
const start = workbench.builder.get_object<Gtk.Button>("start");
18+
const close = workbench.builder.get_object<Gtk.Button>("close");
19+
const distance_threshold = workbench.builder.get_object<Adw.SpinRow>(
20+
"distance_threshold",
21+
);
22+
const time_threshold = workbench.builder.get_object<Adw.SpinRow>(
23+
"time_threshold",
24+
);
25+
const accuracy_button = workbench.builder.get_object<Adw.ComboRow>(
26+
"accuracy_button",
27+
);
2028

21-
const latitude_label = workbench.builder.get_object("latitude");
22-
const longitude_label = workbench.builder.get_object("longitude");
23-
const accuracy_label = workbench.builder.get_object("accuracy");
24-
const altitude_label = workbench.builder.get_object("altitude");
25-
const speed_label = workbench.builder.get_object("speed");
26-
const heading_label = workbench.builder.get_object("heading");
27-
const description_label = workbench.builder.get_object("description");
28-
const timestamp_label = workbench.builder.get_object("timestamp");
29+
const latitude_label = workbench.builder.get_object<Gtk.Label>("latitude");
30+
const longitude_label = workbench.builder.get_object<Gtk.Label>("longitude");
31+
const accuracy_label = workbench.builder.get_object<Gtk.Label>("accuracy");
32+
const altitude_label = workbench.builder.get_object<Gtk.Label>("altitude");
33+
const speed_label = workbench.builder.get_object<Gtk.Label>("speed");
34+
const heading_label = workbench.builder.get_object<Gtk.Label>("heading");
35+
const description_label = workbench.builder.get_object<Gtk.Label>(
36+
"description",
37+
);
38+
const timestamp_label = workbench.builder.get_object<Gtk.Label>("timestamp");
2939

30-
let locationAccuracy = Xdp.LocationAccuracy.Exact;
40+
let locationAccuracy = Xdp.LocationAccuracy.EXACT;
3141
let distanceThresholdValue = distance_threshold.value;
3242
let timeThresholdValue = time_threshold.value;
3343

@@ -51,22 +61,24 @@ accuracy_button.connect("notify::selected-item", () => {
5161
console.log("Accuracy changed");
5262
portal.location_monitor_stop();
5363
revealer.reveal_child = false;
54-
const accuracy_flag = accuracy_button.selected_item.get_string();
64+
const accuracy_flag = (accuracy_button.selected_item as Gtk.StringObject)
65+
.get_string();
5566
locationAccuracy = Xdp.LocationAccuracy[accuracy_flag];
5667
startSession();
5768
});
5869

5970
async function startSession() {
6071
start.sensitive = false;
6172
close.sensitive = true;
73+
// @ts-expect-error undetected async function
6274
const result = await portal.location_monitor_start(
6375
parent,
6476
distanceThresholdValue,
6577
timeThresholdValue,
6678
locationAccuracy,
6779
Xdp.LocationMonitorFlags.NONE,
6880
null,
69-
);
81+
) as boolean;
7082
if (result === true) {
7183
console.log("Location access granted");
7284
revealer.reveal_child = true;

0 commit comments

Comments
 (0)