mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 22:12:21 -04:00
switch server back into a bool and rely on config
This commit is contained in:
parent
2c7900989c
commit
eee0d7e92f
8 changed files with 26 additions and 29 deletions
|
@ -94,6 +94,7 @@ message BackendInput {
|
|||
AfterNoteUpdatesIn after_note_updates = 80;
|
||||
AddNoteTagsIn add_note_tags = 81;
|
||||
UpdateNoteTagsIn update_note_tags = 82;
|
||||
int32 set_local_minutes_west = 83;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -167,6 +168,7 @@ message BackendOutput {
|
|||
Empty after_note_updates = 80;
|
||||
uint32 add_note_tags = 81;
|
||||
uint32 update_note_tags = 82;
|
||||
Empty set_local_minutes_west = 83;
|
||||
|
||||
BackendError error = 2047;
|
||||
}
|
||||
|
|
|
@ -41,7 +41,6 @@ class _Collection:
|
|||
crt: int
|
||||
mod: int
|
||||
scm: int
|
||||
dty: bool # no longer used
|
||||
_usn: int
|
||||
ls: int
|
||||
_undo: List[Any]
|
||||
|
@ -50,7 +49,7 @@ class _Collection:
|
|||
self,
|
||||
db: DBProxy,
|
||||
backend: RustBackend,
|
||||
server: Optional["anki.storage.ServerData"] = None,
|
||||
server: bool = False,
|
||||
log: bool = False,
|
||||
) -> None:
|
||||
self.backend = backend
|
||||
|
@ -62,7 +61,7 @@ class _Collection:
|
|||
self.server = server
|
||||
self._lastSave = time.time()
|
||||
self.clearUndo()
|
||||
self.media = MediaManager(self, server is not None)
|
||||
self.media = MediaManager(self, server)
|
||||
self.models = ModelManager(self)
|
||||
self.decks = DeckManager(self)
|
||||
self.tags = TagManager(self)
|
||||
|
@ -133,16 +132,9 @@ class _Collection:
|
|||
##########################################################################
|
||||
|
||||
def load(self) -> None:
|
||||
(
|
||||
self.crt,
|
||||
self.mod,
|
||||
self.scm,
|
||||
self.dty, # no longer used
|
||||
self._usn,
|
||||
self.ls,
|
||||
) = self.db.first(
|
||||
(self.crt, self.mod, self.scm, self._usn, self.ls,) = self.db.first(
|
||||
"""
|
||||
select crt, mod, scm, dty, usn, ls from col"""
|
||||
select crt, mod, scm, usn, ls from col"""
|
||||
)
|
||||
|
||||
def setMod(self) -> None:
|
||||
|
@ -157,11 +149,10 @@ is only necessary if you modify properties of this object."""
|
|||
self.mod = intTime(1000) if mod is None else mod
|
||||
self.db.execute(
|
||||
"""update col set
|
||||
crt=?, mod=?, scm=?, dty=?, usn=?, ls=?""",
|
||||
crt=?, mod=?, scm=?, usn=?, ls=?""",
|
||||
self.crt,
|
||||
self.mod,
|
||||
self.scm,
|
||||
self.dty,
|
||||
self._usn,
|
||||
self.ls,
|
||||
)
|
||||
|
|
|
@ -808,6 +808,9 @@ class RustBackend:
|
|||
)
|
||||
).update_note_tags
|
||||
|
||||
def set_local_minutes_west(self, mins: int) -> None:
|
||||
self._run_command(pb.BackendInput(set_local_minutes_west=mins))
|
||||
|
||||
|
||||
def translate_string_in(
|
||||
key: TR, **kwargs: Union[str, int, float]
|
||||
|
|
|
@ -1390,11 +1390,6 @@ where id = ?
|
|||
|
||||
def _current_timezone_offset(self) -> Optional[int]:
|
||||
if self.col.server:
|
||||
mins = self.col.server.minutes_west
|
||||
if mins is not None:
|
||||
return mins
|
||||
# older Anki versions stored the local offset in
|
||||
# the config
|
||||
return self.col.conf.get("localOffset", 0)
|
||||
else:
|
||||
return None
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
|
||||
import os
|
||||
import weakref
|
||||
from dataclasses import dataclass
|
||||
from typing import Optional
|
||||
|
||||
from anki.collection import _Collection
|
||||
|
@ -12,21 +11,16 @@ from anki.media import media_paths_from_col_path
|
|||
from anki.rsbackend import RustBackend
|
||||
|
||||
|
||||
@dataclass
|
||||
class ServerData:
|
||||
minutes_west: Optional[int] = None
|
||||
|
||||
|
||||
def Collection(
|
||||
path: str,
|
||||
backend: Optional[RustBackend] = None,
|
||||
server: Optional[ServerData] = None,
|
||||
server: bool = False,
|
||||
log: bool = False,
|
||||
) -> _Collection:
|
||||
"Open a new or existing collection. Path must be unicode."
|
||||
assert path.endswith(".anki2")
|
||||
if backend is None:
|
||||
backend = RustBackend(server=server is not None)
|
||||
backend = RustBackend(server=server)
|
||||
|
||||
(media_dir, media_db) = media_paths_from_col_path(path)
|
||||
log_path = ""
|
||||
|
|
|
@ -330,7 +330,7 @@ from notes where %s"""
|
|||
|
||||
def remove(self, graves) -> None:
|
||||
# pretend to be the server so we don't set usn = -1
|
||||
self.col.server = True # type: ignore
|
||||
self.col.server = True
|
||||
|
||||
# notes first, so we don't end up with duplicate graves
|
||||
self.col._remNotes(graves["notes"])
|
||||
|
@ -340,7 +340,7 @@ from notes where %s"""
|
|||
for oid in graves["decks"]:
|
||||
self.col.decks.rem(oid, childrenToo=False)
|
||||
|
||||
self.col.server = False # type: ignore
|
||||
self.col.server = False
|
||||
|
||||
# Models
|
||||
##########################################################################
|
||||
|
|
|
@ -366,6 +366,10 @@ impl Backend {
|
|||
}
|
||||
Value::AddNoteTags(input) => OValue::AddNoteTags(self.add_note_tags(input)?),
|
||||
Value::UpdateNoteTags(input) => OValue::UpdateNoteTags(self.update_note_tags(input)?),
|
||||
Value::SetLocalMinutesWest(mins) => OValue::SetLocalMinutesWest({
|
||||
self.set_local_mins_west(mins)?;
|
||||
pb::Empty {}
|
||||
}),
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -1119,6 +1123,10 @@ impl Backend {
|
|||
.map(|n| n as u32)
|
||||
})
|
||||
}
|
||||
|
||||
fn set_local_mins_west(&self, mins: i32) -> Result<()> {
|
||||
self.with_col(|col| col.transact(None, |col| col.set_local_mins_west(mins)))
|
||||
}
|
||||
}
|
||||
|
||||
fn to_nids(ids: Vec<i64>) -> Vec<NoteID> {
|
||||
|
|
|
@ -134,6 +134,10 @@ impl Collection {
|
|||
self.get_config_optional(ConfigKey::LocalOffset)
|
||||
}
|
||||
|
||||
pub(crate) fn set_local_mins_west(&self, mins: i32) -> Result<()> {
|
||||
self.set_config(ConfigKey::LocalOffset, &mins)
|
||||
}
|
||||
|
||||
pub(crate) fn get_rollover(&self) -> Option<i8> {
|
||||
self.get_config_optional(ConfigKey::Rollover)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue