Made the ping messages better
This commit is contained in:
@@ -46,8 +46,18 @@ class AppConfiguration:
|
||||
'current_server': self.current_server,
|
||||
}
|
||||
|
||||
@classmethod
|
||||
def get_default_configuration(cls):
|
||||
config = AppConfiguration()
|
||||
config.servers = []
|
||||
config.current_server = -1
|
||||
return config
|
||||
|
||||
|
||||
def get_config(filename: str) -> AppConfiguration:
|
||||
if not os.path.exists(filename):
|
||||
return AppConfiguration.get_default_configuration()
|
||||
|
||||
with open(filename, 'r') as f:
|
||||
try:
|
||||
response_json = json.load(f)
|
||||
@@ -64,5 +74,7 @@ def get_config(filename: str) -> AppConfiguration:
|
||||
|
||||
|
||||
def save_config(config: AppConfiguration, filename: str):
|
||||
# Make the necessary directories before writing the config.
|
||||
os.makedirs(os.path.dirname(filename), exist_ok=True)
|
||||
with open(filename, 'w+') as f:
|
||||
f.write(json.dumps(config.to_json(), indent=2, sort_keys=True))
|
||||
|
@@ -39,7 +39,7 @@ class LibremsonicApp(Gtk.Application):
|
||||
config_folder = (os.environ.get('XDG_CONFIG_HOME')
|
||||
or os.environ.get('APPDATA') or os.path.join(
|
||||
os.environ.get('HOME'), '.config'))
|
||||
config_folder = os.path.join(config_folder, 'visplay')
|
||||
config_folder = os.path.join(config_folder, 'libremsonic')
|
||||
self.config_file = os.path.join(config_folder, 'config.yaml')
|
||||
|
||||
self.activate()
|
||||
|
@@ -90,7 +90,24 @@ class EditServerDialog(Gtk.Dialog):
|
||||
self.data['Username'].get_text(),
|
||||
self.data['Password'].get_text(),
|
||||
)
|
||||
server.ping()
|
||||
try:
|
||||
server.ping()
|
||||
dialog = Gtk.MessageDialog(self, 0, Gtk.MessageType.INFO,
|
||||
Gtk.ButtonsType.OK,
|
||||
'Connection to server successful.')
|
||||
dialog.format_secondary_markup(
|
||||
f"Connection to {self.data['Server address'].get_text()} successful."
|
||||
)
|
||||
except Exception as err:
|
||||
dialog = Gtk.MessageDialog(self, 0, Gtk.MessageType.ERROR,
|
||||
Gtk.ButtonsType.OK,
|
||||
'Connection to server unsuccessful.')
|
||||
dialog.format_secondary_markup(
|
||||
f"Connection to {self.data['Server address'].get_text()} resulted in the following error:\n\n{err}"
|
||||
)
|
||||
|
||||
dialog.run()
|
||||
dialog.destroy()
|
||||
|
||||
def on_open_in_browser_clicked(self, event):
|
||||
subprocess.call(['xdg-open', self.data['Server address'].get_text()])
|
||||
@@ -129,8 +146,8 @@ class ConfigureServersDialog(Gtk.Dialog):
|
||||
(Gtk.Button('Add...'), lambda e: self.on_edit_clicked(e, True),
|
||||
'start', False),
|
||||
(Gtk.Button('Remove'), self.on_remove_clicked, 'start', True),
|
||||
(Gtk.Button('Connect'), self.on_connect_clicked, 'end', False),
|
||||
(Gtk.Button('Close'), lambda _: self.close(), 'end', False),
|
||||
(Gtk.Button('Connect'), self.on_connect_clicked, 'end', True),
|
||||
]
|
||||
for button_cfg in self.buttons:
|
||||
btn, action, pack_end, requires_selection = button_cfg
|
||||
@@ -202,6 +219,7 @@ class ConfigureServersDialog(Gtk.Dialog):
|
||||
else:
|
||||
self.server_configs[selected_index] = new_config
|
||||
|
||||
self.refresh_server_list()
|
||||
self.emit('server-list-changed', self.server_configs)
|
||||
|
||||
dialog.destroy()
|
||||
|
@@ -31,8 +31,13 @@ class MainWindow(Gtk.ApplicationWindow):
|
||||
self.add(stack)
|
||||
|
||||
def update(self, config: AppConfiguration):
|
||||
server_name = config.servers[config.current_server].name
|
||||
self.connected_to_label.set_markup(f'Connected to {server_name}')
|
||||
# Update the Connected to label on the popup menu.
|
||||
if config.current_server >= 0:
|
||||
server_name = config.servers[config.current_server].name
|
||||
self.connected_to_label.set_markup(f'Connected to {server_name}')
|
||||
else:
|
||||
self.connected_to_label.set_markup(
|
||||
f'<span style="italic">Not Connected to a Server</span>')
|
||||
|
||||
def create_stack(self, **kwargs):
|
||||
stack = Gtk.Stack()
|
||||
|
Reference in New Issue
Block a user