Added bearer token entry to connection error dialog
This commit is contained in:
parent
760c00e8ae
commit
3b20daf807
@ -172,26 +172,38 @@ def remove_attached_file(self, name):
|
|||||||
|
|
||||||
# RECONNECT REMOTE | WORKS
|
# RECONNECT REMOTE | WORKS
|
||||||
|
|
||||||
def reconnect_remote_response(self, dialog, task, entry):
|
def reconnect_remote_response(self, dialog, task, url_entry, bearer_entry):
|
||||||
response = dialog.choose_finish(task)
|
response = dialog.choose_finish(task)
|
||||||
if not task or response == "remote":
|
if not task or response == "remote":
|
||||||
self.connect_remote(entry.get_text())
|
self.connect_remote(url_entry.get_text(), bearer_entry.get_text())
|
||||||
elif response == "local":
|
elif response == "local":
|
||||||
self.connect_local()
|
self.connect_local()
|
||||||
elif response == "close":
|
elif response == "close":
|
||||||
self.destroy()
|
self.destroy()
|
||||||
|
|
||||||
def reconnect_remote(self, current_url):
|
def reconnect_remote(self, current_url, current_bearer_token):
|
||||||
entry = Gtk.Entry(
|
entry_url = Gtk.Entry(
|
||||||
css_classes = ["error"],
|
css_classes = ["error"],
|
||||||
text = current_url
|
text = current_url,
|
||||||
|
placeholder_text = "URL"
|
||||||
)
|
)
|
||||||
|
entry_bearer_token = Gtk.Entry(
|
||||||
|
css_classes = ["error"] if current_bearer_token else None,
|
||||||
|
text = current_bearer_token,
|
||||||
|
placeholder_text = "Bearer Token (Optional)"
|
||||||
|
)
|
||||||
|
container = Gtk.Box(
|
||||||
|
orientation = 1,
|
||||||
|
spacing = 10
|
||||||
|
)
|
||||||
|
container.append(entry_url)
|
||||||
|
container.append(entry_bearer_token)
|
||||||
dialog = Adw.AlertDialog(
|
dialog = Adw.AlertDialog(
|
||||||
heading=_("Connection Error"),
|
heading=_("Connection Error"),
|
||||||
body=_("The remote instance has disconnected"),
|
body=_("The remote instance has disconnected"),
|
||||||
extra_child=entry
|
extra_child=container
|
||||||
)
|
)
|
||||||
entry.connect("activate", lambda entry, dialog: reconnect_remote_response(self, dialog, None, entry))
|
#entry.connect("activate", lambda entry, dialog: reconnect_remote_response(self, dialog, None, entry))
|
||||||
dialog.add_response("close", _("Close Alpaca"))
|
dialog.add_response("close", _("Close Alpaca"))
|
||||||
dialog.add_response("local", _("Use local instance"))
|
dialog.add_response("local", _("Use local instance"))
|
||||||
dialog.add_response("remote", _("Connect"))
|
dialog.add_response("remote", _("Connect"))
|
||||||
@ -199,7 +211,7 @@ def reconnect_remote(self, current_url):
|
|||||||
dialog.choose(
|
dialog.choose(
|
||||||
parent = self,
|
parent = self,
|
||||||
cancellable = None,
|
cancellable = None,
|
||||||
callback = lambda dialog, task, entry=entry: reconnect_remote_response(self, dialog, task, entry)
|
callback = lambda dialog, task, url_entry=entry_url, bearer_entry=entry_bearer_token: reconnect_remote_response(self, dialog, task, url_entry, bearer_entry)
|
||||||
)
|
)
|
||||||
|
|
||||||
# CREATE MODEL | WORKS
|
# CREATE MODEL | WORKS
|
||||||
|
@ -290,6 +290,9 @@ class AlpacaWindow(Adw.ApplicationWindow):
|
|||||||
|
|
||||||
@Gtk.Template.Callback()
|
@Gtk.Template.Callback()
|
||||||
def change_remote_url(self, entry):
|
def change_remote_url(self, entry):
|
||||||
|
if not entry.get_text().startswith("http"):
|
||||||
|
entry.set_text("http://{}".format(entry.get_text()))
|
||||||
|
return
|
||||||
self.remote_url = entry.get_text()
|
self.remote_url = entry.get_text()
|
||||||
logger.debug(f"Changing remote url: {self.remote_url}")
|
logger.debug(f"Changing remote url: {self.remote_url}")
|
||||||
if self.run_remote:
|
if self.run_remote:
|
||||||
@ -1234,9 +1237,10 @@ Generate a title following these rules:
|
|||||||
logger.debug("Showing preferences dialog")
|
logger.debug("Showing preferences dialog")
|
||||||
self.preferences_dialog.present(self)
|
self.preferences_dialog.present(self)
|
||||||
|
|
||||||
def connect_remote(self, url):
|
def connect_remote(self, url, bearer_token):
|
||||||
logger.debug(f"Connecting to remote: {url}")
|
logger.debug(f"Connecting to remote: {url}")
|
||||||
connection_handler.url = url
|
connection_handler.url = url
|
||||||
|
connection_handler.bearer_token = bearer_token
|
||||||
self.remote_url = connection_handler.url
|
self.remote_url = connection_handler.url
|
||||||
self.remote_connection_entry.set_text(self.remote_url)
|
self.remote_connection_entry.set_text(self.remote_url)
|
||||||
if self.verify_connection() == False: self.connection_error()
|
if self.verify_connection() == False: self.connection_error()
|
||||||
@ -1253,7 +1257,7 @@ Generate a title following these rules:
|
|||||||
def connection_error(self):
|
def connection_error(self):
|
||||||
logger.error("Connection error")
|
logger.error("Connection error")
|
||||||
if self.run_remote:
|
if self.run_remote:
|
||||||
dialogs.reconnect_remote(self, connection_handler.url)
|
dialogs.reconnect_remote(self, connection_handler.url, connection_handler.bearer_token)
|
||||||
else:
|
else:
|
||||||
local_instance.reset()
|
local_instance.reset()
|
||||||
self.show_toast(_("There was an error with the local Ollama instance, so it has been reset"), self.main_overlay)
|
self.show_toast(_("There was an error with the local Ollama instance, so it has been reset"), self.main_overlay)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user