Skip to content

Commit 76e027f

Browse files
authored
Update actions.rs
1 parent 5fa5efc commit 76e027f

File tree

1 file changed

+93
-54
lines changed

1 file changed

+93
-54
lines changed

source-code/src/actions.rs

Lines changed: 93 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,93 @@
1-
import os
2-
import webbrowser
3-
import subprocess
4-
5-
class Actions:
6-
def __init__(self, window):
7-
self.window = window
8-
9-
def run_command_with_feedback(self, cmd):
10-
"""Uruchamianie komend z feedbackiem."""
11-
full_cmd = f"bash -c '{cmd}'"
12-
result = os.system(f"pkexec {full_cmd}")
13-
cmd_name = cmd.split('/')[-1] if '/' in cmd else cmd
14-
if result == 0:
15-
self.window.subtitle_label.set_label(f"Uruchomiono: {cmd_name}.")
16-
else:
17-
self.window.subtitle_label.set_label(f"Błąd podczas uruchamiania: {cmd_name}.")
18-
19-
def open_website(self):
20-
webbrowser.open("https://hackeros-linux-system.github.io/HackerOS-Website/Home-page.html")
21-
self.window.subtitle_label.set_label("Otworzono stronę HackerOS.")
22-
23-
def open_x(self):
24-
webbrowser.open("https://x.com/hackeros_linux")
25-
self.window.subtitle_label.set_label("Otworzono X.")
26-
27-
def open_software(self):
28-
result = os.system("gnome-software &")
29-
self.window.subtitle_label.set_label("Uruchomiono Sklep z aplikacjami.")
30-
31-
def open_changelog(self):
32-
webbrowser.open("https://hackeros-linux-system.github.io/HackerOS-Website/releases.html")
33-
self.window.subtitle_label.set_label("Otworzono Changelog.")
34-
35-
def open_system_info(self):
36-
webbrowser.open("https://hackeros-linux-system.github.io/HackerOS-Website/about-hackeros.html")
37-
self.window.subtitle_label.set_label("Otworzono Informacje o systemie.")
38-
39-
def report_bug(self):
40-
webbrowser.open("https://github.com/HackerOS-Linux-System/HackerOS-Website/issues")
41-
self.window.subtitle_label.set_label("Otworzono Zgłoś błąd.")
42-
43-
def open_forum(self):
44-
webbrowser.open("https://github.com/HackerOS-Linux-System/HackerOS-Website/discussions")
45-
self.window.subtitle_label.set_label("Otworzono Forum dyskusyjne.")
46-
47-
def update_system(self):
48-
# Otwiera terminal z komendą hacker update, potem pyta o zamknięcie
49-
terminal_cmd = 'alacritty -e bash -c "hacker update; read -p \'Chcesz zamknąć terminal? (t/n) \' answer; if [ \"$answer\" = \'t\' ]; then exit; else echo \'Terminal pozostanie otwarty.\'; read; fi"'
50-
result = os.system(terminal_cmd)
51-
if result == 0:
52-
self.window.subtitle_label.set_label("Rozpoczęto aktualizację systemu w terminalu.")
53-
else:
54-
self.window.subtitle_label.set_label("Błąd podczas uruchamiania aktualizacji systemu.")
1+
// src/actions.rs
2+
use gtk::prelude::*;
3+
use gtk::Label;
4+
use std::process::Command;
5+
use webbrowser;
6+
7+
pub struct Actions {
8+
pub subtitle_label: Option<Label>,
9+
}
10+
11+
impl Actions {
12+
pub fn new() -> Self {
13+
Actions {
14+
subtitle_label: None,
15+
}
16+
}
17+
18+
fn update_subtitle(&self, text: &str) {
19+
if let Some(label) = &self.subtitle_label {
20+
label.set_label(text);
21+
}
22+
}
23+
24+
pub fn run_command_with_feedback(&self, cmd: &str) {
25+
let full_cmd = format!("bash -c '{}'", cmd);
26+
let result = Command::new("pkexec")
27+
.arg(&full_cmd)
28+
.status();
29+
30+
let cmd_name = cmd.split('/').last().unwrap_or(cmd);
31+
match result {
32+
Ok(status) if status.success() => self.update_subtitle(&format!("Uruchomiono: {}.", cmd_name)),
33+
_ => self.update_subtitle(&format!("Błąd podczas uruchamiania: {}.", cmd_name)),
34+
}
35+
}
36+
37+
pub fn open_website(&self) {
38+
if webbrowser::open("https://hackeros-linux-system.github.io/HackerOS-Website/Home-page.html").is_ok() {
39+
self.update_subtitle("Otworzono stronę HackerOS.");
40+
}
41+
}
42+
43+
pub fn open_x(&self) {
44+
if webbrowser::open("https://x.com/hackeros_linux").is_ok() {
45+
self.update_subtitle("Otworzono X.");
46+
}
47+
}
48+
49+
pub fn open_software(&self) {
50+
if Command::new("gnome-software").spawn().is_ok() {
51+
self.update_subtitle("Uruchomiono Sklep z aplikacjami.");
52+
} else {
53+
self.update_subtitle("Błąd podczas uruchamiania Sklep z aplikacjami.");
54+
}
55+
}
56+
57+
pub fn open_changelog(&self) {
58+
if webbrowser::open("https://hackeros-linux-system.github.io/HackerOS-Website/releases.html").is_ok() {
59+
self.update_subtitle("Otworzono Changelog.");
60+
}
61+
}
62+
63+
pub fn open_system_info(&self) {
64+
if webbrowser::open("https://hackeros-linux-system.github.io/HackerOS-Website/about-hackeros.html").is_ok() {
65+
self.update_subtitle("Otworzono Informacje o systemie.");
66+
}
67+
}
68+
69+
pub fn report_bug(&self) {
70+
if webbrowser::open("https://github.com/HackerOS-Linux-System/HackerOS-Website/issues").is_ok() {
71+
self.update_subtitle("Otworzono Zgłoś błąd.");
72+
}
73+
}
74+
75+
pub fn open_forum(&self) {
76+
if webbrowser::open("https://github.com/HackerOS-Linux-System/HackerOS-Website/discussions").is_ok() {
77+
self.update_subtitle("Otworzono Forum dyskusyjne.");
78+
}
79+
}
80+
81+
pub fn update_system(&self) {
82+
let terminal_cmd = "alacritty -e bash -c \"hacker update; read -p 'Chcesz zamknąć terminal? (t/n) ' answer; if [ \"$answer\" = 't' ]; then exit; else echo 'Terminal pozostanie otwarty.'; read; fi\"";
83+
let result = Command::new("sh")
84+
.arg("-c")
85+
.arg(terminal_cmd)
86+
.status();
87+
88+
match result {
89+
Ok(status) if status.success() => self.update_subtitle("Rozpoczęto aktualizację systemu w terminalu."),
90+
_ => self.update_subtitle("Błąd podczas uruchamiania aktualizacji systemu."),
91+
}
92+
}
93+
}

0 commit comments

Comments
 (0)