Skip to content

Commit 7f0f663

Browse files
committed
feat: implement initial plugin functionality
0 parents  commit 7f0f663

9 files changed

Lines changed: 281 additions & 0 deletions

File tree

.github/workflows/build.yml

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
name: Build
2+
3+
on:
4+
workflow_dispatch:
5+
6+
jobs:
7+
build:
8+
name: Build for ${{ matrix.target }}
9+
runs-on: ${{ matrix.os }}
10+
strategy:
11+
matrix:
12+
include:
13+
- target: x86_64-pc-windows-msvc
14+
os: windows-latest
15+
build-ext: .exe
16+
artifact-ext: -x86_64-pc-windows-msvc.exe
17+
- target: x86_64-apple-darwin
18+
os: macos-latest
19+
build-ext: ""
20+
artifact-ext: -x86_64-apple-darwin
21+
- target: aarch64-apple-darwin
22+
os: macos-latest
23+
build-ext: ""
24+
artifact-ext: -aarch64-apple-darwin
25+
- target: x86_64-unknown-linux-gnu
26+
os: ubuntu-22.04
27+
build-ext: ""
28+
artifact-ext: -x86_64-unknown-linux-gnu
29+
- target: aarch64-unknown-linux-gnu
30+
os: ubuntu-22.04-arm
31+
build-ext: ""
32+
artifact-ext: -aarch64-unknown-linux-gnu
33+
34+
steps:
35+
- name: Checkout
36+
uses: actions/checkout@v4
37+
38+
- name: Set up Rust toolchain
39+
uses: dtolnay/rust-toolchain@stable
40+
with:
41+
targets: ${{ matrix.target }}
42+
43+
- name: Set up Rust cache
44+
uses: swatinem/rust-cache@v2
45+
with:
46+
key: ${{ matrix.target }}
47+
48+
- name: Build binary
49+
run: cargo build --release --target ${{ matrix.target }}
50+
51+
- name: Rename binary and output artifact name (Windows)
52+
if: matrix.os == 'windows-latest'
53+
id: rename_win
54+
shell: pwsh
55+
run: |
56+
$PACKAGE_NAME = (cargo metadata --no-deps --format-version 1 | ConvertFrom-Json).packages[0].name
57+
$ARTIFACT_NAME = "$PACKAGE_NAME${{ matrix.artifact-ext }}"
58+
Move-Item "target\${{ matrix.target }}\release\$PACKAGE_NAME${{ matrix.build-ext }}" $ARTIFACT_NAME
59+
echo "artifact_name=$ARTIFACT_NAME" >> $env:GITHUB_OUTPUT
60+
61+
- name: Rename binary and output artifact name (Unix)
62+
if: matrix.os != 'windows-latest'
63+
id: rename_unix
64+
shell: bash
65+
run: |
66+
PACKAGE_NAME=$(cargo metadata --no-deps --format-version 1 | jq -r ".packages[0].name")
67+
ARTIFACT_NAME="${PACKAGE_NAME}${{ matrix.artifact-ext }}"
68+
mv "target/${{ matrix.target }}/release/${PACKAGE_NAME}${{ matrix.build-ext }}" "$ARTIFACT_NAME"
69+
echo "artifact_name=$ARTIFACT_NAME" >> $GITHUB_OUTPUT
70+
71+
- name: Upload artifact
72+
uses: actions/upload-artifact@v4
73+
with:
74+
name: ${{ steps.rename_win.outputs.artifact_name || steps.rename_unix.outputs.artifact_name }}
75+
path: ${{ steps.rename_win.outputs.artifact_name || steps.rename_unix.outputs.artifact_name }}
76+
compression-level: 0

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
target/
2+
Cargo.lock

Cargo.toml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[package]
2+
name = "oasystem"
3+
edition = "2024"
4+
5+
[dependencies]
6+
openaction = "2.1"
7+
serde = "1.0"
8+
tokio = { version = "1.47", features = ["rt-multi-thread", "macros", "time"] }
9+
log = "0.4"
10+
simplelog = "0.12"
11+
sysinfo = "0.37"

