From 86f0a8a6a0b185e7d232bffcc3b46535620c0c00 Mon Sep 17 00:00:00 2001 From: miruka Date: Tue, 19 Jan 2021 13:22:29 -0400 Subject: [PATCH] Add warning popup when old settings.json detected --- src/backend/backend.py | 5 +- src/backend/pyotherside_events.py | 6 ++ src/backend/qml_bridge.py | 2 +- src/backend/user_files.py | 15 ++++- .../Popups/Pre070SettingsDetectedPopup.qml | 56 +++++++++++++++++++ src/gui/PythonBridge/EventHandlers.qml | 4 ++ 6 files changed, 85 insertions(+), 3 deletions(-) create mode 100644 src/gui/Popups/Pre070SettingsDetectedPopup.qml diff --git a/src/backend/backend.py b/src/backend/backend.py index 5cf1597f..df9ce73a 100644 --- a/src/backend/backend.py +++ b/src/backend/backend.py @@ -29,7 +29,9 @@ from .models.model import Model from .models.model_store import ModelStore from .presence import Presence from .sso_server import SSOServer -from .user_files import Accounts, History, NewTheme, Settings, Theme, UIState +from .user_files import ( + Accounts, History, NewTheme, Pre070Settings, Settings, Theme, UIState, +) # Logging configuration log.getLogger().setLevel(log.INFO) @@ -112,6 +114,7 @@ class Backend: self.theme = Theme(self, self.settings.General.theme) # self.new_theme = NewTheme(self, self.settings.General.new_theme) self.new_theme = NewTheme(self, ".new.py") # TODO + Pre070Settings(self) self.clients: Dict[str, MatrixClient] = {} diff --git a/src/backend/pyotherside_events.py b/src/backend/pyotherside_events.py index 30dfbec7..98f067fc 100644 --- a/src/backend/pyotherside_events.py +++ b/src/backend/pyotherside_events.py @@ -63,6 +63,12 @@ class LoopException(PyOtherSideEvent): traceback: Optional[str] = None +@dataclass +class Pre070SettingsDetected(PyOtherSideEvent): + """Warn that a pre-0.7.0 settings.json file exists.""" + path: Path = field() + + @dataclass class UserFileChanged(PyOtherSideEvent): """Indicate that a config or data file changed on disk.""" diff --git a/src/backend/qml_bridge.py b/src/backend/qml_bridge.py index 6b96b7f6..d6994f83 100644 --- a/src/backend/qml_bridge.py +++ b/src/backend/qml_bridge.py @@ -145,7 +145,7 @@ class QMLBridge: rc = lambda c: asyncio.run_coroutine_threadsafe(c, self._loop) # noqa try: - from devtools import debug # noqa + from devtools import debug # noqa d = debug # noqa except ModuleNotFoundError: log.warning("Module python-devtools not found, can't use debug()") diff --git a/src/backend/user_files.py b/src/backend/user_files.py index 29d8f392..08a8fd42 100644 --- a/src/backend/user_files.py +++ b/src/backend/user_files.py @@ -18,7 +18,9 @@ import pyotherside from watchgod import Change, awatch from .pcn.section import Section -from .pyotherside_events import LoopException, UserFileChanged +from .pyotherside_events import ( + LoopException, Pre070SettingsDetected, UserFileChanged, +) from .theme_parser import convert_to_qml from .utils import ( aiopen, atomic_write, deep_serialize_for_qml, dict_update_recursive, @@ -396,6 +398,17 @@ class Accounts(ConfigFile, JSONFile): self.save() +@dataclass +class Pre070Settings(ConfigFile): + """Detect and warn about the presence of a pre-0.7.0 settings.json file.""" + + filename: str = "settings.json" + + def __post_init__(self) -> None: + if self.path.exists(): + Pre070SettingsDetected(self.path) + + @dataclass class Settings(ConfigFile, PCNFile): """General config file for UI and backend settings""" diff --git a/src/gui/Popups/Pre070SettingsDetectedPopup.qml b/src/gui/Popups/Pre070SettingsDetectedPopup.qml new file mode 100644 index 00000000..4c2309b8 --- /dev/null +++ b/src/gui/Popups/Pre070SettingsDetectedPopup.qml @@ -0,0 +1,56 @@ +// Copyright Mirage authors & contributors +// SPDX-License-Identifier: LGPL-3.0-or-later + +import QtQuick 2.12 +import "../Base" +import "../Base/Buttons" + +HFlickableColumnPopup { + id: root + + property string path + + readonly property string docs: + "https://github.com/mirukana/mirage/tree/dev/docs" + + page.footer: AutoDirectionLayout { + CancelButton { + id: cancelButton + text: qsTr("Close") + onClicked: root.close() + } + } + + onOpened: cancelButton.forceActiveFocus() + + SummaryLabel { + leftPadding: theme.spacing / 2 + rightPadding: leftPadding + textFormat: SummaryLabel.StyledText + text: qsTr("Old configuration file %1 detected").arg( + utils.htmlColorize("settings.json", theme.colors.accentText), + ) + } + + DetailsLabel { + leftPadding: theme.spacing / 2 + rightPadding: leftPadding + textFormat: DetailsLabel.StyledText + text: qsTr( + "The configuration format has changed and settings.json " + + "is no longer supported. " + + `Visit the new config documentation for ` + + "more info.

" + + "This warning will stop appearing if the file " + + `${path.replace(/^file:\/\//, "")} is ` + + "renamed, removed or moved away." + ) + + MouseArea { + anchors.fill: parent + acceptedButtons: Qt.NoButton + cursorShape: + parent.hoveredLink ? Qt.PointingHandCursor : Qt.ArrowCursor + } + } +} diff --git a/src/gui/PythonBridge/EventHandlers.qml b/src/gui/PythonBridge/EventHandlers.qml index e6b801db..dbdfb9ea 100644 --- a/src/gui/PythonBridge/EventHandlers.qml +++ b/src/gui/PythonBridge/EventHandlers.qml @@ -61,6 +61,10 @@ QtObject { py.showError(type, traceback, "", message) } + function onPre070SettingsDetected(path) { + window.makePopup("Popups/Pre070SettingsDetectedPopup.qml", {path}) + } + function onUserFileChanged(type, newData) { if (type === "Theme") { window.theme = Qt.createQmlObject(newData, window, "theme")