Commit eeff2a6196
Unsigned
Layout: unified · split
src/lib.rs +5 −3
| @@ -62,9 +62,11 @@ impl Matrix { | |||
| 62 | let weechat = unsafe { Weechat::weechat() }; | 62 | let weechat = unsafe { Weechat::weechat() }; |
| 63 | 63 | ||
| 64 | for server in servers.values_mut() { | 64 | for server in servers.values_mut() { |
| 65 | match server.connect() { | 65 | if server.autoconnect() { |
| 66 | Ok(_) => (), | 66 | match server.connect() { |
| 67 | Err(e) => weechat.print(&format!("{:?}", e)), | 67 | Ok(_) => (), |
| 68 | Err(e) => weechat.print(&format!("{:?}", e)), | ||
| 69 | } | ||
| 68 | } | 70 | } |
| 69 | } | 71 | } |
| 70 | } | 72 | } |
src/server.rs +27 −2
| @@ -50,6 +50,13 @@ pub enum ServerMessage { | |||
| 50 | #[derive(Default)] | 50 | #[derive(Default)] |
| 51 | pub struct ServerSettings { | 51 | pub struct ServerSettings { |
| 52 | homeserver: Option<Url>, | 52 | homeserver: Option<Url>, |
| 53 | autoconnect: bool, | ||
| 54 | } | ||
| 55 | |||
| 56 | impl ServerSettings { | ||
| 57 | pub fn new() -> Self { | ||
| 58 | Default::default() | ||
| 59 | } | ||
| 53 | } | 60 | } |
| 54 | 61 | ||
| 55 | pub struct LoginState { | 62 | pub struct LoginState { |
| @@ -101,7 +108,7 @@ impl MatrixServer { | |||
| 101 | let server = InnerServer { | 108 | let server = InnerServer { |
| 102 | server_name: server_name.clone(), | 109 | server_name: server_name.clone(), |
| 103 | room_buffers: HashMap::new(), | 110 | room_buffers: HashMap::new(), |
| 104 | settings: ServerSettings { homeserver: None }, | 111 | settings: ServerSettings::new(), |
| 105 | config: config.clone(), | 112 | config: config.clone(), |
| 106 | client: None, | 113 | client: None, |
| 107 | login_state: None, | 114 | login_state: None, |
| @@ -142,13 +149,27 @@ impl MatrixServer { | |||
| 142 | server_ref: &Rc<RefCell<InnerServer>>, | 149 | server_ref: &Rc<RefCell<InnerServer>>, |
| 143 | ) { | 150 | ) { |
| 144 | let server = Rc::downgrade(server_ref); | 151 | let server = Rc::downgrade(server_ref); |
| 152 | let server_copy = server.clone(); | ||
| 145 | let autoconnect = | 153 | let autoconnect = |
| 146 | BooleanOptionSettings::new(format!("{}.autoconnect", server_name)); | 154 | BooleanOptionSettings::new(format!("{}.autoconnect", server_name)) |
| 155 | .set_change_callback(move |_, option| { | ||
| 156 | let server = server.clone(); | ||
| 157 | let value = option.value(); | ||
| 158 | |||
| 159 | let server_ref = server.upgrade().expect( | ||
| 160 | "Server got deleted while server config is alive", | ||
| 161 | ); | ||
| 162 | |||
| 163 | let mut server = server_ref.borrow_mut(); | ||
| 164 | server.settings.autoconnect = value; | ||
| 165 | }); | ||
| 147 | 166 | ||
| 148 | server_section | 167 | server_section |
| 149 | .new_boolean_option(autoconnect) | 168 | .new_boolean_option(autoconnect) |
| 150 | .expect("Can't create autoconnect option"); | 169 | .expect("Can't create autoconnect option"); |
| 151 | 170 | ||
| 171 | let server = server_copy; | ||
| 172 | |||
| 152 | let homeserver = | 173 | let homeserver = |
| 153 | StringOptionSettings::new(format!("{}.homeserver", server_name)) | 174 | StringOptionSettings::new(format!("{}.homeserver", server_name)) |
| 154 | .set_check_callback(|_, _, value| { | 175 | .set_check_callback(|_, _, value| { |
| @@ -177,6 +198,10 @@ impl MatrixServer { | |||
| 177 | pub fn connected(&self) -> bool { | 198 | pub fn connected(&self) -> bool { |
| 178 | self.inner.borrow().connected() | 199 | self.inner.borrow().connected() |
| 179 | } | 200 | } |
| 201 | |||
| 202 | pub fn autoconnect(&self) -> bool { | ||
| 203 | self.inner.borrow().settings.autoconnect | ||
| 204 | } | ||
| 180 | } | 205 | } |
| 181 | 206 | ||
| 182 | impl Drop for MatrixServer { | 207 | impl Drop for MatrixServer { |