Skip to content

Commit

Permalink
mwp! (also added screenshot)
Browse files Browse the repository at this point in the history
  • Loading branch information
toger5 committed Mar 31, 2021
1 parent 5c1fdd8 commit 01fd372
Show file tree
Hide file tree
Showing 8 changed files with 130 additions and 104 deletions.
33 changes: 17 additions & 16 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 @@ -15,6 +15,7 @@ num-traits = "0.2"
num-derive = "0.2"
pango = "0.9.1"
libc = "0.2.91"
gdk = "0.13.2"

[dependencies.gtk]
version = "0.9.2"
Expand Down
2 changes: 1 addition & 1 deletion build-aux/flatpak-install.sh
Original file line number Diff line number Diff line change
@@ -1 +1 @@
flatpak-builder --install .flatpak-app-dir build-aux/com.github.spectre.json --force-clean --user -y
flatpak-builder --install .flatpak-app-dir build-aux/com.github.spectre.json --force-clean --user -y
Binary file added data/Screenshot_login.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion data/com.github.spectre.desktop
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[Desktop Entry]
Name=Rust Flatpak Spectre
Name=Spectre password
Comment=Rust Flapaked Gtk Spectre application
Type=Application
# should be the same as the Cargo project name
Expand Down
21 changes: 5 additions & 16 deletions data/com.github.spectre.metainfo.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,33 +19,22 @@
It is now.
</p>
</description>
<!-- <screenshots>
<screenshot type="default">
<image>https://gitlab.gnome.org/World/design/contrast/raw/master/data/resources/screenshots/screenshot1.png</image>
<caption>Main Window</caption>
</screenshot>
</screenshots>
<screenshots>
<screenshot type="default">
<image></image>
<caption>Main Window</caption>
<image>data/Screenshot_login.png</image>
<caption>Login window</caption>
</screenshot>
</screenshots> -->
</screenshots>
<url type="homepage">https://github.com/toger5/Spectre-gtk</url>
<!--
Open Age Rating Service
https://hughsie.github.io/oars/index.html
-->
<content_rating type="oars-1.0" />
<releases>
<release version="0.0.1" date="2020-02-08">
<release version="0.0.2" date="2021-03-31">
<description>
<p>First release of the Spectre Rust Flatpak App</p>
<p>First release of the Spectre Rust Flatpak App. Nothing works but all the important pices are figured out (distribution, binding to the Spectre api repo)</p>
</description>
</release>
</releases>
<developer_name>Timo</developer_name>
<update_contact>@toger5:matrix.org</update_contact>

<launchable type="desktop-id">com.github.spectre.desktop</launchable>
</component>
55 changes: 38 additions & 17 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ use std::ffi::{CStr, CString};
use std::mem;
use std::rc::Rc;
use gio::ApplicationCommandLineExt;

extern crate gio;
extern crate gtk;
extern crate gdk;
extern crate libc;

use gio::prelude::*;
Expand Down Expand Up @@ -130,15 +130,30 @@ fn build_ui(application: &gtk::Application, mut windows: Rc<RefCell<HashMap<Stri
let s_store = site_list_store.clone();
let windows_clone = windows.clone();
spectre_entry.connect_activate(move |_| {

let mut path = dirs::config_dir().unwrap();
path.push(format!("{}", name.get_text().as_str()));
path.set_extension("mpsites");

// check if user already exists:
if path.exists() {
*usr.borrow_mut() = spectre::User::authenticate(path, pwd.get_text().as_str().to_string());
}else{
let u = spectre::User::create(
"Test",
"Testpwd",
spectre::AlgorithmVersionDefault,
);
*usr.borrow_mut() = Some(spectre::User::create(
name.get_text().as_str(),
pwd.get_text().as_str(),
spectre::AlgorithmVersionDefault,
));
}
// change to load file instead of create user
*usr.borrow_mut() = Some(spectre::User::create(
name.get_text().as_str(),
pwd.get_text().as_str(),
spectre::AlgorithmVersionDefault,
));
usr.borrow_mut().as_mut().unwrap().load_sites_from_file();
// usr.borrow_mut().as_mut().unwrap().load_sites_from_file();

*m_k.borrow_mut() = Some(spectre::master_key(
*m_k.borrow_mut() = Some(spectre::user_key(
name.get_text().as_str(),
pwd.get_text().as_str(),
spectre::AlgorithmVersionDefault,
Expand Down Expand Up @@ -189,7 +204,7 @@ fn build_ui(application: &gtk::Application, mut windows: Rc<RefCell<HashMap<Stri
let s_store = site_list_store.clone();
pwd_entry_big.connect_activate(move |entry| {
// log_win.hide();
pwd_win.hide();

let m_k = m_k.borrow().expect("NO MASTER KEY GOT DAMMIT");
let site_name = entry.get_text();
let pwd = spectre::site_result(
Expand All @@ -198,6 +213,19 @@ fn build_ui(application: &gtk::Application, mut windows: Rc<RefCell<HashMap<Stri
password_type,
spectre::AlgorithmVersionDefault,
);
let atom = gdk::Atom::intern("CLIPBOARD");
let clipboard = gtk::Clipboard::get(&atom);

// pwd_win.get_clipboard(gtk::Atom::intern("GDK_SELECTION_CLIPBOARD"))
// .expect("There is no default Clipboard")
clipboard.set_text(&pwd);
// gtk::Clipboard::get_default(
// &pwd_win
// .get_display(),
// )
println!("pwd for site {} ({:}) saved to clipboard",site_name.as_str(), spectre::c_char_to_string(usr.borrow().unwrap().userName));

pwd_win.hide();
let mut exists = false;
for s in usr.borrow().unwrap().get_sites() {
unsafe {
Expand All @@ -208,7 +236,7 @@ fn build_ui(application: &gtk::Application, mut windows: Rc<RefCell<HashMap<Stri
}

if !exists {
print!("The site does not exist!!!");
println!("The site does not exist!!! -> gets created");
//TODO: show popup
usr.borrow_mut().as_mut().unwrap().add_site(
site_name.as_str(),
Expand All @@ -225,13 +253,6 @@ fn build_ui(application: &gtk::Application, mut windows: Rc<RefCell<HashMap<Stri
// reload site list:
fill_site_list(&s_store, &usr.borrow().expect("no User while filling site list"))
}
gtk::Clipboard::get_default(
&entry
.get_display(),
)
.expect("There is no default Clipboard")
.set_text(&pwd);
println!("pwd for site {} ({:}) saved to clipboard",site_name.as_str(), spectre::c_char_to_string(usr.borrow().unwrap().userName));
});
}
}
Expand Down
Loading

0 comments on commit 01fd372

Please sign in to comment.