Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 24 additions & 7 deletions anilist/panel.luau
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ local visibleRowLimit = INITIAL_VISIBLE_ROWS

local snapshot = noctalia.state.get("anilist_snapshot") or {
revision = 0,
oauthLoading = false,
loading = false,
refreshing = false,
busy = false,
error = "",
viewer = nil,
anime = {},
manga = {},
loadProgress = nil,
}

local mediaTab = "ANIME"
Expand Down Expand Up @@ -229,6 +231,17 @@ local function settingsButton()
})
end

local function loadProgressText()
local progress = snapshot.loadProgress
if type(progress) ~= "table" then
return tr("loading")
end
return tr("loading_progress", {
anime = progress.animeLoaded or 0,
manga = progress.mangaLoaded or 0,
})
end

local function renderLogin()
local children = {
ui.row({ align = "center", justify = "space_between", gap = 8 }, {
Expand All @@ -239,8 +252,10 @@ local function renderLogin()
ui.label({ text = tr("login_help"), fontSize = 12, color = "on_surface_variant", maxLines = 8 }),
}

if snapshot.loading then
if snapshot.oauthLoading then
table.insert(children, ui.label({ text = tr("login_waiting"), color = "primary", fontSize = 13 }))
elseif snapshot.loading then
table.insert(children, ui.label({ text = loadProgressText(), color = "primary", fontSize = 13 }))
else
table.insert(children, ui.button({
text = tr("connect"),
Expand Down Expand Up @@ -578,17 +593,17 @@ local function renderLibrary()
}),
}))

if snapshot.loading and not snapshot.viewer then
table.insert(children, ui.label({ text = tr("loading"), color = "on_surface_variant", padding = { top = 12 } }))
if snapshot.loading then
table.insert(children, ui.label({ text = loadProgressText(), color = "on_surface_variant", padding = { top = 12 } }))
elseif snapshot.error ~= "" then
table.insert(children, ui.label({ text = tr("error", { message = snapshot.error }), color = "error", padding = { top = 12 } }))
elseif snapshot.refreshing then
elseif snapshot.refreshing and #rows == 0 then
table.insert(children, ui.label({ text = tr("refreshing"), color = "on_surface_variant", padding = { top = 8 } }))
elseif snapshot.busy then
table.insert(children, ui.label({ text = tr("updating"), color = "on_surface_variant", padding = { top = 8 } }))
end

if (not snapshot.loading or snapshot.viewer) and #rows == 0 then
if not snapshot.loading and #rows == 0 then
table.insert(children, ui.label({ text = tr("empty"), color = "on_surface_variant", padding = { top = 12 } }))
else
local listChildren = {}
Expand Down Expand Up @@ -647,7 +662,7 @@ function onOpen(_context)
noctalia.state.set("anilist_open", true)
resetListView()
if snapshot.viewer and snapshot.viewer.id then
sendCommand("refresh", { mediaType = mediaTab })
sendCommand("refresh", { mediaType = mediaTab, silent = true })
end
dirty = true
render()
Expand All @@ -656,7 +671,9 @@ end
function onClose()
coverPreview = nil
noctalia.state.set("anilist_open", false)
noctalia.setUpdateInterval(LIST_IDLE_INTERVAL_MS)
if not snapshot.oauthLoading then
noctalia.setUpdateInterval(LIST_IDLE_INTERVAL_MS)
end
end

function update()
Expand Down
2 changes: 1 addition & 1 deletion anilist/plugin.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
id = "cleboost/anilist"
name = "AniList (UNOFFICIAL)"
version = "1.1.0"
version = "1.1.1"
plugin_api = 15
author = "Cleboost"
license = "MIT"
Expand Down
19 changes: 17 additions & 2 deletions anilist/scripts/oauth_login.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,15 @@ def main() -> int:
emit({"ok": False, "error": str(exc)}, result_path)
return 1

result: dict[str, str] = {"status": "pending"}
result: dict[str, str | bool] = {"status": "pending"}
emitted = False
done = threading.Event()

def report(payload: dict) -> None:
nonlocal emitted
emit(payload, result_path)
emitted = True

class CallbackHandler(BaseHTTPRequestHandler):
def do_GET(self) -> None: # noqa: N802
if done.is_set():
Expand All @@ -132,6 +138,7 @@ def do_GET(self) -> None: # noqa: N802
if error:
result["status"] = "error"
result["error"] = str(error)
report({"ok": False, "error": str(error)})
self._success_page("Login failed", "Return to Noctalia and try again.")
done.set()
return
Expand All @@ -140,27 +147,32 @@ def do_GET(self) -> None: # noqa: N802
if not code:
result["status"] = "error"
result["error"] = "missing authorization code"
report({"ok": False, "error": "missing authorization code"})
self._success_page("Login failed", "No authorization code was received.")
done.set()
return

try:
token = exchange_code(client_id, client_secret, code)
except urllib.error.HTTPError as exc:
message = format_http_error(exc)
result["status"] = "error"
result["error"] = format_http_error(exc)
result["error"] = message
report({"ok": False, "error": message})
self._success_page("Login failed", "Could not finish login. Return to Noctalia and try again.")
done.set()
return
except Exception as exc: # noqa: BLE001
result["status"] = "error"
result["error"] = str(exc)
report({"ok": False, "error": str(exc)})
self._success_page("Login failed", "Could not finish login. Return to Noctalia and try again.")
done.set()
return

result["status"] = "ok"
result["access_token"] = token
report({"ok": True, "access_token": token})
self._success_page(
"Connected to AniList",
"You can close this tab and return to Noctalia.",
Expand Down Expand Up @@ -233,6 +245,9 @@ def serve_until_done() -> None:

server.server_close()

if emitted:
return 0 if result.get("status") == "ok" else 1

if result.get("status") == "ok" and result.get("access_token"):
emit({"ok": True, "access_token": result["access_token"]}, result_path)
return 0
Expand Down
Loading