mirror of
https://github.com/EDCD/EDMarketConnector.git
synced 2025-04-21 11:27:38 +03:00
Merge pull request #1117 from A-UNDERSCORE-D/fix/491-configurable-coriolis-link
Add configuration option for coriolis.io instance to use
This commit is contained in:
commit
f3b8df6548
@ -601,3 +601,30 @@
|
||||
|
||||
/* Shortcut settings prompt on OSX. [prefs.py] */
|
||||
"{APP} needs permission to use shortcuts" = "{APP} needs permission to use shortcuts";
|
||||
|
||||
/* Coriolis override modes [plugins/coriolis.py] */
|
||||
"Normal" = "Normal";
|
||||
|
||||
/* Coriolis override modes [plugins/coriolis.py] */
|
||||
"Beta" = "Beta";
|
||||
|
||||
/* Coriolis override modes [plugins/coriolis.py] */
|
||||
"Auto" = "Auto";
|
||||
|
||||
/* Coriolis override label [plugins/coriolis.py] */
|
||||
"Override Beta/Normal Selection" = "Override Beta/Normal Selection";
|
||||
|
||||
/* Coriolis reset buttons [plugins/coriolis.py] */
|
||||
"Reset" = "Reset";
|
||||
|
||||
/* Coriolis Normal URL label [plugins/coriolis.py] */
|
||||
"Normal URL" = "Normal URL";
|
||||
|
||||
/* Coriolis Beta URL label [plugins/coriolis.py] */
|
||||
"Beta URL" = "Beta URL";
|
||||
|
||||
/* Coriolis config title label [plugins/coriolis.py] */
|
||||
"Set the URL to use with coriolis.io ship loadouts. Note that this MUST end with '/import?data='" = "Set the URL to use with coriolis.io ship loadouts. Note that this MUST end with '/import?data='";
|
||||
|
||||
/* Coriolis invalid mode warning [plugins/coriolis.py] */
|
||||
"Invalid Coriolis override mode!" = "Invalid Coriolis override mode!";
|
||||
|
@ -1,9 +1,19 @@
|
||||
# Coriolis ship export
|
||||
"""Coriolis ship export."""
|
||||
|
||||
import base64
|
||||
import gzip
|
||||
import json
|
||||
import io
|
||||
import json
|
||||
import tkinter as tk
|
||||
from typing import TYPE_CHECKING, Union
|
||||
|
||||
import myNotebook as nb # noqa: N813 # its not my fault.
|
||||
from EDMCLogging import get_main_logger
|
||||
from plug import show_error
|
||||
|
||||
if TYPE_CHECKING:
|
||||
def _(s: str) -> str:
|
||||
...
|
||||
|
||||
# Migrate settings from <= 3.01
|
||||
from config import config
|
||||
@ -13,13 +23,122 @@ 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 = ''
|
||||
override_mode = ''
|
||||
|
||||
normal_textvar = tk.StringVar()
|
||||
beta_textvar = tk.StringVar()
|
||||
override_textvar = tk.StringVar() # This will always contain a _localised_ version
|
||||
|
||||
|
||||
def plugin_start3(path: str) -> str:
|
||||
"""Set up URLs."""
|
||||
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={'auto': _('Auto'), 'normal': _('Normal'), 'beta': _('Beta')}.get(override_mode, _('Auto'))
|
||||
)
|
||||
|
||||
def plugin_start3(_):
|
||||
return 'Coriolis'
|
||||
|
||||
|
||||
def shipyard_url(loadout, is_beta):
|
||||
"""Return a URL for the current ship"""
|
||||
def plugin_prefs(parent: tk.Widget, cmdr: str, is_beta: bool) -> tk.Frame:
|
||||
"""Set up plugin preferences."""
|
||||
PADX = 10 # noqa: N806
|
||||
|
||||
conf_frame = nb.Frame(parent)
|
||||
conf_frame.columnconfigure(index=1, weight=1)
|
||||
cur_row = 0
|
||||
nb.Label(conf_frame, text=_(
|
||||
"Set the URL to use with coriolis.io ship loadouts. Note that this MUST end with '/import?data='"
|
||||
)).grid(sticky=tk.EW, row=cur_row, column=0, columnspan=3)
|
||||
cur_row += 1
|
||||
|
||||
nb.Label(conf_frame, text=_('Normal URL')).grid(sticky=tk.W, row=cur_row, column=0, padx=PADX)
|
||||
nb.Entry(conf_frame, textvariable=normal_textvar).grid(sticky=tk.EW, row=cur_row, column=1, padx=PADX)
|
||||
nb.Button(conf_frame, text=_("Reset"), command=lambda: normal_textvar.set(value=DEFAULT_NORMAL_URL)).grid(
|
||||
sticky=tk.W, row=cur_row, column=2, padx=PADX
|
||||
)
|
||||
cur_row += 1
|
||||
|
||||
nb.Label(conf_frame, text=_('Beta URL')).grid(sticky=tk.W, row=cur_row, column=0, padx=PADX)
|
||||
nb.Entry(conf_frame, textvariable=beta_textvar).grid(sticky=tk.EW, row=cur_row, column=1, padx=PADX)
|
||||
nb.Button(conf_frame, text=_('Reset'), command=lambda: beta_textvar.set(value=DEFAULT_BETA_URL)).grid(
|
||||
sticky=tk.W, row=cur_row, column=2, 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'), _('Auto')
|
||||
).grid(sticky=tk.W, row=cur_row, column=1, padx=PADX)
|
||||
cur_row += 1
|
||||
|
||||
return conf_frame
|
||||
|
||||
|
||||
def prefs_changed(cmdr: str, is_beta: bool) -> None:
|
||||
"""Update URLs."""
|
||||
global normal_url, beta_url, override_mode
|
||||
normal_url = normal_textvar.get()
|
||||
beta_url = beta_textvar.get()
|
||||
override_mode = override_textvar.get()
|
||||
override_mode = { # Convert to unlocalised names
|
||||
_('Normal'): 'normal',
|
||||
_('Beta'): 'beta',
|
||||
_('Auto'): 'auto',
|
||||
}.get(override_mode, override_mode)
|
||||
|
||||
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=_('Auto'))
|
||||
|
||||
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:
|
||||
global override_mode
|
||||
if override_mode not in ('auto', 'normal', 'beta'):
|
||||
show_error(_('Invalid Coriolis override mode!'))
|
||||
logger.warning(f'Unexpected override mode {override_mode!r}! defaulting to auto!')
|
||||
override_mode = 'auto'
|
||||
|
||||
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
|
||||
string = json.dumps(loadout, ensure_ascii=False, sort_keys=True, separators=(',', ':')).encode('utf-8')
|
||||
if not string:
|
||||
@ -30,6 +149,5 @@ def shipyard_url(loadout, is_beta):
|
||||
f.write(string)
|
||||
|
||||
encoded = base64.urlsafe_b64encode(out.getvalue()).decode().replace('=', '%3D')
|
||||
url = 'https://beta.coriolis.io/import?data=' if is_beta else 'https://coriolis.io/import?data='
|
||||
|
||||
return f'{url}{encoded}'
|
||||
return _get_target_url(is_beta) + encoded
|
||||
|
Loading…
x
Reference in New Issue
Block a user