mirror of
https://github.com/ankitects/anki.git
synced 2025-11-06 12:47:11 -05:00
add bodyclass field
This commit is contained in:
parent
dc17cb1e81
commit
b0a8c341a1
5 changed files with 22 additions and 11 deletions
|
|
@ -301,17 +301,18 @@ message NextCardDataResponse {
|
||||||
QueuedCards queue = 1;
|
QueuedCards queue = 1;
|
||||||
repeated AnswerButton answer_buttons = 2;
|
repeated AnswerButton answer_buttons = 2;
|
||||||
|
|
||||||
// TODO: We can probably make this a little faster by using oneof and
|
|
||||||
// preventing the partial_front and back being sent to svelte where it isn't
|
|
||||||
// used Alternatively we can use a completely different message for both
|
|
||||||
// Rust -> Python and the Python -> Svelte though this would be more
|
|
||||||
// complicated to implement.
|
|
||||||
string front = 3;
|
string front = 3;
|
||||||
string back = 4;
|
string back = 4;
|
||||||
string css = 5;
|
string css = 5;
|
||||||
|
string body_class = 6;
|
||||||
|
|
||||||
repeated card_rendering.RenderedTemplateNode partial_front = 6;
|
// TODO: We can probably make this a little faster by using oneof and
|
||||||
repeated card_rendering.RenderedTemplateNode partial_back = 7;
|
// preventing the partial_front and back being sent to svelte where it isn't
|
||||||
|
// used. Alternatively we can use a completely different message for both
|
||||||
|
// Rust -> Python and the Python -> Svelte though this would be more
|
||||||
|
// complicated to implement.
|
||||||
|
repeated card_rendering.RenderedTemplateNode partial_front = 7;
|
||||||
|
repeated card_rendering.RenderedTemplateNode partial_back = 8;
|
||||||
}
|
}
|
||||||
|
|
||||||
optional NextCardData next_card = 1;
|
optional NextCardData next_card = 1;
|
||||||
|
|
|
||||||
|
|
@ -45,6 +45,7 @@ from aqt.operations import on_op_finished
|
||||||
from aqt.operations.deck import update_deck_configs as update_deck_configs_op
|
from aqt.operations.deck import update_deck_configs as update_deck_configs_op
|
||||||
from aqt.progress import ProgressUpdate
|
from aqt.progress import ProgressUpdate
|
||||||
from aqt.qt import *
|
from aqt.qt import *
|
||||||
|
from aqt.theme import ThemeManager
|
||||||
from aqt.utils import aqt_data_path, show_warning, tr
|
from aqt.utils import aqt_data_path, show_warning, tr
|
||||||
|
|
||||||
# https://forums.ankiweb.net/t/anki-crash-when-using-a-specific-deck/22266
|
# https://forums.ankiweb.net/t/anki-crash-when-using-a-specific-deck/22266
|
||||||
|
|
@ -645,6 +646,9 @@ def save_custom_colours() -> bytes:
|
||||||
return b""
|
return b""
|
||||||
|
|
||||||
|
|
||||||
|
theme_manager = ThemeManager()
|
||||||
|
|
||||||
|
|
||||||
def next_card_data() -> bytes:
|
def next_card_data() -> bytes:
|
||||||
raw = aqt.mw.col._backend.next_card_data_raw(request.data)
|
raw = aqt.mw.col._backend.next_card_data_raw(request.data)
|
||||||
data = NextCardDataResponse.FromString(raw)
|
data = NextCardDataResponse.FromString(raw)
|
||||||
|
|
@ -666,6 +670,9 @@ def next_card_data() -> bytes:
|
||||||
|
|
||||||
data.next_card.front = qside
|
data.next_card.front = qside
|
||||||
data.next_card.back = aside
|
data.next_card.back = aside
|
||||||
|
# Night mode is handled by the frontend so that it works with the browsers theme if used outside of anki.
|
||||||
|
# Perhaps the OS class should be handled this way too?
|
||||||
|
data.next_card.body_class = theme_manager.body_classes_for_card_ord(card.ord, False)
|
||||||
|
|
||||||
return data.SerializeToString()
|
return data.SerializeToString()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -417,6 +417,7 @@ impl crate::services::SchedulerService for Collection {
|
||||||
// Filled by python
|
// Filled by python
|
||||||
front: "".to_string(),
|
front: "".to_string(),
|
||||||
back: "".to_string(),
|
back: "".to_string(),
|
||||||
|
body_class: "".to_string(),
|
||||||
|
|
||||||
partial_front: rendered_nodes_to_proto(render.qnodes),
|
partial_front: rendered_nodes_to_proto(render.qnodes),
|
||||||
partial_back: rendered_nodes_to_proto(render.anodes),
|
partial_back: rendered_nodes_to_proto(render.anodes),
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,9 @@ addEventListener("message", (e) => {
|
||||||
if (e.data.css) {
|
if (e.data.css) {
|
||||||
style.innerHTML = e.data.css;
|
style.innerHTML = e.data.css;
|
||||||
}
|
}
|
||||||
|
if (e.data.bodyclass) {
|
||||||
|
document.body.className = e.data.bodyclass;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
|
|
@ -37,4 +40,3 @@ const theme = params.get("nightMode");
|
||||||
if (theme !== null) {
|
if (theme !== null) {
|
||||||
enableNightMode();
|
enableNightMode();
|
||||||
}
|
}
|
||||||
document.documentElement.classList.add("card");
|
|
||||||
|
|
|
||||||
|
|
@ -76,8 +76,8 @@ export class ReviewerState {
|
||||||
document.addEventListener("keydown", this.onKeyDown.bind(this));
|
document.addEventListener("keydown", this.onKeyDown.bind(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
updateHtml(htmlString: string, css?: string) {
|
updateHtml(htmlString: string, css?: string, bodyclass?: string) {
|
||||||
this.iframe?.contentWindow?.postMessage({ type: "html", value: htmlString, css }, "*");
|
this.iframe?.contentWindow?.postMessage({ type: "html", value: htmlString, css, bodyclass }, "*");
|
||||||
}
|
}
|
||||||
|
|
||||||
async showQuestion(answer: CardAnswer | null) {
|
async showQuestion(answer: CardAnswer | null) {
|
||||||
|
|
@ -91,7 +91,7 @@ export class ReviewerState {
|
||||||
this.answerShown.set(false);
|
this.answerShown.set(false);
|
||||||
|
|
||||||
const question = resp.nextCard?.front || "";
|
const question = resp.nextCard?.front || "";
|
||||||
this.updateHtml(question, resp?.nextCard?.css);
|
this.updateHtml(question, resp?.nextCard?.css, resp?.nextCard?.bodyClass);
|
||||||
|
|
||||||
this.beginAnsweringMs = Date.now();
|
this.beginAnsweringMs = Date.now();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue