-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move handling of terminal settings into separate file
- Loading branch information
1 parent
e9beaf3
commit 957d720
Showing
6 changed files
with
79 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
pub mod prerequisit; | ||
pub mod settings; | ||
pub mod terminal; | ||
pub mod toolbox; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
use crate::gio; | ||
use crate::util::terminal::TerminalType; | ||
use crate::APP_ID; | ||
use relm4::gtk::prelude::SettingsExt; | ||
|
||
pub fn get_terminal() -> TerminalType { | ||
let settings = gio::Settings::new(APP_ID); | ||
let terminal = settings.string("terminal"); | ||
terminal.as_str().try_into().unwrap_or_default() | ||
} | ||
|
||
pub fn set_terminal(terminal: TerminalType) { | ||
let settings = gio::Settings::new(APP_ID); | ||
let terminal: String = terminal.into(); | ||
settings.set_string("terminal", &terminal); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
use crate::util::toolbox::ToolbxError; | ||
use std::process::Command; | ||
|
||
#[derive(Debug, Default)] | ||
pub enum TerminalType { | ||
#[default] | ||
GnomeTerminal, | ||
Konsole, | ||
} | ||
|
||
impl From<TerminalType> for String { | ||
fn from(value: TerminalType) -> Self { | ||
match value { | ||
TerminalType::GnomeTerminal => "GnomeTerminal".to_string(), | ||
TerminalType::Konsole => "Konsole".to_string(), | ||
} | ||
} | ||
} | ||
|
||
impl TryFrom<&str> for TerminalType { | ||
type Error = (); | ||
|
||
fn try_from(value: &str) -> Result<Self, Self::Error> { | ||
Ok(TerminalType::GnomeTerminal) | ||
} | ||
} | ||
|
||
pub fn get_installed_terminals() -> Result<Vec<TerminalType>, ToolbxError> { | ||
let output = Command::new("flatpak-spawn") | ||
.arg("--host") | ||
.arg("gnome-terminal") | ||
.arg("--version") | ||
.output(); | ||
|
||
if output.is_err() { | ||
return Err(ToolbxError::CommandExecutionError( | ||
output.unwrap_err().to_string(), | ||
)); | ||
} | ||
let output = output.unwrap(); | ||
|
||
if output.status.code() == Some(0) { | ||
Ok(vec![TerminalType::GnomeTerminal, TerminalType::Konsole]) | ||
} else { | ||
Err(ToolbxError::CommandUnsuccessfulError( | ||
String::from_utf8_lossy(&output.stderr).into_owned(), | ||
)) | ||
} | ||
} |