joelekstrom / fastmate

A native Fastmail-wrapper for Mac.
MIT License
192 stars 12 forks source link

Feature Request: Add "Keep me logged in" to preferences #66

Closed pro-sumer closed 2 years ago

pro-sumer commented 2 years ago

For quite a while I have been using Keyboard Maestro and (recently) the 1Password CLI to automatically log me in. Unfortunately, since the recent Fastmail UI update, I'm unable to let Keyboard Maestro automatically click on the "Keep me logged in" checkbox.

Would you consider adding "Keep me logged in" as an option in the preferences of Fastmate?

And use that to enable/disable the checkbox, which should be possible using some JavaScript?

(similar to "Use beta.fastmail.com")

(for reference: I use Fastmate on my work's Mac and log out every night)

joelekstrom commented 2 years ago

Hi, from a quick look at that thread it seems like you could achieve it using the Fastmate JS API with a userscript maybe?

Simply putting the command suggested by cdthomer in a js file in your userscript folder (accessible from settings) should do the trick: document.getElementById("v17-input").checked = true.

Or would you specifically like support for keyboardmaestro itself to be able to select it?

pro-sumer commented 2 years ago

I was not aware that I could use user scripts in Fastmate... That's excellent!

However, it does not seem to work for me.

I added a file keep_me_logged_in.js in ~/Library/Containers/io.ekstrom.Fastmate/Data/userscripts with this content:

document.getElementById("v17-input").checked = true

What am I doing wrong?

(executing that one line in the JavaScript console in Safari does select the item)

joelekstrom commented 2 years ago

Nothing really, the problem is that the checkbox doesn't appear until a while after the userscript has been executed. This should solve it by polling until it finds the checkbox:

var checkExist = setInterval(function() {
  var checkbox = document.getElementById("v17-input")
  if (checkbox) {
    checkbox.checked = true
    clearInterval(checkExist)
  }
}, 100); // check every 100ms
pro-sumer commented 2 years ago

That does work indeed!

Thanks!

joelekstrom commented 2 years ago

Happy to help!

joelekstrom commented 2 years ago

As for the feature request itself, I'm gonna say no to adding it as a Fastmate setting since I imagine it's pretty niche and can be solved with userscripts.

pro-sumer commented 2 years ago

I'm starting to have doubts that it works as I expected...

Despite the checkbox showing as checked I still get logged out of Fastmail after several hours of inactivity.

Looks like the UI is updated, but the not the underlying logic?

(Though I wonder Fastmate could help then, if this is true)

joelekstrom commented 2 years ago

Hmm, that's strange. I looked briefly at the Fastmail source and didn't find any obvious reasons. It may be that they have an event listender that updates some state when the value changes. If that's the case, you could try manually triggering that event:

var checkExist = setInterval(function() {
  var checkbox = document.getElementById("v17-input")
  if (checkbox) {
    checkbox.checked = true
    var event = new Event('change');
    checkbox.dispatchEvent(event);
    clearInterval(checkExist)
  }
}, 100); // check every 100ms
pro-sumer commented 2 years ago

Thanks for that. Unfortunately it did not help either.

I hope Fastmail will improve this (make the checkbox accessible via the keyboard)

joelekstrom commented 2 years ago

Thanks for the update. I might look into this a bit more if I get inspired, but no promises