Skip to content

Commit

Permalink
Merge pull request #45 from swsnr/swsnr/issue4
Browse files Browse the repository at this point in the history
Scan devices from ARP cache
  • Loading branch information
swsnr authored Dec 19, 2024
2 parents eaa426b + 73f3da4 commit 940dd46
Show file tree
Hide file tree
Showing 23 changed files with 775 additions and 69 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ macaddr = { version = "1.0.1", default-features = false }
serde = { version = "1.0.210", features = ["derive"] }
serde_json = "1.0.128"
socket2 = "0.5.7"
bitflags = "2.6.0"

[build-dependencies]
glob = "0.3.1"
Expand Down
14 changes: 13 additions & 1 deletion resources/de.swsnr.turnon.metainfo.xml.in
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
<p>Features:</p>
<ul>
<li>Add devices to turn on.</li>
<li>Turn on devices with magic Wake On LAN (WoL) packets.</li>
<li>Discover devices in the local network.</li>
<li>Monitor device status.</li>
<li>Turn on devices with magic Wake On LAN (WoL) packets.</li>
<li>Turn on devices from GNOME Shell search.</li>
<li>Turn on devices from the command line.</li>
</ul>
Expand All @@ -30,6 +31,17 @@
<url type="contribute">https://github.com/swsnr/turnon</url>
<launchable type="desktop-id">de.swsnr.turnon.desktop</launchable>
<releases>
<release version="next" date="9999-01-01">
<description>
<p>Add a toolbar button to enable or disable network scanning.</p>
<p>When network scanning is enabled show devices from the system's ARP cache.</p>
<p>Add a button to directly add devices discovered from network scanning.</p>
</description>
<issues>
<issue url="https://github.com/swsnr/turnon/issues/4">GH-4</issue>
</issues>
<url>https://github.com/swsnr/turnon/releases/tag/next</url>
</release>
<release version="1.6.2" date="2024-12-12">
<description>
<p>The dialog to add a new device now uses success and error styles for the validity indicators.</p>
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions resources/resources.gresource.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@
<file compressed="true" preprocess="xml-stripblanks">gtk/help-overlay.ui</file>
<!-- Icons -->
<file preprocess="xml-stripblanks">icons/scalable/actions/sonar-symbolic.svg</file>
<file preprocess="xml-stripblanks">icons/scalable/actions/waves-and-screen-symbolic.svg</file>
<file preprocess="xml-stripblanks">icons/scalable/apps/de.swsnr.turnon.svg</file>
<file preprocess="xml-stripblanks">icons/scalable/apps/de.swsnr.turnon-symbolic.svg</file>
<file preprocess="xml-stripblanks">icons/scalable/apps/de.swsnr.turnon.Devel.svg</file>
<!-- Other data files -->
<file compressed="true">style.css</file>
<file compressed="true" preprocess="xml-stripblanks">de.swsnr.turnon.metainfo.xml</file>
</gresource>
</gresources>
5 changes: 5 additions & 0 deletions resources/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/* Dim labels of discovered devices */
row.discovered .title > .title,
row.discovered .suffixes .title {
opacity: var(--dim-opacity);
}
20 changes: 17 additions & 3 deletions resources/ui/device-row.blp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ template $DeviceRow: Adw.ActionRow {

[prefix]
Gtk.Stack {
visible-child-name: bind $device_state_name(template.is_device_online) as <string>;
visible-child-name: bind $device_state_name(template.is-device-online) as <string>;

Gtk.StackPage {
name: "offline";
Expand Down Expand Up @@ -48,12 +48,12 @@ template $DeviceRow: Adw.ActionRow {
label: bind (template.device as <$Device>).host;

styles [
"dim-label"
"title"
]
}

Gtk.Stack {
visible-child-name: bind template.suffix_mode;
visible-child-name: bind template.suffix-mode;
margin-start: 12;
hhomogeneous: false;
transition-type: slide_left_right;
Expand All @@ -64,11 +64,24 @@ template $DeviceRow: Adw.ActionRow {
child: Gtk.Box {
orientation: horizontal;

Gtk.Button {
icon-name: "list-add-symbolic";
tooltip-text: C_("device-row.action.row.add.tooltip", "Add this device");
action-name: "row.add";
valign: center;
visible: bind template.can-add;

styles [
"flat"
]
}

Gtk.Button {
icon-name: "document-edit-symbolic";
tooltip-text: C_("device-row.action.row.edit.tooltip", "Edit this device");
action-name: "row.edit";
valign: center;
visible: bind template.can-edit;

styles [
"flat"
Expand All @@ -81,6 +94,7 @@ template $DeviceRow: Adw.ActionRow {
action-name: "row.ask_delete";
margin-start: 6;
valign: center;
visible: bind template.can-delete;

styles [
"flat"
Expand Down
20 changes: 17 additions & 3 deletions resources/ui/device-row.ui
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ corresponding .blp file and regenerate this file with blueprint-compiler.
<object class="GtkStack">
<binding name="visible-child-name">
<closure function="device_state_name" type="gchararray">
<lookup name="is_device_online" type="DeviceRow">
<lookup name="is-device-online" type="DeviceRow">
<constant>DeviceRow</constant>
</lookup>
</closure>
Expand Down Expand Up @@ -73,13 +73,13 @@ corresponding .blp file and regenerate this file with blueprint-compiler.
</lookup>
</binding>
<style>
<class name="dim-label"/>
<class name="title"/>
</style>
</object>
</child>
<child>
<object class="GtkStack">
<property name="visible-child-name" bind-source="DeviceRow" bind-property="suffix_mode" bind-flags="sync-create"/>
<property name="visible-child-name" bind-source="DeviceRow" bind-property="suffix-mode" bind-flags="sync-create"/>
<property name="margin-start">12</property>
<property name="hhomogeneous">false</property>
<property name="transition-type">6</property>
Expand All @@ -89,12 +89,25 @@ corresponding .blp file and regenerate this file with blueprint-compiler.
<property name="child">
<object class="GtkBox">
<property name="orientation">0</property>
<child>
<object class="GtkButton">
<property name="icon-name">list-add-symbolic</property>
<property name="tooltip-text" translatable="yes" context="device-row.action.row.add.tooltip">Add this device</property>
<property name="action-name">row.add</property>
<property name="valign">3</property>
<property name="visible" bind-source="DeviceRow" bind-property="can-add" bind-flags="sync-create"/>
<style>
<class name="flat"/>
</style>
</object>
</child>
<child>
<object class="GtkButton">
<property name="icon-name">document-edit-symbolic</property>
<property name="tooltip-text" translatable="yes" context="device-row.action.row.edit.tooltip">Edit this device</property>
<property name="action-name">row.edit</property>
<property name="valign">3</property>
<property name="visible" bind-source="DeviceRow" bind-property="can-edit" bind-flags="sync-create"/>
<style>
<class name="flat"/>
</style>
Expand All @@ -107,6 +120,7 @@ corresponding .blp file and regenerate this file with blueprint-compiler.
<property name="action-name">row.ask_delete</property>
<property name="margin-start">6</property>
<property name="valign">3</property>
<property name="visible" bind-source="DeviceRow" bind-property="can-delete" bind-flags="sync-create"/>
<style>
<class name="flat"/>
</style>
Expand Down
7 changes: 7 additions & 0 deletions resources/ui/turnon-application-window.blp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ template $TurnOnApplicationWindow: Adw.ApplicationWindow {
tooltip-text: C_("application-window.action.win.add-device.tooltip", "Add a new device");
}

[start]
Gtk.ToggleButton toggle_scan_network {
action-name: "win.toggle-scan-network";
icon-name: "waves-and-screen-symbolic";
tooltip-text: C_("application-window.action.win.scan-network.tooltip", "Scan the network for devices");
}

[end]
MenuButton button_menu {
menu-model: main_menu;
Expand Down
7 changes: 7 additions & 0 deletions resources/ui/turnon-application-window.ui
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ corresponding .blp file and regenerate this file with blueprint-compiler.
<property name="tooltip-text" translatable="yes" context="application-window.action.win.add-device.tooltip">Add a new device</property>
</object>
</child>
<child type="start">
<object class="GtkToggleButton" id="toggle_scan_network">
<property name="action-name">win.toggle-scan-network</property>
<property name="icon-name">waves-and-screen-symbolic</property>
<property name="tooltip-text" translatable="yes" context="application-window.action.win.scan-network.tooltip">Scan the network for devices</property>
</object>
</child>
<child type="end">
<object class="GtkMenuButton" id="button_menu">
<property name="menu-model">main_menu</property>
Expand Down
3 changes: 3 additions & 0 deletions screenshots/arp
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
IP address HW type Flags HW address Mask Device
192.168.2.100 0x1 0x2 62:6f:a3:f8:3e:ef * eth0
192.168.2.101 0x1 0x2 a3:6f:7f:3a:9d:ff * eth0
5 changes: 4 additions & 1 deletion screenshots/run-for-screenshot.bash
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

set -euo pipefail

DEVICES_FILE="${1:-"$(git rev-parse --show-toplevel)/screenshots/devices.json"}"

variables=(
# Run app with default settings: Force the in-memory gsettings backend to
# block access to standard Gtk settings, and tell Adwaita not to access
Expand All @@ -14,4 +16,5 @@ variables=(
)

exec env "${variables[@]}" cargo run -- \
--devices-file "$(git rev-parse --show-toplevel)/screenshots/devices.json"
--devices-file "${DEVICES_FILE}" \
--arp-cache-file "$(git rev-parse --show-toplevel)/screenshots/arp"
Loading

0 comments on commit 940dd46

Please sign in to comment.