mirror of
https://gitlab.gnome.org/World/Authenticator.git
synced 2025-03-04 08:44:40 +01:00
fix few clippy complaints
This commit is contained in:
parent
ce307d07fc
commit
61e4feabb1
18 changed files with 41 additions and 39 deletions
|
@ -202,7 +202,7 @@ mod imp {
|
|||
Keyring::ensure_unlocked()
|
||||
.expect("Authenticator couldn't reach a secret service provider or unlock it");
|
||||
|
||||
let has_set_password = Keyring::has_set_password().unwrap_or_else(|_| false);
|
||||
let has_set_password = Keyring::has_set_password().unwrap_or(false);
|
||||
|
||||
app.set_resource_base_path(Some("/com/belmoussaoui/Authenticator"));
|
||||
app.set_accels_for_action("app.quit", &["<primary>q"]);
|
||||
|
@ -248,7 +248,7 @@ impl Application {
|
|||
|
||||
pub fn locked(&self) -> bool {
|
||||
let self_ = imp::Application::from_instance(self);
|
||||
return self_.locked.get();
|
||||
self_.locked.get()
|
||||
}
|
||||
|
||||
pub fn set_locked(&self, state: bool) {
|
||||
|
@ -263,8 +263,6 @@ impl Application {
|
|||
|
||||
fn create_window(&self) -> Window {
|
||||
let self_ = imp::Application::from_instance(self);
|
||||
let window = Window::new(self_.model.clone(), &self.clone());
|
||||
|
||||
window
|
||||
Window::new(self_.model.clone(), &self.clone())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -107,12 +107,12 @@ impl Restorable for AndOTP {
|
|||
|
||||
let provider = model.find_or_create(
|
||||
&item.issuer,
|
||||
item.period.unwrap_or_else(|| 30),
|
||||
item.period.unwrap_or(30),
|
||||
item.method,
|
||||
None,
|
||||
item.algorithm,
|
||||
item.digits,
|
||||
item.counter.unwrap_or_else(|| 1),
|
||||
item.counter.unwrap_or(1),
|
||||
)?;
|
||||
|
||||
let account = Account::create(&item.label, &item.secret, &provider)?;
|
||||
|
|
|
@ -71,19 +71,19 @@ impl Restorable for FreeOTP {
|
|||
let (data, _) = from.load_contents(gio::NONE_CANCELLABLE)?;
|
||||
let uris = String::from_utf8(data)?;
|
||||
|
||||
uris.split("\n")
|
||||
uris.split('\n')
|
||||
.into_iter()
|
||||
.try_for_each(|uri| -> Result<()> {
|
||||
println!("{:#?}", uri);
|
||||
let otp_uri = OTPUri::from_str(uri)?;
|
||||
let provider = model.find_or_create(
|
||||
&otp_uri.issuer,
|
||||
otp_uri.period.unwrap_or_else(|| 30),
|
||||
otp_uri.period.unwrap_or(30),
|
||||
otp_uri.method,
|
||||
None,
|
||||
otp_uri.algorithm,
|
||||
otp_uri.digits.unwrap_or_else(|| 6),
|
||||
otp_uri.counter.unwrap_or_else(|| 1),
|
||||
otp_uri.digits.unwrap_or(6),
|
||||
otp_uri.counter.unwrap_or(1),
|
||||
)?;
|
||||
|
||||
let account = Account::create(&otp_uri.label, &otp_uri.secret, &provider)?;
|
||||
|
|
|
@ -70,10 +70,7 @@ impl Keyring {
|
|||
let ss = SecretService::new(EncryptionType::Dh)?;
|
||||
let col = Self::get_default_collection(&ss)?;
|
||||
match col.search_items(vec![("type", "password"), ("application", config::APP_ID)]) {
|
||||
Ok(items) => Ok(match items.get(0) {
|
||||
Some(_) => true,
|
||||
_ => false,
|
||||
}),
|
||||
Ok(items) => Ok(matches!(items.get(0), Some(_))),
|
||||
_ => Ok(false),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -195,7 +195,7 @@ impl Account {
|
|||
diesel::insert_into(accounts::table)
|
||||
.values(NewAccount {
|
||||
name: name.to_string(),
|
||||
token_id: token_id.to_string(),
|
||||
token_id,
|
||||
provider_id: provider.id(),
|
||||
counter: provider.default_counter(),
|
||||
})
|
||||
|
@ -261,7 +261,7 @@ impl Account {
|
|||
|
||||
let token = Keyring::token(token_id).unwrap().unwrap();
|
||||
let self_ = imp::Account::from_instance(&account);
|
||||
self_.token.set(token);
|
||||
self_.token.set(token).unwrap();
|
||||
|
||||
account.init();
|
||||
account
|
||||
|
|
|
@ -48,6 +48,7 @@ glib_wrapper! {
|
|||
}
|
||||
|
||||
impl AccountSorter {
|
||||
#[allow(clippy::new_without_default)]
|
||||
pub fn new() -> Self {
|
||||
glib::Object::new(Self::static_type(), &[])
|
||||
.expect("Failed to create AccountSorter")
|
||||
|
|
|
@ -53,6 +53,7 @@ glib_wrapper! {
|
|||
}
|
||||
|
||||
impl AccountsModel {
|
||||
#[allow(clippy::new_without_default)]
|
||||
pub fn new() -> Self {
|
||||
glib::Object::new(Self::static_type(), &[])
|
||||
.expect("Failed to create AccountsModel")
|
||||
|
|
|
@ -61,14 +61,13 @@ impl FaviconScrapper {
|
|||
let mut urls = Vec::new();
|
||||
loop {
|
||||
match reader.read_event(&mut buf) {
|
||||
Ok(Event::Start(ref e)) => match e.name() {
|
||||
b"link" => {
|
||||
Ok(Event::Start(ref e)) => {
|
||||
if let b"link" = e.name() {
|
||||
if let Some(url) = Self::from_link(e, base_url) {
|
||||
urls.push(url);
|
||||
}
|
||||
}
|
||||
_ => (),
|
||||
},
|
||||
}
|
||||
Ok(Event::Eof) => break,
|
||||
Err(e) => warn!("Error at position {}: {:?}", reader.buffer_position(), e),
|
||||
_ => (),
|
||||
|
|
|
@ -101,8 +101,8 @@ impl Into<String> for OTPUri {
|
|||
self.secret,
|
||||
self.issuer,
|
||||
self.algorithm.to_string(),
|
||||
self.digits.unwrap_or_else(|| 6),
|
||||
self.counter.unwrap_or_else(|| 1),
|
||||
self.digits.unwrap_or(6),
|
||||
self.counter.unwrap_or(1),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,6 +48,7 @@ glib_wrapper! {
|
|||
}
|
||||
|
||||
impl ProviderSorter {
|
||||
#[allow(clippy::new_without_default)]
|
||||
pub fn new() -> Self {
|
||||
glib::Object::new(Self::static_type(), &[])
|
||||
.expect("Failed to create ProviderSorter")
|
||||
|
|
|
@ -55,6 +55,7 @@ glib_wrapper! {
|
|||
}
|
||||
|
||||
impl ProvidersModel {
|
||||
#[allow(clippy::new_without_default)]
|
||||
pub fn new() -> Self {
|
||||
let model: ProvidersModel = glib::Object::new(Self::static_type(), &[])
|
||||
.expect("Failed to create Model")
|
||||
|
|
|
@ -16,12 +16,13 @@ mod imp {
|
|||
use super::*;
|
||||
use glib::subclass;
|
||||
use gtk::subclass::prelude::*;
|
||||
use std::cell::RefCell;
|
||||
|
||||
#[derive(CompositeTemplate)]
|
||||
pub struct AccountAddDialog {
|
||||
pub global_sender: OnceCell<Sender<Action>>,
|
||||
pub model: OnceCell<ProvidersModel>,
|
||||
pub selected_provider: OnceCell<Provider>,
|
||||
pub selected_provider: RefCell<Option<Provider>>,
|
||||
pub actions: gio::SimpleActionGroup,
|
||||
pub image: ProviderImage,
|
||||
#[template_child]
|
||||
|
@ -71,7 +72,7 @@ mod imp {
|
|||
actions,
|
||||
image: ProviderImage::new(ProviderImageSize::Large),
|
||||
model: OnceCell::new(),
|
||||
selected_provider: OnceCell::new(),
|
||||
selected_provider: RefCell::new(None),
|
||||
main_container: TemplateChild::default(),
|
||||
token_entry: TemplateChild::default(),
|
||||
username_entry: TemplateChild::default(),
|
||||
|
@ -180,12 +181,12 @@ impl AccountAddDialog {
|
|||
.unwrap()
|
||||
.find_or_create(
|
||||
&otp_uri.issuer,
|
||||
otp_uri.period.unwrap_or_else(|| 30),
|
||||
otp_uri.period.unwrap_or(30),
|
||||
otp_uri.method,
|
||||
None,
|
||||
otp_uri.algorithm,
|
||||
otp_uri.digits.unwrap_or_else(|| 6),
|
||||
otp_uri.counter.unwrap_or_else(|| 1),
|
||||
otp_uri.digits.unwrap_or(6),
|
||||
otp_uri.counter.unwrap_or(1),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
|
@ -195,7 +196,7 @@ impl AccountAddDialog {
|
|||
fn save(&self) -> Result<()> {
|
||||
let self_ = imp::AccountAddDialog::from_instance(self);
|
||||
|
||||
if let Some(provider) = self_.selected_provider.get().clone() {
|
||||
if let Some(ref provider) = *self_.selected_provider.borrow() {
|
||||
let username = self_.username_entry.get().get_text().unwrap();
|
||||
let token = self_.token_entry.get().get_text().unwrap();
|
||||
|
||||
|
@ -253,7 +254,7 @@ impl AccountAddDialog {
|
|||
if let Some(ref help_url) = provider.help_url() {
|
||||
self_.provider_help_row.get().set_subtitle(Some(help_url));
|
||||
}
|
||||
self_.selected_provider.set(provider);
|
||||
self_.selected_provider.borrow_mut().replace(provider);
|
||||
}
|
||||
|
||||
fn setup_actions(&self) {
|
||||
|
|
|
@ -62,6 +62,7 @@ glib_wrapper! {
|
|||
pub struct QRCodePage(ObjectSubclass<imp::QRCodePage>) @extends gtk::Widget, gtk::Box;
|
||||
}
|
||||
impl QRCodePage {
|
||||
#[allow(clippy::new_without_default)]
|
||||
pub fn new() -> Self {
|
||||
glib::Object::new(Self::static_type(), &[])
|
||||
.expect("Failed to create QRCodePage")
|
||||
|
|
|
@ -40,7 +40,7 @@ mod imp {
|
|||
glib_object_subclass!();
|
||||
|
||||
fn new() -> Self {
|
||||
let has_set_password = Keyring::has_set_password().unwrap_or_else(|_| false);
|
||||
let has_set_password = Keyring::has_set_password().unwrap_or(false);
|
||||
|
||||
Self {
|
||||
has_set_password: Cell::new(has_set_password),
|
||||
|
@ -175,10 +175,10 @@ impl PasswordPage {
|
|||
let current_password = self_.current_password_entry.get().get_text().unwrap();
|
||||
let password = self_.password_entry.get().get_text().unwrap();
|
||||
|
||||
if Keyring::has_set_password().unwrap_or(false) {
|
||||
if !Keyring::is_current_password(¤t_password).unwrap_or(false) {
|
||||
return;
|
||||
}
|
||||
if Keyring::has_set_password().unwrap_or(false)
|
||||
&& !Keyring::is_current_password(¤t_password).unwrap_or(false)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if Keyring::set_password(&password).is_ok() {
|
||||
|
|
|
@ -110,7 +110,7 @@ impl PreferencesWindow {
|
|||
.downcast::<PreferencesWindow>()
|
||||
.expect("Created object is of wrong type");
|
||||
let self_ = imp::PreferencesWindow::from_instance(&window);
|
||||
self_.model.set(model);
|
||||
self_.model.set(model).unwrap();
|
||||
window.setup_widgets();
|
||||
window
|
||||
}
|
||||
|
|
|
@ -123,7 +123,7 @@ impl ProvidersDialog {
|
|||
.downcast::<ProviderActionRow>()
|
||||
.unwrap();
|
||||
let item = list_item.get_item().unwrap();
|
||||
let provider = item.clone().downcast::<Provider>().unwrap();
|
||||
let provider = item.downcast::<Provider>().unwrap();
|
||||
row.set_provider(provider);
|
||||
});
|
||||
|
||||
|
@ -294,6 +294,7 @@ mod row {
|
|||
}
|
||||
|
||||
impl ProviderActionRow {
|
||||
#[allow(clippy::new_without_default)]
|
||||
pub fn new() -> Self {
|
||||
glib::Object::new(Self::static_type(), &[])
|
||||
.expect("Failed to create ProviderActionRow")
|
||||
|
|
|
@ -106,6 +106,7 @@ glib_wrapper! {
|
|||
pub struct ProviderPage(ObjectSubclass<imp::ProviderPage>) @extends gtk::Widget, gtk::Box;
|
||||
}
|
||||
impl ProviderPage {
|
||||
#[allow(clippy::new_without_default)]
|
||||
pub fn new() -> Self {
|
||||
glib::Object::new(Self::static_type(), &[])
|
||||
.expect("Failed to create ProviderPage")
|
||||
|
|
|
@ -177,8 +177,8 @@ impl Window {
|
|||
|
||||
fn init(&self, model: ProvidersModel) {
|
||||
let self_ = imp::Window::from_instance(self);
|
||||
self_.model.set(model.clone());
|
||||
self_.providers.set_model(model.clone());
|
||||
self_.model.set(model.clone()).unwrap();
|
||||
self_.providers.set_model(model);
|
||||
|
||||
self.set_icon_name(Some(config::APP_ID));
|
||||
self_
|
||||
|
|
Loading…
Add table
Reference in a new issue