[fractal/ui-refactor: 2/16] Get App::get_op() out of App




commit c6343cc25f4960991557115d4d032edfee837e98
Author: Alejandro Domínguez <adomu net-c com>
Date:   Mon Oct 12 02:45:46 2020 +0200

    Get App::get_op() out of App

 fractal-gtk/src/actions/account_settings.rs |  2 +-
 fractal-gtk/src/actions/global.rs           | 12 ++++++------
 fractal-gtk/src/actions/message.rs          |  5 ++---
 fractal-gtk/src/actions/room_settings.rs    |  2 +-
 fractal-gtk/src/app/mod.rs                  | 10 ++++------
 fractal-gtk/src/appop/account.rs            |  2 +-
 fractal-gtk/src/appop/attach.rs             |  1 -
 fractal-gtk/src/appop/directory.rs          |  2 +-
 fractal-gtk/src/appop/invite.rs             |  2 +-
 fractal-gtk/src/appop/login.rs              |  1 -
 fractal-gtk/src/appop/member.rs             |  1 -
 fractal-gtk/src/appop/message.rs            |  1 -
 fractal-gtk/src/appop/room.rs               |  2 +-
 fractal-gtk/src/appop/start_chat.rs         |  2 +-
 fractal-gtk/src/appop/sync.rs               |  2 +-
 fractal-gtk/src/appop/user.rs               |  2 +-
 fractal-gtk/src/backend/directory.rs        |  1 -
 fractal-gtk/src/backend/register.rs         |  1 -
 fractal-gtk/src/backend/room.rs             |  1 -
 fractal-gtk/src/backend/sync.rs             |  1 -
 fractal-gtk/src/backend/user.rs             |  1 -
 fractal-gtk/src/widgets/address.rs          |  2 +-
 fractal-gtk/src/widgets/inline_player.rs    |  2 +-
 fractal-gtk/src/widgets/room.rs             |  2 +-
 fractal-gtk/src/widgets/room_settings.rs    |  2 +-
 25 files changed, 25 insertions(+), 37 deletions(-)
---
diff --git a/fractal-gtk/src/actions/account_settings.rs b/fractal-gtk/src/actions/account_settings.rs
index be7c3bfa..3526347f 100644
--- a/fractal-gtk/src/actions/account_settings.rs
+++ b/fractal-gtk/src/actions/account_settings.rs
@@ -6,7 +6,7 @@ use gio::SimpleActionGroup;
 use glib::clone;
 use std::sync::{Arc, Mutex};
 
-use crate::app::{App, RUNTIME};
+use crate::app::RUNTIME;
 use crate::appop::AppOp;
 
 use crate::widgets::FileDialog::open;
diff --git a/fractal-gtk/src/actions/global.rs b/fractal-gtk/src/actions/global.rs
index ecb3cddb..75e063e6 100644
--- a/fractal-gtk/src/actions/global.rs
+++ b/fractal-gtk/src/actions/global.rs
@@ -4,11 +4,11 @@ use std::convert::TryInto;
 use std::rc::Rc;
 use std::sync::{Arc, Mutex};
 
+use crate::app;
 use crate::appop::AppOp;
 use crate::model::message::Message;
 use crate::util::i18n::i18n;
 use crate::widgets::FileDialog::open;
-use crate::App;
 use gio::prelude::*;
 use gio::SimpleAction;
 use gtk::prelude::*;
@@ -290,14 +290,14 @@ pub fn new(app: &gtk::Application, op: &Arc<Mutex<AppOp>>) {
             back.borrow_mut().pop();
             if let Some(state) = back.borrow().last() {
                 debug!("Go back to state {:?}", state);
-                if let Some(op) = App::get_op() {
+                if let Some(op) = app::get_op() {
                     let mut op = op.lock().unwrap();
                     op.set_state(*state);
                 }
             } else {
                 // Fallback when there is no back history
                 debug!("There is no state to go back to. Go back to state NoRoom");
-                if let Some(op) = App::get_op() {
+                if let Some(op) = app::get_op() {
                     let mut op = op.lock().unwrap();
                     if op.login_data.is_some() {
                         op.set_state(AppState::NoRoom);
@@ -383,7 +383,7 @@ pub fn get_event_id(data: Option<&glib::Variant>) -> Option<EventId> {
 
 /* TODO: get message from storage once implemented */
 pub fn get_message_by_id(id: &EventId) -> Option<Message> {
-    let op = App::get_op()?;
+    let op = app::get_op()?;
     let op = op.lock().unwrap();
     let room_id = op.active_room.as_ref()?;
     op.get_message_by_id(room_id, id)
@@ -391,14 +391,14 @@ pub fn get_message_by_id(id: &EventId) -> Option<Message> {
 
 fn open_viewer(data: Option<&glib::Variant>) -> Option<()> {
     let msg = get_event_id(data).as_ref().and_then(get_message_by_id)?;
-    let op = App::get_op()?;
+    let op = app::get_op()?;
     let mut op = op.lock().unwrap();
     op.create_media_viewer(msg);
     None
 }
 
 pub fn activate_action(action_group_name: &str, action_name: &str) {
-    if let Some(op) = App::get_op() {
+    if let Some(op) = app::get_op() {
         let main_window = op
             .lock()
             .unwrap()
diff --git a/fractal-gtk/src/actions/message.rs b/fractal-gtk/src/actions/message.rs
index c9ceb11e..7ddf1651 100644
--- a/fractal-gtk/src/actions/message.rs
+++ b/fractal-gtk/src/actions/message.rs
@@ -9,12 +9,11 @@ use std::process::Command;
 use std::rc::Rc;
 
 use crate::actions::AppState;
-use crate::app::RUNTIME;
+use crate::app::{self, RUNTIME};
 use crate::backend::HandleError;
 use crate::model::message::Message;
 use crate::uibuilder::UI;
 use crate::util::i18n::i18n;
-use crate::App;
 use gio::ActionGroupExt;
 use gio::ActionMapExt;
 use gio::SimpleAction;
@@ -230,7 +229,7 @@ fn get_message(id: Option<&glib::Variant>) -> Option<Message> {
 }
 
 fn request_more_messages(session_client: MatrixClient, id: Option<RoomId>) -> Option<()> {
-    let op = App::get_op()?;
+    let op = app::get_op()?;
     let op = op.lock().unwrap();
     let id = id?;
     let r = op.rooms.get(&id)?;
diff --git a/fractal-gtk/src/actions/room_settings.rs b/fractal-gtk/src/actions/room_settings.rs
index 51c1f344..5a1aa904 100644
--- a/fractal-gtk/src/actions/room_settings.rs
+++ b/fractal-gtk/src/actions/room_settings.rs
@@ -7,7 +7,7 @@ use matrix_sdk::identifiers::RoomId;
 use matrix_sdk::Client as MatrixClient;
 use std::convert::TryFrom;
 
-use crate::app::{App, RUNTIME};
+use crate::app::RUNTIME;
 use crate::backend::HandleError;
 use crate::util::i18n::i18n;
 
diff --git a/fractal-gtk/src/app/mod.rs b/fractal-gtk/src/app/mod.rs
index 8281ea38..107a3844 100644
--- a/fractal-gtk/src/app/mod.rs
+++ b/fractal-gtk/src/app/mod.rs
@@ -35,7 +35,7 @@ macro_rules! APPOP {
         let ctx = glib::MainContext::default();
         ctx.invoke(move || {
             $( let $x = $x.clone(); )*
-            if let Some(op) = App::get_op() {
+            if let Some(op) = crate::app::get_op() {
                 op.lock().unwrap().$fn($($x),*);
             }
         });
@@ -220,10 +220,8 @@ impl App {
     fn on_shutdown(self: AppRef) {
         self.op.lock().unwrap().quit();
     }
+}
 
-    // Legazy function to get AppOp
-    // This shouldn't be used in new code
-    pub fn get_op() -> Option<Arc<Mutex<AppOp>>> {
-        unsafe { OP.as_ref().and_then(|x| x.upgrade()) }
-    }
+pub fn get_op() -> Option<Arc<Mutex<AppOp>>> {
+    unsafe { OP.as_ref().and_then(|x| x.upgrade()) }
 }
diff --git a/fractal-gtk/src/appop/account.rs b/fractal-gtk/src/appop/account.rs
index 917f5afb..00e80641 100644
--- a/fractal-gtk/src/appop/account.rs
+++ b/fractal-gtk/src/appop/account.rs
@@ -3,7 +3,7 @@ use gtk::prelude::*;
 use log::info;
 use std::path::PathBuf;
 
-use crate::app::{App, RUNTIME};
+use crate::app::RUNTIME;
 use crate::appop::AppOp;
 use crate::appop::AppState;
 use crate::backend::HandleError;
diff --git a/fractal-gtk/src/appop/attach.rs b/fractal-gtk/src/appop/attach.rs
index 95f51d5e..dd6688cc 100644
--- a/fractal-gtk/src/appop/attach.rs
+++ b/fractal-gtk/src/appop/attach.rs
@@ -11,7 +11,6 @@ use anyhow::Error;
 use gtk::prelude::*;
 
 use crate::appop::AppOp;
-use crate::App;
 
 use crate::util::get_pixbuf_data;
 use gdk_pixbuf::Pixbuf;
diff --git a/fractal-gtk/src/appop/directory.rs b/fractal-gtk/src/appop/directory.rs
index cb437fc7..fcbf3405 100644
--- a/fractal-gtk/src/appop/directory.rs
+++ b/fractal-gtk/src/appop/directory.rs
@@ -2,7 +2,7 @@ use gtk::prelude::*;
 
 use crate::backend::{directory, HandleError};
 
-use crate::app::{App, RUNTIME};
+use crate::app::RUNTIME;
 use crate::appop::AppOp;
 
 use crate::widgets;
diff --git a/fractal-gtk/src/appop/invite.rs b/fractal-gtk/src/appop/invite.rs
index cc9d4ec0..95edc59b 100644
--- a/fractal-gtk/src/appop/invite.rs
+++ b/fractal-gtk/src/appop/invite.rs
@@ -4,7 +4,7 @@ use crate::backend::room;
 use gtk::prelude::*;
 use matrix_sdk::identifiers::{RoomId, UserId};
 
-use crate::app::{App, RUNTIME};
+use crate::app::RUNTIME;
 use crate::appop::member::SearchType;
 use crate::appop::AppOp;
 use crate::backend::HandleError;
diff --git a/fractal-gtk/src/appop/login.rs b/fractal-gtk/src/appop/login.rs
index c8310419..be257272 100644
--- a/fractal-gtk/src/appop/login.rs
+++ b/fractal-gtk/src/appop/login.rs
@@ -7,7 +7,6 @@ use matrix_sdk::identifiers::{DeviceId, ServerName, UserId};
 use matrix_sdk::Session;
 use url::Url;
 
-use crate::app::App;
 use crate::appop::AppOp;
 
 use crate::backend::HandleError;
diff --git a/fractal-gtk/src/appop/member.rs b/fractal-gtk/src/appop/member.rs
index 278e7349..ac729e1d 100644
--- a/fractal-gtk/src/appop/member.rs
+++ b/fractal-gtk/src/appop/member.rs
@@ -18,7 +18,6 @@ use crate::actions::AppState;
 use crate::app::RUNTIME;
 use crate::appop::AppOp;
 use crate::widgets;
-use crate::App;
 
 use crate::model::member::Member;
 
diff --git a/fractal-gtk/src/appop/message.rs b/fractal-gtk/src/appop/message.rs
index 974974b4..460a8fc6 100644
--- a/fractal-gtk/src/appop/message.rs
+++ b/fractal-gtk/src/appop/message.rs
@@ -20,7 +20,6 @@ use url::Url;
 use crate::app::RUNTIME;
 use crate::appop::room::Force;
 use crate::appop::AppOp;
-use crate::App;
 
 use crate::uitypes::MessageContent;
 use crate::uitypes::RowType;
diff --git a/fractal-gtk/src/appop/room.rs b/fractal-gtk/src/appop/room.rs
index e21f561d..9bb446f2 100644
--- a/fractal-gtk/src/appop/room.rs
+++ b/fractal-gtk/src/appop/room.rs
@@ -10,7 +10,7 @@ use url::Url;
 
 use gtk::prelude::*;
 
-use crate::app::{App, RUNTIME};
+use crate::app::RUNTIME;
 use crate::appop::AppOp;
 use crate::backend::HandleError;
 
diff --git a/fractal-gtk/src/appop/start_chat.rs b/fractal-gtk/src/appop/start_chat.rs
index 61ea26d4..1000d6f5 100644
--- a/fractal-gtk/src/appop/start_chat.rs
+++ b/fractal-gtk/src/appop/start_chat.rs
@@ -1,7 +1,7 @@
 use crate::backend::room;
 use gtk::prelude::*;
 
-use crate::app::{App, RUNTIME};
+use crate::app::RUNTIME;
 use crate::appop::AppOp;
 use crate::appop::SearchType;
 use crate::backend::HandleError;
diff --git a/fractal-gtk/src/appop/sync.rs b/fractal-gtk/src/appop/sync.rs
index 9228a9bb..26cb7b7a 100644
--- a/fractal-gtk/src/appop/sync.rs
+++ b/fractal-gtk/src/appop/sync.rs
@@ -1,4 +1,4 @@
-use crate::app::{App, RUNTIME};
+use crate::app::RUNTIME;
 use crate::appop::AppOp;
 use crate::backend::{
     sync::{self, RoomElement, SyncRet, SyncUpdates},
diff --git a/fractal-gtk/src/appop/user.rs b/fractal-gtk/src/appop/user.rs
index bb6c3c90..e2cd0cd3 100644
--- a/fractal-gtk/src/appop/user.rs
+++ b/fractal-gtk/src/appop/user.rs
@@ -4,7 +4,7 @@ use crate::backend::{user, HandleError};
 
 use std::path::PathBuf;
 
-use crate::app::{App, RUNTIME};
+use crate::app::RUNTIME;
 use crate::appop::AppOp;
 
 use crate::cache::download_to_cache;
diff --git a/fractal-gtk/src/backend/directory.rs b/fractal-gtk/src/backend/directory.rs
index 4af547f3..adff9014 100644
--- a/fractal-gtk/src/backend/directory.rs
+++ b/fractal-gtk/src/backend/directory.rs
@@ -18,7 +18,6 @@ use matrix_sdk::directory::RoomNetwork;
 use matrix_sdk::thirdparty::ProtocolInstance;
 
 use super::{dw_media, ContentType, HandleError};
-use crate::app::App;
 use crate::util::i18n::i18n;
 use crate::APPOP;
 
diff --git a/fractal-gtk/src/backend/register.rs b/fractal-gtk/src/backend/register.rs
index 387c2e99..91dbc028 100644
--- a/fractal-gtk/src/backend/register.rs
+++ b/fractal-gtk/src/backend/register.rs
@@ -19,7 +19,6 @@ use crate::backend::HTTP_CLIENT;
 use crate::globals;
 
 use super::HandleError;
-use crate::app::App;
 use crate::util::i18n::i18n;
 use crate::APPOP;
 
diff --git a/fractal-gtk/src/backend/room.rs b/fractal-gtk/src/backend/room.rs
index 92a3cbb5..784581b9 100644
--- a/fractal-gtk/src/backend/room.rs
+++ b/fractal-gtk/src/backend/room.rs
@@ -73,7 +73,6 @@ use super::{
     dw_media, get_prev_batch_from, get_ruma_error_kind, remove_matrix_access_token_if_present,
     ContentType, HandleError,
 };
-use crate::app::App;
 use crate::util::i18n::i18n;
 use crate::APPOP;
 
diff --git a/fractal-gtk/src/backend/sync.rs b/fractal-gtk/src/backend/sync.rs
index 36455b54..5dc2f60b 100644
--- a/fractal-gtk/src/backend/sync.rs
+++ b/fractal-gtk/src/backend/sync.rs
@@ -19,7 +19,6 @@ use matrix_sdk::SyncSettings;
 use std::{collections::HashMap, time::Duration};
 
 use super::{get_ruma_client_error, remove_matrix_access_token_if_present, HandleError};
-use crate::app::App;
 use crate::APPOP;
 
 pub enum RoomElement {
diff --git a/fractal-gtk/src/backend/user.rs b/fractal-gtk/src/backend/user.rs
index c84b6fa1..d262e512 100644
--- a/fractal-gtk/src/backend/user.rs
+++ b/fractal-gtk/src/backend/user.rs
@@ -51,7 +51,6 @@ use matrix_sdk::assign;
 use super::{dw_media, ContentType};
 
 use super::{get_ruma_error_kind, remove_matrix_access_token_if_present, HandleError};
-use crate::app::App;
 use crate::util::i18n::i18n;
 use crate::APPOP;
 use serde_json::json;
diff --git a/fractal-gtk/src/widgets/address.rs b/fractal-gtk/src/widgets/address.rs
index 8dace7cc..8c6fc80d 100644
--- a/fractal-gtk/src/widgets/address.rs
+++ b/fractal-gtk/src/widgets/address.rs
@@ -8,7 +8,7 @@ use rand::distributions::Alphanumeric;
 use rand::{thread_rng, Rng};
 use url::Url;
 
-use crate::app::{App, RUNTIME};
+use crate::app::RUNTIME;
 use crate::appop::AppOp;
 use crate::backend::HandleError;
 
diff --git a/fractal-gtk/src/widgets/inline_player.rs b/fractal-gtk/src/widgets/inline_player.rs
index 0ec6b3ce..1d5594c2 100644
--- a/fractal-gtk/src/widgets/inline_player.rs
+++ b/fractal-gtk/src/widgets/inline_player.rs
@@ -43,7 +43,7 @@ use std::rc::Rc;
 use matrix_sdk::Client as MatrixClient;
 use url::Url;
 
-use crate::app::{App, RUNTIME};
+use crate::app::RUNTIME;
 use crate::util::i18n::i18n;
 
 pub trait PlayerExt {
diff --git a/fractal-gtk/src/widgets/room.rs b/fractal-gtk/src/widgets/room.rs
index 3971967e..4a4cdc28 100644
--- a/fractal-gtk/src/widgets/room.rs
+++ b/fractal-gtk/src/widgets/room.rs
@@ -7,7 +7,7 @@ use crate::model::room::Room;
 
 use crate::util::markup_text;
 
-use crate::app::{App, RUNTIME};
+use crate::app::RUNTIME;
 use crate::appop::AppOp;
 use crate::backend::HandleError;
 
diff --git a/fractal-gtk/src/widgets/room_settings.rs b/fractal-gtk/src/widgets/room_settings.rs
index 9e6bbaab..ba38e3c9 100644
--- a/fractal-gtk/src/widgets/room_settings.rs
+++ b/fractal-gtk/src/widgets/room_settings.rs
@@ -11,7 +11,7 @@ use gtk::prelude::*;
 
 use crate::actions;
 use crate::actions::{ButtonState, StateExt};
-use crate::app::{App, RUNTIME};
+use crate::app::RUNTIME;
 use crate::model::{member::Member, room::Room};
 use crate::util::markup_text;
 use crate::widgets;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]