LICENSE

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
MIT License
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is
8+
furnished to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in all
11+
copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19+
SOFTWARE.

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
## OpenAction System Information plugin
2+
3+
An OpenAction ([OpenDeck](https://github.com/nekename/OpenDeck) / [Tacto](https://tacto.rivul.us)) plugin for displaying system information
4+
5+
#### Actions
6+
7+
- CPU
8+
- RAM
9+
- Uptime
10+
- OS

assets/icon.png

878 KB
Loading

assets/manifest.json

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
{
2+
"Name": "System Information",
3+
"Author": "nekename",
4+
"Version": "1.0.0",
5+
"Category": "System Information",
6+
"Icon": "icon",
7+
"OS": [{ "Platform": "windows" }, { "Platform": "mac" }, { "Platform": "linux" }],
8+
"CodePaths": {
9+
"x86_64-pc-windows-msvc": "oasystem-x86_64-pc-windows-msvc.exe",
10+
"x86_64-apple-darwin": "oasystem-x86_64-apple-darwin",
11+
"aarch64-apple-darwin": "oasystem-aarch64-apple-darwin",
12+
"x86_64-unknown-linux-gnu": "oasystem-x86_64-unknown-linux-gnu",
13+
"aarch64-unknown-linux-gnu": "oasystem-aarch64-unknown-linux-gnu"
14+
},
15+
"CodePathWin": "oasystem-x86_64-pc-windows-msvc.exe",
16+
"CodePathMac": "oasystem-x86_64-apple-darwin",
17+
"CodePathLin": "oasystem-x86_64-unknown-linux-gnu",
18+
"Actions": [
19+
{
20+
"UUID": "me.amankhanna.oasystem.cpu",
21+
"Name": "CPU",
22+
"Icon": "icon",
23+
"Tooltip": "Displays average CPU utilisation",
24+
"Controllers": ["Keypad", "Encoder"],
25+
"States": [{ "Title": "0%", "FontSize": 16 }]
26+
},
27+
{
28+
"UUID": "me.amankhanna.oasystem.ram",
29+
"Name": "RAM",
30+
"Icon": "icon",
31+
"Tooltip": "Displays RAM utilisation",
32+
"Controllers": ["Keypad", "Encoder"],
33+
"States": [{ "Title": "0GB", "FontSize": 14 }]
34+
},
35+
{
36+
"UUID": "me.amankhanna.oasystem.uptime",
37+
"Name": "Uptime",
38+
"Icon": "icon",
39+
"Tooltip": "Displays system uptime",
40+
"Controllers": ["Keypad", "Encoder"],
41+
"States": [{ "Title": "00:00.00", "FontSize": 12 }]
42+
},
43+
{
44+
"UUID": "me.amankhanna.oasystem.os",
45+
"Name": "OS",
46+
"Icon": "icon",
47+
"Tooltip": "Displays operating system information",
48+
"Controllers": ["Keypad", "Encoder"],
49+
"States": [{ "Title": "Unknown", "FontSize": 12 }]
50+
}
51+
]
52+
}

rustfmt.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
hard_tabs = true
2+
newline_style = "Unix"

src/main.rs

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
use std::collections::HashMap;
2+
3+
use openaction::*;
4+
5+
use sysinfo::System;
6+
7+
struct CPUAction;
8+
#[async_trait]
9+
impl Action for CPUAction {
10+
const UUID: ActionUuid = "me.amankhanna.oasystem.cpu";
11+
type Settings = HashMap<String, String>;
12+
}
13+
14+
struct RAMAction;
15+
#[async_trait]
16+
impl Action for RAMAction {
17+
const UUID: ActionUuid = "me.amankhanna.oasystem.ram";
18+
type Settings = HashMap<String, String>;
19+
}
20+
21+
struct UptimeAction;
22+
#[async_trait]
23+
impl Action for UptimeAction {
24+
const UUID: ActionUuid = "me.amankhanna.oasystem.uptime";
25+
type Settings = HashMap<String, String>;
26+
}
27+
28+
struct OSAction;
29+
#[async_trait]
30+
impl Action for OSAction {
31+
const UUID: ActionUuid = "me.amankhanna.oasystem.os";
32+
type Settings = HashMap<String, String>;
33+
34+
async fn will_appear(
35+
&self,
36+
instance: &Instance,
37+
_settings: &Self::Settings,
38+
) -> OpenActionResult<()> {
39+
instance
40+
.set_title(
41+
Some(
42+
System::long_os_version()
43+
.unwrap_or_else(|| "Unknown".to_owned())
44+
.replace(" ", "\n"),
45+
),
46+
None,
47+
)
48+
.await
49+
}
50+
}
51+
52+
#[tokio::main]
53+
async fn main() -> OpenActionResult<()> {
54+
{
55+
use simplelog::*;
56+
if let Err(error) = TermLogger::init(
57+
LevelFilter::Debug,
58+
Config::default(),
59+
TerminalMode::Stdout,
60+
ColorChoice::Never,
61+
) {
62+
eprintln!("Logger initialization failed: {}", error);
63+
}
64+
}
65+
66+
tokio::spawn(async {
67+
let mut system = System::new_all();
68+
loop {
69+
system.refresh_cpu_usage();
70+
tokio::time::sleep(std::time::Duration::from_secs(1)).await;
71+
system.refresh_cpu_usage();
72+
73+
let cpu_usage = format!("{:.0}%", system.global_cpu_usage());
74+
for instance in visible_instances(CPUAction::UUID).await {
75+
let _ = instance.set_title(Some(cpu_usage.clone()), None).await;
76+
}
77+
78+
system.refresh_memory();
79+
let ram_usage = format!("{:.1}GB", (system.used_memory() as f32) / 1073741824.0);
80+
for instance in visible_instances(RAMAction::UUID).await {
81+
let _ = instance.set_title(Some(ram_usage.clone()), None).await;
82+
}
83+
84+
{
85+
let total_secs = System::uptime();
86+
let days = total_secs / 86_400;
87+
let hours = (total_secs % 86_400) / 3600;
88+
let minutes = (total_secs % 3600) / 60;
89+
let seconds = total_secs % 60;
90+
91+
for instance in visible_instances(UptimeAction::UUID).await {
92+
let _ = instance
93+
.set_title(
94+
Some(format!("{days}d {hours:02}h\n{minutes:02}m {seconds:02}s")),
95+
None,
96+
)
97+
.await;
98+
}
99+
}
100+
}
101+
});
102+
103+
register_action(CPUAction).await;
104+
register_action(RAMAction).await;
105+
register_action(UptimeAction).await;
106+
register_action(OSAction).await;
107+
108+
run(std::env::args().collect()).await
109+
}

0 commit comments

Comments
 (0)