diff --git a/qt/aqt/mediasrv.py b/qt/aqt/mediasrv.py index e48ba9661..f91506a71 100644 --- a/qt/aqt/mediasrv.py +++ b/qt/aqt/mediasrv.py @@ -256,12 +256,12 @@ def graph_data() -> bytes: return aqt.mw.col.backend.graphs(search=args["search"], days=args["days"]) -def graph_preferences() -> bytes: - return aqt.mw.col.backend.graphs_preferences() +def graph_preferences() -> pb.GraphsPreferences: + return aqt.mw.col.backend.get_graphs_preferences() def set_graph_preferences() -> None: - input = pb.GraphsPreferencesOut() + input = pb.GraphsPreferences() input.ParseFromString(request.data) aqt.mw.col.backend.set_graphs_preferences(input=input) diff --git a/rslib/backend.proto b/rslib/backend.proto index 2af60ab6e..3f2e74f14 100644 --- a/rslib/backend.proto +++ b/rslib/backend.proto @@ -116,8 +116,8 @@ service BackendService { rpc CardStats(CardID) returns (String); rpc Graphs(GraphsIn) returns (GraphsOut); - rpc GraphsPreferences(Empty) returns (GraphsPreferencesOut); - rpc SetGraphsPreferences(GraphsPreferencesOut) returns (Empty); + rpc GetGraphsPreferences(Empty) returns (GraphsPreferences); + rpc SetGraphsPreferences(GraphsPreferences) returns (Empty); // media @@ -1094,7 +1094,7 @@ message GraphsOut { int32 local_offset_secs = 7; } -message GraphsPreferencesOut { +message GraphsPreferences { enum Weekday { SUNDAY = 0; MONDAY = 1; diff --git a/rslib/src/backend/mod.rs b/rslib/src/backend/mod.rs index 3444f8358..d502f9f8b 100644 --- a/rslib/src/backend/mod.rs +++ b/rslib/src/backend/mod.rs @@ -676,11 +676,11 @@ impl BackendService for Backend { self.with_col(|col| col.graph_data_for_search(&input.search, input.days)) } - fn graphs_preferences(&self, _input: pb::Empty) -> BackendResult { - self.with_col(|col| col.graphs_preferences()) + fn get_graphs_preferences(&self, _input: pb::Empty) -> BackendResult { + self.with_col(|col| col.get_graphs_preferences()) } - fn set_graphs_preferences(&self, input: pb::GraphsPreferencesOut) -> BackendResult { + fn set_graphs_preferences(&self, input: pb::GraphsPreferences) -> BackendResult { self.with_col(|col| col.set_graphs_preferences(input)) .map(Into::into) } diff --git a/rslib/src/stats/graphs.rs b/rslib/src/stats/graphs.rs index ed4a73eda..bf4c6d62b 100644 --- a/rslib/src/stats/graphs.rs +++ b/rslib/src/stats/graphs.rs @@ -47,14 +47,14 @@ impl Collection { }) } - pub(crate) fn graphs_preferences(&self) -> Result { - Ok(pb::GraphsPreferencesOut { + pub(crate) fn get_graphs_preferences(&self) -> Result { + Ok(pb::GraphsPreferences { calendar_first_day_of_week: self.get_first_day_of_week() as i32, card_counts_separate_inactive: self.get_card_counts_separate_inactive(), }) } - pub(crate) fn set_graphs_preferences(&self, prefs: pb::GraphsPreferencesOut) -> Result<()> { + pub(crate) fn set_graphs_preferences(&self, prefs: pb::GraphsPreferences) -> Result<()> { self.set_first_day_of_week(match prefs.calendar_first_day_of_week { 1 => Weekday::Monday, 5 => Weekday::Friday, diff --git a/ts/graphs/calendar.ts b/ts/graphs/calendar.ts index 3d6553480..5f080fdab 100644 --- a/ts/graphs/calendar.ts +++ b/ts/graphs/calendar.ts @@ -41,8 +41,8 @@ interface DayDatum { date: Date; } -type WeekdayType = pb.BackendProto.GraphsPreferencesOut.Weekday; -const Weekday = pb.BackendProto.GraphsPreferencesOut.Weekday; /* enum */ +type WeekdayType = pb.BackendProto.GraphsPreferences.Weekday; +const Weekday = pb.BackendProto.GraphsPreferences.Weekday; /* enum */ export function gatherData( data: pb.BackendProto.GraphsOut, diff --git a/ts/graphs/graph-helpers.ts b/ts/graphs/graph-helpers.ts index 8047e45f0..5e9fd1e8a 100644 --- a/ts/graphs/graph-helpers.ts +++ b/ts/graphs/graph-helpers.ts @@ -20,8 +20,8 @@ export async function getGraphData( ); } -export async function getGraphPreferences(): Promise { - return pb.BackendProto.GraphsPreferencesOut.decode( +export async function getGraphPreferences(): Promise { + return pb.BackendProto.GraphsPreferences.decode( await postRequest("/_anki/graphPreferences", JSON.stringify({})) ); } @@ -30,7 +30,7 @@ export async function setGraphPreferences(prefs: PreferencePayload): Promise => { await postRequest( "/_anki/setGraphPreferences", - pb.BackendProto.GraphsPreferencesOut.encode(prefs).finish() + pb.BackendProto.GraphsPreferences.encode(prefs).finish() ); })(); } diff --git a/ts/graphs/preferences.ts b/ts/graphs/preferences.ts index 9a235b2b8..affa77c99 100644 --- a/ts/graphs/preferences.ts +++ b/ts/graphs/preferences.ts @@ -8,16 +8,16 @@ export interface CustomStore extends Writable { } export type PreferenceStore = { - [K in keyof Omit]: CustomStore< - pb.BackendProto.GraphsPreferencesOut[K] + [K in keyof Omit]: CustomStore< + pb.BackendProto.GraphsPreferences[K] >; }; export type PreferencePayload = { [K in keyof Omit< - pb.BackendProto.GraphsPreferencesOut, + pb.BackendProto.GraphsPreferences, "toJSON" - >]: pb.BackendProto.GraphsPreferencesOut[K]; + >]: pb.BackendProto.GraphsPreferences[K]; }; function createPreference( @@ -40,7 +40,7 @@ function createPreference( } function preparePreferences( - graphsPreferences: pb.BackendProto.GraphsPreferencesOut + graphsPreferences: pb.BackendProto.GraphsPreferences ): PreferenceStore { const preferences: Partial = {};