2019-12-19 22:46:16 +11:00
|
|
|
# SPDX-License-Identifier: LGPL-3.0-or-later
|
|
|
|
|
2019-12-18 23:41:02 +11:00
|
|
|
"""User data and configuration files definitions."""
|
|
|
|
|
2019-07-19 10:30:41 +10:00
|
|
|
import asyncio
|
|
|
|
import json
|
2020-03-28 23:01:26 +11:00
|
|
|
import os
|
2020-04-01 20:08:08 +11:00
|
|
|
import platform
|
2019-09-11 07:28:16 +10:00
|
|
|
from dataclasses import dataclass, field
|
2019-07-19 10:30:41 +10:00
|
|
|
from pathlib import Path
|
2020-02-12 07:22:05 +11:00
|
|
|
from typing import TYPE_CHECKING, Any, ClassVar, Dict, Optional
|
2019-07-19 10:30:41 +10:00
|
|
|
|
|
|
|
import aiofiles
|
|
|
|
|
2020-03-15 08:33:13 +11:00
|
|
|
import pyotherside
|
|
|
|
|
2019-07-23 17:14:02 +10:00
|
|
|
from .theme_parser import convert_to_qml
|
2020-03-13 19:35:51 +11:00
|
|
|
from .utils import atomic_write, dict_update_recursive
|
2019-07-19 10:30:41 +10:00
|
|
|
|
2020-02-12 07:22:05 +11:00
|
|
|
if TYPE_CHECKING:
|
|
|
|
from .backend import Backend
|
|
|
|
|
2019-07-19 11:58:21 +10:00
|
|
|
JsonData = Dict[str, Any]
|
|
|
|
|
2019-07-19 10:30:41 +10:00
|
|
|
WRITE_LOCK = asyncio.Lock()
|
|
|
|
|
|
|
|
|
|
|
|
@dataclass
|
2019-12-18 23:41:02 +11:00
|
|
|
class DataFile:
|
|
|
|
"""Base class representing a user data file."""
|
|
|
|
|
2020-02-15 03:21:24 +11:00
|
|
|
is_config: ClassVar[bool] = False
|
|
|
|
create_missing: ClassVar[bool] = True
|
2019-12-18 23:41:02 +11:00
|
|
|
|
2020-02-12 07:22:05 +11:00
|
|
|
backend: "Backend" = field(repr=False)
|
|
|
|
filename: str = field()
|
2019-07-19 10:30:41 +10:00
|
|
|
|
2019-12-11 08:59:04 +11:00
|
|
|
_to_write: Optional[str] = field(init=False, default=None)
|
|
|
|
|
|
|
|
|
|
|
|
def __post_init__(self) -> None:
|
|
|
|
asyncio.ensure_future(self._write_loop())
|
|
|
|
|
|
|
|
|
2019-07-19 10:30:41 +10:00
|
|
|
@property
|
|
|
|
def path(self) -> Path:
|
2019-12-18 23:41:02 +11:00
|
|
|
"""Full path of the file, even if it doesn't exist yet."""
|
|
|
|
|
|
|
|
if self.is_config:
|
2020-03-28 23:01:26 +11:00
|
|
|
return Path(
|
|
|
|
os.environ.get("MIRAGE_CONFIG_DIR") or
|
2020-04-01 20:08:08 +11:00
|
|
|
self.backend.appdirs.user_config_dir,
|
2020-03-28 23:01:26 +11:00
|
|
|
) / self.filename
|
|
|
|
|
|
|
|
return Path(
|
|
|
|
os.environ.get("MIRAGE_DATA_DIR") or
|
2020-04-01 20:08:08 +11:00
|
|
|
self.backend.appdirs.user_data_dir,
|
2020-03-28 23:01:26 +11:00
|
|
|
) / self.filename
|
2019-07-23 17:14:02 +10:00
|
|
|
|
|
|
|
|
|
|
|
async def default_data(self):
|
2019-12-18 23:41:02 +11:00
|
|
|
"""Default content if the file doesn't exist."""
|
|
|
|
|
2019-07-23 17:14:02 +10:00
|
|
|
return ""
|
|
|
|
|
|
|
|
|
|
|
|
async def read(self):
|
2020-02-15 03:21:24 +11:00
|
|
|
"""Return content of the existing file on disk, or default content."""
|
2019-12-18 23:41:02 +11:00
|
|
|
|
2020-02-15 03:21:24 +11:00
|
|
|
try:
|
|
|
|
return self.path.read_text()
|
|
|
|
except FileNotFoundError:
|
|
|
|
default = await self.default_data()
|
|
|
|
|
|
|
|
if self.create_missing:
|
|
|
|
await self.write(default)
|
|
|
|
|
|
|
|
return default
|
2019-07-23 17:14:02 +10:00
|
|
|
|
|
|
|
|
|
|
|
async def write(self, data) -> None:
|
2019-12-18 23:41:02 +11:00
|
|
|
"""Request for the file to be written/updated with data."""
|
|
|
|
|
2019-12-11 08:59:04 +11:00
|
|
|
self._to_write = data
|
|
|
|
|
|
|
|
|
|
|
|
async def _write_loop(self) -> None:
|
2020-02-15 03:21:24 +11:00
|
|
|
"""Write/update file on disk with a 1 second cooldown."""
|
2019-12-18 23:41:02 +11:00
|
|
|
|
2019-12-11 08:59:04 +11:00
|
|
|
self.path.parent.mkdir(parents=True, exist_ok=True)
|
2019-07-23 17:14:02 +10:00
|
|
|
|
2019-12-11 08:59:04 +11:00
|
|
|
while True:
|
2020-02-15 03:21:24 +11:00
|
|
|
await asyncio.sleep(1)
|
2019-12-11 08:59:04 +11:00
|
|
|
|
2020-02-15 03:21:24 +11:00
|
|
|
if self._to_write is None:
|
|
|
|
continue
|
2019-12-11 08:59:04 +11:00
|
|
|
|
2020-02-15 03:21:24 +11:00
|
|
|
if not self.create_missing and not self.path.exists():
|
|
|
|
continue
|
|
|
|
|
2020-03-18 03:09:08 +11:00
|
|
|
async with atomic_write(self.path) as (new, done):
|
2020-02-15 03:21:24 +11:00
|
|
|
await new.write(self._to_write)
|
2020-03-18 03:09:08 +11:00
|
|
|
done()
|
2020-02-15 03:21:24 +11:00
|
|
|
|
|
|
|
self._to_write = None
|
2019-07-19 10:30:41 +10:00
|
|
|
|
|
|
|
|
2019-12-18 23:41:02 +11:00
|
|
|
|
2019-07-19 10:30:41 +10:00
|
|
|
@dataclass
|
2019-12-18 23:41:02 +11:00
|
|
|
class JSONDataFile(DataFile):
|
|
|
|
"""Represent a user data file in the JSON format."""
|
|
|
|
|
2020-03-23 03:01:22 +11:00
|
|
|
_data: Optional[Dict[str, Any]] = field(init=False, default=None)
|
|
|
|
|
|
|
|
|
|
|
|
def __getitem__(self, key: str) -> Any:
|
|
|
|
if self._data is None:
|
|
|
|
raise RuntimeError(f"{self}: read() hasn't been called yet")
|
|
|
|
|
|
|
|
return self._data[key]
|
|
|
|
|
|
|
|
|
2019-07-19 11:58:21 +10:00
|
|
|
async def default_data(self) -> JsonData:
|
|
|
|
return {}
|
|
|
|
|
|
|
|
|
|
|
|
async def read(self) -> JsonData:
|
2020-02-15 03:21:24 +11:00
|
|
|
"""Return content of the existing file on disk, or default content.
|
2019-12-18 23:41:02 +11:00
|
|
|
|
2020-02-15 03:21:24 +11:00
|
|
|
If the file has missing keys, the missing data will be merged and
|
|
|
|
written to disk before returning.
|
|
|
|
|
|
|
|
If `create_missing` is `True` and the file doesn't exist, it will be
|
|
|
|
created.
|
2019-12-18 23:41:02 +11:00
|
|
|
"""
|
2020-02-15 03:21:24 +11:00
|
|
|
|
2019-07-19 10:30:41 +10:00
|
|
|
try:
|
2020-03-16 01:26:53 +11:00
|
|
|
data = json.loads(self.path.read_text())
|
2020-02-15 03:21:24 +11:00
|
|
|
except FileNotFoundError:
|
|
|
|
if not self.create_missing:
|
2020-03-23 03:01:22 +11:00
|
|
|
data = await self.default_data()
|
|
|
|
self._data = data
|
|
|
|
return data
|
2020-02-15 03:21:24 +11:00
|
|
|
|
|
|
|
data = {}
|
|
|
|
except json.JSONDecodeError:
|
2019-07-21 23:24:11 +10:00
|
|
|
data = {}
|
|
|
|
|
2019-07-25 07:20:21 +10:00
|
|
|
all_data = await self.default_data()
|
|
|
|
dict_update_recursive(all_data, data)
|
2019-08-17 05:12:14 +10:00
|
|
|
|
2019-08-31 09:43:58 +10:00
|
|
|
if data != all_data:
|
2019-08-17 05:12:14 +10:00
|
|
|
await self.write(all_data)
|
|
|
|
|
2020-03-23 03:01:22 +11:00
|
|
|
self._data = all_data
|
2019-07-25 07:20:21 +10:00
|
|
|
return all_data
|
2019-07-19 10:30:41 +10:00
|
|
|
|
|
|
|
|
2019-07-19 11:58:21 +10:00
|
|
|
async def write(self, data: JsonData) -> None:
|
2019-07-19 10:30:41 +10:00
|
|
|
js = json.dumps(data, indent=4, ensure_ascii=False, sort_keys=True)
|
2019-07-23 17:14:02 +10:00
|
|
|
await super().write(js)
|
2019-07-19 10:30:41 +10:00
|
|
|
|
|
|
|
|
|
|
|
@dataclass
|
2019-12-18 23:41:02 +11:00
|
|
|
class Accounts(JSONDataFile):
|
|
|
|
"""Config file for saved matrix accounts: user ID, access tokens, etc."""
|
|
|
|
|
|
|
|
is_config = True
|
|
|
|
|
2019-07-19 10:30:41 +10:00
|
|
|
filename: str = "accounts.json"
|
|
|
|
|
2019-12-11 08:59:04 +11:00
|
|
|
|
2019-07-19 10:30:41 +10:00
|
|
|
async def any_saved(self) -> bool:
|
2019-12-18 23:41:02 +11:00
|
|
|
"""Return whether there are any accounts saved on disk."""
|
2019-07-19 10:30:41 +10:00
|
|
|
return bool(await self.read())
|
|
|
|
|
|
|
|
|
|
|
|
async def add(self, user_id: str) -> None:
|
2019-12-18 23:41:02 +11:00
|
|
|
"""Add an account to the config and write it on disk.
|
|
|
|
|
|
|
|
The account's details such as its access token are retrieved from
|
|
|
|
the corresponding `MatrixClient` in `backend.clients`.
|
|
|
|
"""
|
|
|
|
|
2019-07-19 10:30:41 +10:00
|
|
|
client = self.backend.clients[user_id]
|
2020-05-14 17:33:34 +10:00
|
|
|
saved = await self.read()
|
2019-07-19 10:30:41 +10:00
|
|
|
|
|
|
|
await self.write({
|
2020-05-14 17:33:34 +10:00
|
|
|
**saved,
|
2019-07-19 10:30:41 +10:00
|
|
|
client.user_id: {
|
|
|
|
"homeserver": client.homeserver,
|
|
|
|
"token": client.access_token,
|
|
|
|
"device_id": client.device_id,
|
2020-04-06 05:04:40 +10:00
|
|
|
"enabled": True,
|
2020-05-22 22:48:58 +10:00
|
|
|
"order": max([
|
2020-05-14 17:33:34 +10:00
|
|
|
account.get("order", i)
|
|
|
|
for i, account in enumerate(saved.values())
|
2020-05-22 22:48:58 +10:00
|
|
|
] or [-1]) + 1,
|
Big performance refactoring & various improvements
Instead of passing all sorts of events for the JS to handle and manually
add to different data models, we now handle everything we can in Python.
For any change, the python models send a sync event with their
contents (no more than 4 times per second) to JS, and the QSyncable
library's JsonListModel takes care of converting it to a QML ListModel
and sending the appropriate signals.
The SortFilterProxyModel library is not used anymore, the only case
where we need to filter/sort something now is when the user interacts
with the "Filter rooms" or "Filter members" fields. These cases are
handled by a simple JS function.
We now keep separated room and timeline models for different accounts,
the previous approach of sharing all the data we could between accounts
created a lot of complications (local echoes, decrypted messages
replacing others, etc).
The users's own account profile changes are now hidden in the timeline.
On startup, if all events for a room were only own profile changes, more
events will be loaded.
Any kind of image format supported by Qt is now handled by the
pyotherside image provider, instead of just PNG/JPG.
SVGs which previously caused errors are supported as well.
The typing members bar paddings/margins are fixed.
The behavior of the avatar/"upload a profile picture" overlay is fixed.
Config files read from disk are now cached (TODO: make them reloadable
again).
Pylint is not used anymore because of all its annoying false warnings
and lack of understanding for dataclasses, it is replaced by flake8 with
a custom config and various plugins.
Debug mode is now considered on if the program was compiled with
the right option, instead of taking an argument from CLI.
When on, C++ will set a flag in the Window QML component.
The loading screen is now unloaded after the UI is ready, where
previously it just stayed in the background invisible and wasted CPU.
The overall refactoring and improvements make us now able to handle
rooms with thousand of members and no lazy-loading, where previously
everything would freeze and simply scrolling up to load past events
in any room would block the UI for a few seconds.
2019-08-11 22:01:22 +10:00
|
|
|
},
|
2019-07-19 10:30:41 +10:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
async def delete(self, user_id: str) -> None:
|
2019-12-18 23:41:02 +11:00
|
|
|
"""Delete an account from the config and write it on disk."""
|
|
|
|
|
2019-07-19 10:30:41 +10:00
|
|
|
await self.write({
|
|
|
|
uid: info
|
|
|
|
for uid, info in (await self.read()).items() if uid != user_id
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
@dataclass
|
2019-12-18 23:41:02 +11:00
|
|
|
class UISettings(JSONDataFile):
|
|
|
|
"""Config file for QML interface settings and keybindings."""
|
|
|
|
|
|
|
|
is_config = True
|
|
|
|
|
2019-07-25 10:02:31 +10:00
|
|
|
filename: str = "settings.json"
|
2019-07-19 11:58:21 +10:00
|
|
|
|
2019-12-11 08:59:04 +11:00
|
|
|
|
2019-07-19 11:58:21 +10:00
|
|
|
async def default_data(self) -> JsonData:
|
2020-05-14 16:48:48 +10:00
|
|
|
def ctrl_or_osx_ctrl() -> str:
|
|
|
|
# Meta in Qt corresponds to Ctrl on OSX
|
|
|
|
return "Meta" if platform.system() == "Darwin" else "Ctrl"
|
|
|
|
|
2020-04-01 20:08:08 +11:00
|
|
|
def alt_or_cmd() -> str:
|
|
|
|
# Ctrl in Qt corresponds to Cmd on OSX
|
|
|
|
return "Ctrl" if platform.system() == "Darwin" else "Alt"
|
|
|
|
|
2019-07-19 11:58:21 +10:00
|
|
|
return {
|
2020-06-03 11:42:16 +10:00
|
|
|
"alertOnMentionForMsec": -1,
|
|
|
|
"alertOnMessageForMsec": 0,
|
2020-03-18 07:39:29 +11:00
|
|
|
"alwaysCenterRoomHeader": False,
|
2020-03-29 02:04:43 +11:00
|
|
|
"compactMode": False,
|
2019-09-08 06:39:14 +10:00
|
|
|
"clearRoomFilterOnEnter": True,
|
2019-09-08 06:46:30 +10:00
|
|
|
"clearRoomFilterOnEscape": True,
|
2020-05-14 16:24:28 +10:00
|
|
|
"clearMemberFilterOnEscape": True,
|
2020-05-21 14:42:23 +10:00
|
|
|
"collapseSidePanesUnderWindowWidth": 450,
|
2020-05-21 12:03:36 +10:00
|
|
|
"enableKineticScrolling": True,
|
2020-03-23 03:04:43 +11:00
|
|
|
"hideProfileChangeEvents": True,
|
|
|
|
"hideMembershipEvents": False,
|
2020-05-21 01:49:25 +10:00
|
|
|
"hideUnknownEvents": True,
|
2020-06-27 22:56:50 +10:00
|
|
|
"kineticScrollingMaxSpeed": 2500,
|
2020-06-02 08:57:17 +10:00
|
|
|
"markRoomReadMsecDelay": 200,
|
2020-05-17 04:28:29 +10:00
|
|
|
"maxMessageCharactersPerLine": 65,
|
2020-05-17 04:36:00 +10:00
|
|
|
"ownMessagesOnLeftAboveWidth": 895,
|
2020-03-11 00:48:51 +11:00
|
|
|
"theme": "Midnight.qpl",
|
2019-07-23 17:14:02 +10:00
|
|
|
"writeAliases": {},
|
2019-09-18 06:30:04 +10:00
|
|
|
"media": {
|
|
|
|
"autoLoad": True,
|
|
|
|
"autoPlay": False,
|
|
|
|
"autoPlayGIF": True,
|
|
|
|
"autoHideOSDAfterMsec": 3000,
|
|
|
|
"defaultVolume": 100,
|
|
|
|
"startMuted": False,
|
|
|
|
},
|
2019-07-25 07:05:27 +10:00
|
|
|
"keys": {
|
2019-11-10 23:32:17 +11:00
|
|
|
"startPythonDebugger": ["Alt+Shift+D"],
|
2019-12-10 03:27:40 +11:00
|
|
|
"toggleDebugConsole": ["Alt+Shift+C", "F1"],
|
2019-11-10 23:32:17 +11:00
|
|
|
"reloadConfig": ["Alt+Shift+R"],
|
2019-08-24 01:02:22 +10:00
|
|
|
|
2020-03-23 04:30:03 +11:00
|
|
|
"zoomIn": ["Ctrl++"],
|
|
|
|
"zoomOut": ["Ctrl+-"],
|
|
|
|
"zoomReset": ["Ctrl+="],
|
|
|
|
"toggleCompactMode": ["Ctrl+Alt+C"],
|
2019-12-05 00:08:38 +11:00
|
|
|
|
2019-08-31 03:06:54 +10:00
|
|
|
"scrollUp": ["Alt+Up", "Alt+K"],
|
|
|
|
"scrollDown": ["Alt+Down", "Alt+J"],
|
2019-12-09 03:42:40 +11:00
|
|
|
"scrollPageUp": ["Alt+Ctrl+Up", "Alt+Ctrl+K", "PgUp"],
|
|
|
|
"scrollPageDown": ["Alt+Ctrl+Down", "Alt+Ctrl+J", "PgDown"],
|
2019-08-31 03:40:56 +10:00
|
|
|
"scrollToTop":
|
|
|
|
["Alt+Ctrl+Shift+Up", "Alt+Ctrl+Shift+K", "Home"],
|
|
|
|
"scrollToBottom":
|
|
|
|
["Alt+Ctrl+Shift+Down", "Alt+Ctrl+Shift+J", "End"],
|
2019-08-24 01:02:22 +10:00
|
|
|
|
2019-11-11 00:28:57 +11:00
|
|
|
"previousTab": ["Alt+Shift+Left", "Alt+Shift+H"],
|
|
|
|
"nextTab": ["Alt+Shift+Right", "Alt+Shift+L"],
|
|
|
|
|
2020-05-14 15:21:44 +10:00
|
|
|
"addNewAccount": ["Alt+Shift+A"],
|
|
|
|
"accountSettings": ["Alt+A"],
|
|
|
|
"addNewChat": ["Alt+C"],
|
|
|
|
"toggleFocusMainPane": ["Alt+F"],
|
|
|
|
"clearRoomFilter": ["Alt+Shift+F"],
|
2019-11-10 23:36:54 +11:00
|
|
|
"toggleCollapseAccount": [ "Alt+O"],
|
2020-05-14 15:21:44 +10:00
|
|
|
|
|
|
|
"goToLastPage": ["Ctrl+Tab"],
|
|
|
|
"goToPreviousAccount": ["Alt+Shift+N"],
|
|
|
|
"goToNextAccount": ["Alt+N"],
|
|
|
|
"goToPreviousRoom": ["Alt+Shift+Up", "Alt+Shift+K"],
|
|
|
|
"goToNextRoom": ["Alt+Shift+Down", "Alt+Shift+J"],
|
|
|
|
"goToPreviousUnreadRoom": ["Alt+Shift+U"],
|
|
|
|
"goToNextUnreadRoom": ["Alt+U"],
|
|
|
|
"goToPreviousMentionedRoom": ["Alt+Shift+M"],
|
|
|
|
"goToNextMentionedRoom": ["Alt+M"],
|
|
|
|
|
2020-05-14 16:48:48 +10:00
|
|
|
"focusAccountAtIndex": {
|
|
|
|
"01": f"{ctrl_or_osx_ctrl()}+1",
|
|
|
|
"02": f"{ctrl_or_osx_ctrl()}+2",
|
|
|
|
"03": f"{ctrl_or_osx_ctrl()}+3",
|
|
|
|
"04": f"{ctrl_or_osx_ctrl()}+4",
|
|
|
|
"05": f"{ctrl_or_osx_ctrl()}+5",
|
|
|
|
"06": f"{ctrl_or_osx_ctrl()}+6",
|
|
|
|
"07": f"{ctrl_or_osx_ctrl()}+7",
|
|
|
|
"08": f"{ctrl_or_osx_ctrl()}+8",
|
|
|
|
"09": f"{ctrl_or_osx_ctrl()}+9",
|
|
|
|
"10": f"{ctrl_or_osx_ctrl()}+0",
|
|
|
|
},
|
|
|
|
# On OSX, alt+numbers if used for symbols, use cmd instead
|
2020-03-23 05:07:49 +11:00
|
|
|
"focusRoomAtIndex": {
|
2020-04-01 20:08:08 +11:00
|
|
|
"01": f"{alt_or_cmd()}+1",
|
|
|
|
"02": f"{alt_or_cmd()}+2",
|
|
|
|
"03": f"{alt_or_cmd()}+3",
|
|
|
|
"04": f"{alt_or_cmd()}+4",
|
|
|
|
"05": f"{alt_or_cmd()}+5",
|
|
|
|
"06": f"{alt_or_cmd()}+6",
|
|
|
|
"07": f"{alt_or_cmd()}+7",
|
|
|
|
"08": f"{alt_or_cmd()}+8",
|
|
|
|
"09": f"{alt_or_cmd()}+9",
|
|
|
|
"10": f"{alt_or_cmd()}+0",
|
2020-03-23 05:07:49 +11:00
|
|
|
},
|
2019-09-09 01:49:47 +10:00
|
|
|
|
2020-05-14 16:26:25 +10:00
|
|
|
"unfocusOrDeselectAllMessages": ["Ctrl+D"],
|
2020-04-03 01:19:43 +11:00
|
|
|
"focusPreviousMessage": ["Ctrl+Up", "Ctrl+K"],
|
|
|
|
"focusNextMessage": ["Ctrl+Down", "Ctrl+J"],
|
|
|
|
"toggleSelectMessage": ["Ctrl+Space"],
|
|
|
|
"selectMessagesUntilHere": ["Ctrl+Shift+Space"],
|
2020-04-03 01:59:00 +11:00
|
|
|
"removeFocusedOrSelectedMessages": ["Ctrl+R", "Alt+Del"],
|
2020-05-20 20:51:26 +10:00
|
|
|
"replyToFocusedOrLastMessage": ["Ctrl+Q"], # Q for Quote
|
2020-05-14 16:26:25 +10:00
|
|
|
"debugFocusedMessage": ["Ctrl+Shift+D"],
|
2020-05-22 14:10:45 +10:00
|
|
|
"openMessagesLinks": ["Ctrl+O"],
|
2020-04-03 01:19:43 +11:00
|
|
|
"clearRoomMessages": ["Ctrl+L"],
|
2020-03-27 19:49:01 +11:00
|
|
|
|
2020-03-18 08:09:00 +11:00
|
|
|
"sendFile": ["Alt+S"],
|
|
|
|
"sendFileFromPathInClipboard": ["Alt+Shift+S"],
|
2020-03-29 03:40:11 +11:00
|
|
|
"inviteToRoom": ["Alt+I"],
|
2020-03-29 03:50:09 +11:00
|
|
|
"leaveRoom": ["Alt+Escape"],
|
|
|
|
"forgetRoom": ["Alt+Shift+Escape"],
|
2020-03-18 07:52:14 +11:00
|
|
|
|
|
|
|
"toggleFocusRoomPane": ["Alt+R"],
|
2020-07-10 17:11:26 +10:00
|
|
|
|
|
|
|
"refreshDevices": ["Alt+R", "F5"],
|
|
|
|
"signOutCheckedOrAllDevices": ["Alt+S", "Delete"],
|
2019-07-25 07:05:27 +10:00
|
|
|
},
|
2019-07-19 11:58:21 +10:00
|
|
|
}
|
2019-07-21 20:05:01 +10:00
|
|
|
|
|
|
|
|
|
|
|
@dataclass
|
2019-12-18 23:41:02 +11:00
|
|
|
class UIState(JSONDataFile):
|
|
|
|
"""File to save and restore the state of the QML interface."""
|
2019-12-11 08:59:04 +11:00
|
|
|
|
2019-12-18 23:41:02 +11:00
|
|
|
filename: str = "state.json"
|
2019-07-23 17:14:02 +10:00
|
|
|
|
2019-07-21 20:05:01 +10:00
|
|
|
|
|
|
|
async def default_data(self) -> JsonData:
|
|
|
|
return {
|
2019-12-11 05:46:05 +11:00
|
|
|
"collapseAccounts": {},
|
|
|
|
"page": "Pages/Default.qml",
|
|
|
|
"pageProperties": {},
|
2019-07-21 20:05:01 +10:00
|
|
|
}
|
2019-07-23 17:14:02 +10:00
|
|
|
|
|
|
|
|
2019-12-10 04:21:12 +11:00
|
|
|
@dataclass
|
2019-12-18 23:41:02 +11:00
|
|
|
class History(JSONDataFile):
|
|
|
|
"""File to save and restore lines typed by the user in QML components."""
|
2019-12-11 08:59:04 +11:00
|
|
|
|
2019-12-18 23:41:02 +11:00
|
|
|
filename: str = "history.json"
|
2019-12-10 04:21:12 +11:00
|
|
|
|
|
|
|
|
|
|
|
async def default_data(self) -> JsonData:
|
|
|
|
return {"console": []}
|
|
|
|
|
|
|
|
|
2019-07-23 17:14:02 +10:00
|
|
|
@dataclass
|
2019-12-18 23:41:02 +11:00
|
|
|
class Theme(DataFile):
|
|
|
|
"""A theme file defining the look of QML components."""
|
|
|
|
|
2020-02-15 03:21:24 +11:00
|
|
|
# Since it currently breaks at every update and the file format will be
|
|
|
|
# changed later, don't copy the theme to user data dir if it doesn't exist.
|
|
|
|
create_missing = False
|
|
|
|
|
2019-12-18 23:41:02 +11:00
|
|
|
|
2019-07-23 17:14:02 +10:00
|
|
|
@property
|
|
|
|
def path(self) -> Path:
|
2020-03-15 08:33:13 +11:00
|
|
|
data_dir = Path(self.backend.appdirs.user_data_dir)
|
|
|
|
return data_dir / "themes" / self.filename
|
2019-07-23 17:14:02 +10:00
|
|
|
|
|
|
|
|
|
|
|
async def default_data(self) -> str:
|
2020-03-15 08:33:13 +11:00
|
|
|
path = f"src/themes/{self.filename}"
|
|
|
|
|
|
|
|
try:
|
|
|
|
byte_content = pyotherside.qrc_get_file_contents(path)
|
|
|
|
except ValueError:
|
|
|
|
# App was compiled without QRC
|
|
|
|
async with aiofiles.open(path) as file:
|
|
|
|
return await file.read()
|
|
|
|
else:
|
|
|
|
return byte_content.decode()
|
2019-07-23 17:14:02 +10:00
|
|
|
|
|
|
|
|
|
|
|
async def read(self) -> str:
|
2019-07-25 08:09:28 +10:00
|
|
|
return convert_to_qml(await super().read())
|