1
0
mirror of https://github.com/EDCD/EDMarketConnector.git synced 2025-06-01 16:11:18 +03:00

added selector for alpha/beta/auto URL targeting

closes EDCD/EDMarketConnector#823
This commit is contained in:
A_D 2021-05-28 09:07:59 +02:00
parent be6e9e6b4e
commit 10de03298b
No known key found for this signature in database
GPG Key ID: 4BE9EB7DF45076C4

View File

@ -6,6 +6,7 @@ import io
import json
import tkinter as tk
from typing import TYPE_CHECKING, Union
from EDMCLogging import get_main_logger
import myNotebook as nb # noqa: N813 # its not my fault.
@ -21,24 +22,31 @@ if not config.get_str('shipyard_provider') and config.get_int('shipyard'):
config.delete('shipyard', suppress=True)
logger = get_main_logger()
DEFAULT_NORMAL_URL = 'https://coriolis.io/import?data='
DEFAULT_BETA_URL = 'https://beta.coriolis.io/import?data='
DEFAULT_OVERRIDE_MODE = 'auto'
normal_url = ""
beta_url = ""
normal_url = ''
beta_url = ''
override_mode = ''
normal_textvar = tk.StringVar()
beta_textvar = tk.StringVar()
override_textvar = tk.StringVar()
def plugin_start3(_) -> str:
"""Set up URLs."""
global normal_url, beta_url
global normal_url, beta_url, override_mode
normal_url = config.get_str('coriolis_normal_url', default=DEFAULT_NORMAL_URL)
beta_url = config.get_str('coriolis_beta_url', default=DEFAULT_BETA_URL)
override_mode = config.get_str('coriolis_overide_url_selection', default=DEFAULT_OVERRIDE_MODE)
normal_textvar.set(value=normal_url)
beta_textvar.set(value=beta_url)
override_textvar.set(value=override_mode)
return 'Coriolis'
@ -63,21 +71,50 @@ def plugin_prefs(parent: tk.Widget, cmdr: str, is_beta: bool) -> tk.Frame:
nb.Entry(conf_frame, textvariable=beta_textvar).grid(sticky=tk.EW, row=cur_row, column=1, padx=PADX)
cur_row += 1
nb.Label(conf_frame, text=_('Override beta/normal selection')).grid(sticky=tk.W, row=cur_row, column=0, padx=PADX)
nb.OptionMenu(
conf_frame,
override_textvar,
override_textvar.get(),
'normal', 'beta', 'default'
).grid(sticky=tk.W, row=cur_row, column=1, padx=PADX)
return conf_frame
def prefs_changed(cmdr: str, is_beta: bool) -> None:
"""Update URLs."""
global normal_url, beta_url
global normal_url, beta_url, override_mode
normal_url = normal_textvar.get()
beta_url = beta_textvar.get()
override_mode = override_textvar.get()
if override_mode not in ('beta', 'normal', 'auto'):
logger.warning(f'Unexpected value {override_mode=!r}. defaulting to "auto"')
override_mode = 'auto'
override_textvar.set(value=override_mode)
config.set('coriolis_normal_url', normal_url)
config.set('coriolis_beta_url', beta_url)
config.set('coriolis_overide_url_selection', override_mode)
def _get_target_url(is_beta: bool) -> str:
if override_mode == 'beta':
return beta_url
elif override_mode == 'normal':
return normal_url
# Must be auto
if is_beta:
return beta_url
return normal_url
# to anyone reading this, no, this is NOT the correct return type. Its magic internal stuff that I WILL be changing
# some day. Check PLUGINS.md for the right way to do this. -A_D
def shipyard_url(loadout, is_beta) -> Union[str, bool]:
"""Return a URL for the current ship."""
# most compact representation
@ -90,7 +127,5 @@ def shipyard_url(loadout, is_beta) -> Union[str, bool]:
f.write(string)
encoded = base64.urlsafe_b64encode(out.getvalue()).decode().replace('=', '%3D')
if is_beta:
return beta_url + encoded
return normal_url + encoded
return _get_target_url(is_beta) + encoded