1
0
mirror of https://github.com/EDCD/EDMarketConnector.git synced 2025-04-13 07:47:14 +03:00

751 Commits

Author SHA1 Message Date
Athanasius
4d069cb406
Attempting to re-enable Windows "minimize to system tray" support
1. It's not actually hiding the task bar icon currently.
2. As this touched prefs.py I've done a flake8 and mypy cleanup pass
   too.  But some of that will want reviewing later as I noqa'd some
   things.
2021-11-12 13:17:27 +00:00
Athanasius
6bec46be4e
CAPI: Implement a one-shot override of the Access Token
This allows you to force use of an expired token so as to test the code
paths for that without waiting up to 4 hours for the current one to
expire.

NB: The Access Token is *only* stored in the headers of the `requests`
object.
2021-11-06 10:41:33 +00:00
Athanasius
919136874d
CAPI: Re-auth when Access Token expired: Need to .close() first
The old code did this, and without it we enter a loop of:

1. CAPI says unauthorized
2. We call login()
3. But companion.session.state == STATE_OK, so do nothing
4. Re-scheduled CAPI request goes back to 1.
2021-11-06 08:41:09 +00:00
Athanasius
7a52ddd278
CAPI: Add retry of request after refreshing Access Token 2021-11-05 17:57:35 +00:00
Athanasius
8e32ecd216
CAPI: Actually try to use Refresh Token if CAPI says unauthorized
The refactor for threaded CAPI worker has inadvertently caused us to
always try *full* re-auth when the CAPI signals the Access Token is
expired.
2021-11-05 17:52:50 +00:00
Athanasius
8d55e9f02c
Merge pull request #1316 from EDCD/fix/1018/update-and-docked-status
CAPI: Avoid '... EDO Settlement?' for 'Update' in space
2021-10-20 15:05:28 +01:00
Athanasius
3f0f1fe39f
CAPI: Avoid '... EDO Settlement?' for 'Update' in space
1. Logged out in space
2. Logged back in
3. Run EDMC
4. Hit Update button, get "Docked but unknown station: EDO Settlement?"

In investigating this I realised that the entire else needed to be "if
docked according to CAPI".

Then it became clear that there was a redundant conditional, as the
enclosing one is already testing:

`capi_response.capi_data['lastStarport']['name'] != monitor.station:`

Making the:

`if last_station != monitor.station`

conditional un-necessary.
2021-10-20 14:50:03 +01:00
Athanasius
531302b7da
Notify user when 'File' > 'Status' fails
Rather than a silent failure, set a status line message and also play
the 'bad' sound to draw their attention to it.
2021-10-20 14:32:04 +01:00
Athanasius
62b5e4e7eb
EDMarketConnector.py: Fix isort order complaint 2021-10-17 14:03:07 +01:00
Athanasius
60e0386b04
Merge pull request #1283 from A-UNDERSCORE-D/fix/force-localwebserver-does-nothing
Remove protocol.protocolhandler singleton auto-init
2021-10-17 14:00:17 +01:00
Athanasius
dd8ec061d3
EDDN: Dummy tracking UI to determine layout 2021-10-10 15:40:41 +01:00
Athanasius
72f584481a
EDDN: Add --eddn-tracking-ui CL arg
This will only work on startup for now, with it present/active the EDDN
plugin will add a UI frame to show what it's tracking.

Intended for developer use only.
2021-10-10 15:01:16 +01:00
A_D
f6e4bcfcba
importing things before you use them is helpful. 2021-09-24 17:13:00 +02:00
A_D
c0351fec9b
missed an import 2021-09-24 17:06:51 +02:00
A_D
30b2d481c4
hack to fix --force-localserver-auth 2021-09-24 17:01:57 +02:00
A_D
5b68aad184
Remove protocol.protocolhandler singleton auto-init
In general, doing things like this on import is bad, but this was
changed specifically to remove a bug that causes
--force-localserver-auth to do nothing.

That is caused because while we were careful not to import protocol
until after we were done doing arg things, we did not check to make sure
something else didn't. Companion imports protocol, which thus always
instantiates WindowsProtocolHandler before we can modify some config
state to indicate that we want LinuxProtocolHandler.
2021-09-24 16:39:30 +02:00
Athanasius
f9875b5b9a
EDDN: Make use of new CL arg to use custom upload URL
This also entailed slightly reworking the way the EDDN code uses this
URL.  It was very generalised, so as to allow for the debug "just send
and log locally" code, but as the only URL is the 'upload' one much of
that seemed un-necessary.

So that code has been simplified.
2021-09-24 10:59:15 +01:00
Athanasius
e6e1cbd221
CL args: Group them in-code 2021-09-24 10:34:42 +01:00
Athanasius
0e4e31d733
EDMarketConnector: Correct back to dashboard.start()
Bad PyCharm refactor/rename in 81b5d015fdeecfcf2236a61c433d4c2dac929668
2021-09-02 19:41:37 +01:00
Athanasius
018ee49a0d
Fix logic for 'Update' button visual state wrt CQC
This was wrong since 291fbf2908e0f7419769a7727ee0a79cf58a9342 due to the
check saying "only active if in CQC", when it needed to be "only active
NOT in CQC, along with these other conditions".
2021-08-31 15:03:41 +01:00
Athanasius
796bb1f863
CAPI: Remove unuses Session.query/profile()
* Session.profile() was unused (used to be called from stats.py, but
  that uses cached data now).
* Session.query() was unused, other than by itself.  Normal calls will
  currently be via companion.Session.station().  Future CAPI queries
  like `/fleetcarrier` might add their own companion.Session function.
* And in doing so get --capi-pretend-down working again.
* Small tweak to EDMarketConnector to not throw extra exception if there
  was a CAPI query exception.
2021-08-31 14:08:15 +01:00
Athanasius
092b10447c
EDMarketConnector.py: Early return from AppWindow.save_raw() 2021-08-31 12:09:02 +01:00
Athanasius
d1dbd9da8f
AppWindow.capi_request_data: Specific "We're aborting query" messages 2021-08-30 12:55:45 +01:00
Athanasius
9e206d092c
Fix "" string to be '' 2021-08-28 14:36:54 +01:00
Athanasius
e3cd1d6429
EDMarketConnector: Comment about no timed CAPI retry on re-Auth 2021-08-28 14:27:20 +01:00
Athanasius
024e2ba357
EDMarketConnector: invalidate companion session and return on CredentialsError
* If we don't invalidate then the companion.Auth code will do nothing
  due to "already auth'd".
* We need to give the auth flow time to complete, so need to return.
* As that auth flow can take indeterminate time, not setting a timed
  retry of the CAPI query here.  We should consider setting a flag and
  reacting in the Auth code though.
2021-08-28 14:24:54 +01:00
Athanasius
bc29891cc1
CAPI: Some notes in comments 2021-08-28 14:14:56 +01:00
Athanasius
12b1e9b7bc
CAPI: Add more trace_if('capi.worker', ...) to check timings
I keep observing it take 3-4s to update the UI after a manual CAPI
request.  This showed up as mostly *in*
AppWindow.capi_handle_response(), but the moment I ran it under PyCharm
profile that went down to 400ms.
2021-08-28 13:58:46 +01:00
Athanasius
6c24d9291a
CAPI: EDMarketConnector: Don't Session.invalidate() on CredentialsError 2021-08-26 15:13:33 +01:00
Athanasius
885745197c
CAPI: EDMarketConnector: Set status text on ServerConnectionError 2021-08-26 15:00:16 +01:00
Athanasius
816384f16f
CAPI: Begin taking auth retries out of CAPI queries
* Only set/use retrying as companion.session.retrying (untested).
* Don't call Session.login() from CAPI query code, raise
  CredentialsError instead.
* Also don't Session.close() in CAPI query code.
2021-08-26 14:44:43 +01:00
Athanasius
e1c6a0e9f8
CAPI: Create response queue in companion.Session
No need to create in callers and then use setter.
2021-08-25 11:50:56 +01:00
Athanasius
69d0d03b9b
CAPI: Rename to EDMCCAPIFailedRequest & comment queues
* The 'EDMC' prefix on all these classes is to make it clear they're for
  internal passing around of requests/responses, rather than holding the
  literal raw CAPI request and response.

* The request and response queues are now commented, including the
  detail that the response queue is created by the caller and then set
  'here' by Session.set_capi_response_queue().
2021-08-25 11:42:53 +01:00
Athanasius
0456996cdd
EDMarketConnector: Save querytime to config *before* triggering API 2021-08-25 11:36:39 +01:00
Athanasius
dad2f95f64
EDMarketConnector: Correct arg to tk overrideredirect to bool 2021-08-25 11:34:51 +01:00
Athanasius
5710f3fd61
CAPI: Only import queue in EDMarketConnector.py 2021-08-25 11:33:52 +01:00
Athanasius
4397acc6fb
CAPI: Status text when aborting due to CQC (& en.template updated) 2021-08-24 14:06:12 +01:00
Athanasius
3df688ecd4
CAPI: Pass in that tk_response_event from AppWindow.capi_request_data() 2021-08-24 12:43:33 +01:00
Athanasius
1dcefafc73
CAPI: Pass tk_response_event in Request to optionally use in response
EDMC.py will also need to make CAPI queries using the new threaded
method, but it has no tkinter, thus we need to pass in the event name
when we expect one to be generated, and only generate it if this is not
None.
2021-08-24 12:41:02 +01:00
Athanasius
1c93c3a9fa
CAPI: 'Save Raw Data' now using cached copy
It will write a file containing JSON that has a top level dict with a
key per endpoint we have data for, and within each of those a dict with
keys for query_time and the raw_data.

Everything from the opening `{` in that raw_data value until the
matching closing `}` is the raw data from the CAPI service.

The whole file happily goes through `jq -S -C '.'` to examine the
output.
2021-08-23 18:29:37 +01:00
Athanasius
d53b567fca
CAPI: s/querytime/query_time/ in variable names
But not in the config setting, as that would require a migration.
2021-08-23 18:29:36 +01:00
Athanasius
f80623e025
CAPI: Convert full Update flow to class passing
* Base the following on common EDMCCAPIReturn: EDMCFailedrequest,
  EDMCCAPIRequest, EDMCCAPIResponse.  This saves repeating a bunch of
  variable types and comments.
* Use the above throughout the 'Update' button flow.
* Still need to address 'Save Raw Data', i.e. AppWindow.save_raw().
2021-08-23 18:29:36 +01:00
Athanasius
c1deb9113e
CAPI: 'station' query going via work queue
* Defined inner functions in the worker function to handle the actual
  queries.  This allows for *them* to simply return data or raise
  exceptions to be caught by the main worker function.  *IT* then
  handles returning any error appropriately via the queue to AppWindow.

* Due to the coupling between AppWindow and these queries there are
  several extra parameters passed into the queue worker and then back
  out.  This is largely due to having to split AppWindow.getandsend()
  into two functions: capi_request_data() and capi_handle_response().

  This might get changed to use a class to encapsulate those values,
  rather than the bare tuple currently being used.

* No full flake8 & mypy pass done yet.

* Some companion.py globals renamed so their use is more obvious.
2021-08-23 18:29:34 +01:00
Athanasius
454c9f3d0c
CAPI: Continuing code moving/cleanup up/testing
1. Sending back a spurious CredentialsError() to check it's now handled,
   but other issues blocking the code from getting there currently.
2. Move the "Update suit data from CAPI" call into the AppWindow
   handler.
3. Move some more of the old query() exception handling into the worker.
4. session.query() no longer returns anything, and neither should
   anything that calls it (like session.station()).  This is going to
   take quite some unwinding and code moving.
2021-08-23 18:29:32 +01:00
Athanasius
018b4563b3
CAPI: return good data from worker & start handling reauth 2021-08-23 18:29:32 +01:00
Athanasius
7f362be740
CAPI: Reinstate/format post-query exceptions/etc in AppWindow 2021-08-23 18:29:32 +01:00
Athanasius
407bc9f53a
CAPI: Set companion.Session.tk_master ASAP from AppWindow 2021-08-23 18:29:31 +01:00
Athanasius
655c7ea1ca
CAPI: Some progress in using a Queue to signal result/error
Due to main app being Tk we can't just use Python async functionality.

So instead we have a class to hold a message and optional exception.
And instance of that goes into a queue.
The reading of that in the main thread is triggered by sending a Tk
event.

Much more to come.
2021-08-23 18:29:31 +01:00
Athanasius
2fc1568bf7
CAPI: Move CAPI response processing into AppWindow.capi_handle_response() 2021-08-23 18:29:31 +01:00
Athanasius
e79d219657
CAPI: Rename AppWindow.getandsend() to be more obvious 2021-08-23 18:29:31 +01:00