Skip to content

Commit 7106571

Browse files
committed
app: auth on start with task
1 parent 6116937 commit 7106571

File tree

1 file changed

+8
-13
lines changed

1 file changed

+8
-13
lines changed

crates/companion-app/src/main.rs

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -49,19 +49,23 @@ pub fn main() -> iced::Result {
4949
.window_size((1200.0, 800.0))
5050
.resizable(cfg!(not(debug_assertions)))
5151
.theme(|_| Theme::Nord)
52-
.run_with(|| (State::new(), Task::none()))
52+
.run_with(|| (State::new(), Task::done(Message::Auth { force: false })))
5353
}
5454

5555
fn update(state: &mut State, message: Message) -> Task<Message> {
5656
let none = Task::none();
5757

5858
match message {
59-
Message::Auth => {
59+
Message::Auth { force } => {
6060
let Some(config) = &mut state.config else {
6161
error!("config not loaded, skipping forgetting");
6262
return none;
6363
};
6464

65+
if !force && config.auth_key().is_some() {
66+
trace!("already registered, skipping auth");
67+
}
68+
6569
if state.server_ok
6670
&& let Ok(res) = state.client.auth()
6771
{
@@ -224,7 +228,7 @@ fn update(state: &mut State, message: Message) -> Task<Message> {
224228

225229
state.need_reset_config = false;
226230

227-
return Task::done(Message::Auth);
231+
return Task::done(Message::Auth { force: true });
228232
}
229233
}
230234

@@ -388,7 +392,7 @@ fn subscription(state: &State) -> Subscription<Message> {
388392

389393
#[derive(Debug, Clone)]
390394
enum Message {
391-
Auth,
395+
Auth { force: bool },
392396
RegisterOnServer,
393397
SelectProfile(String),
394398
FileUpdated(FileUpdateEvent),
@@ -515,15 +519,6 @@ impl State {
515519
.expect("should be checked when pinged");
516520
}
517521

518-
// auth
519-
if config.auth_key().is_some() {
520-
trace!("already registered, skipping auth");
521-
} else if server_ok && let Ok(res) = client.auth() {
522-
trace!("saving auth");
523-
config.set_auth_key(res.key);
524-
need_save_config = true;
525-
};
526-
527522
let (tx, rx) = mpsc::channel();
528523
if server_ok {
529524
for profile in config.profiles() {

0 commit comments

Comments
 (0)