Skip to content

Commit

Permalink
One button refactoring (#28)
Browse files Browse the repository at this point in the history
* Remove unused methods

* Renaming before refactoring

* General operation runner class

* Separate device state

* Move isDFU method to DeviceState

* Use Device State for message & progress output

* Better names n stuff

* Migrate recovery operations to AbstractRecoveryOperation

* Fully migrate from FlipperZeroOperaton

* Add AbstractTopLevelOperation class

* Minor code cleanup

* UpdateRegistry is now a singleton

* Made UpdateRegistry's constructor private

* Use deviceState as member of FlipperZero

* Partially implemented full update

* Fix directory name handling

* Working implementation of one-button update

* Temporary fix for sha256 check

* Reboot device to apply restored settings

* Some more code cleanup

* Add Failable interface to RemoteFileFetcher

* Preparations to bring ScreenStream feature back

* RemoteFileFetcher cleanup

* Bring back Screen Streaming feature

* Fix ScreenStreamer crash

* Code cleanup

* Add preferences screen

* Fix application updates

* Implement application preferences

* Fix operation satus reporting

* Do not try to delete potentially non-empty directories

* Remove commit hash workaround

* Do not allow devices without OTP programmed

* Bring back version selection menu

* Read radio and FUS version

* Add a temporary directory manager class

* Add RadioManifest class

* Initial implementation or wireless stack update operation

* Open files inside with the necessary modes

* Use 8 characters for git commit hash

* Working wireless stack update via tar.gz file

* Download all necessary files in FullUpdateOperation

* Minor fixes

* Flush every time

* Working one-button update

* Use QTemporaryFiles for files with random names

* Use QTemporaryDirectory for creating temporary directories

* Proper radio stack version detection

* Add Repair option

* Fix device info fetcher with keys that are substrings

* Removed some code duplication

* Bring back install from file operations
  • Loading branch information
gsurkov authored Oct 19, 2021
1 parent 7016000 commit 078c140
Show file tree
Hide file tree
Showing 135 changed files with 5,290 additions and 2,495 deletions.
5 changes: 3 additions & 2 deletions application/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
#include <QtQuickControls2/QQuickStyle>

#include "qflipperbackend.h"
#include "updateregistry.h"
#include "screencanvas.h"
#include "remotefilefetcher.h"
#include "preferences.h"

#include "macros.h"

Expand Down Expand Up @@ -44,10 +45,10 @@ void Application::initStyles()
void Application::initContextProperties()
{
m_engine.rootContext()->setContextProperty("app", this);
m_engine.rootContext()->setContextProperty("preferences", globalPrefs());
m_engine.rootContext()->setContextProperty("deviceRegistry", &m_backend.deviceRegistry);
m_engine.rootContext()->setContextProperty("firmwareUpdates", &m_backend.firmwareUpdates);
m_engine.rootContext()->setContextProperty("applicationUpdates", &m_backend.applicationUpdates);
m_engine.rootContext()->setContextProperty("downloader", &m_backend.downloader);
}

void Application::initInstanceProperties()
Expand Down
2 changes: 0 additions & 2 deletions application/appupdater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ void AppUpdater::installUpdate(const Flipper::Updates::VersionInfo &versionInfo)
#endif

auto *file = new QFile(filePath + QStringLiteral(".part"));
check_return_void(file->open(QIODevice::ReadWrite), QStringLiteral("Failed to create file: %1.").arg(file->fileName()));

auto *fetcher = new RemoteFileFetcher(this);

const auto cleanup = [=]() {
Expand Down
31 changes: 31 additions & 0 deletions application/assets/symbol-gear.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
115 changes: 34 additions & 81 deletions application/components/FlipperListDelegate.qml
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,16 @@ import QtQuick.Controls 2.12

Item {
signal updateRequested(var device)

signal versionListRequested(var device)
signal screenStreamRequested(var device)

signal localUpdateRequested(var device)
signal localRadioUpdateRequested(var device)
signal localFUSUpdateRequested(var device)
signal localAssetsUpdateRequested(var device)

signal fixOptionBytesRequested(var device)
signal fixBootRequested(var device)

signal versionListRequested(var device)
signal screenStreamRequested(var device)

signal backupRequested(var device)
signal restoreRequested(var device)

id: item
width: parent.width
height: 85
Expand All @@ -25,21 +21,21 @@ Item {
id: progressBar
anchors.fill: parent
anchors.margins: frame.border.width
value: device.progress
value: device.state.progress
}

Rectangle {
id: frame
radius: 6
anchors.fill: parent
color: device.isError ? "#3a0000" : "transparent"
border.color: device.isError ? "#d32a34" : "white"
color: device.state.isError ? "#3a0000" : "transparent"
border.color: device.state.isError ? "#d32a34" : "white"
border.width: 1
}

Text {
id: modelLabel
text: device.model
text: device.state.model
color: "darkgray"
font.pixelSize: 13
anchors.verticalCenter: parent.verticalCenter
Expand All @@ -49,7 +45,7 @@ Item {

Rectangle {
id: nameLabel
color: device.isError ? "#d32a34" : (device.isDFU ? "#0345ff" : "darkorange")
color: device.state.isError ? "#d32a34" : (device.state.isRecoveryMode ? "#0345ff" : "darkorange")
width: 100
height: 30

Expand All @@ -60,7 +56,7 @@ Item {
anchors.leftMargin: 10

Text {
text: device.name
text: device.state.name
color: "black"
font.pixelSize: 16
font.bold: true
Expand All @@ -79,44 +75,31 @@ Item {
anchors.rightMargin: 25
anchors.verticalCenter: parent.verticalCenter

enabled: !device.isPersistent && !device.isError
enabled: !device.state.isPersistent && !device.state.isError

onClicked: actionMenu.open()
}

StyledButton {
id: updateButton
text: {
if(firmwareUpdates.channelNames.length === 0) {
if(!firmwareUpdates.isReady) {
return qsTr("Error");
} else if(device.isDFU || (device.version === "N/A")) {
} else if(device.state.isRecoveryMode) {
return qsTr("Repair");
}

const channelName = "release";
const latestVersion = firmwareUpdates.channel(channelName).latestVersion;

if(latestVersion.number === device.version) {
return qsTr("Reinstall");
} else if((latestVersion.number > device.version) || (device.version.includes(latestVersion.number))) {
} else if(device.updater.canChangeChannel(firmwareUpdates.latestVersion)) {
return qsTr("Change");
} else if(device.updater.canUpdate(firmwareUpdates.latestVersion)) {
return qsTr("Update");
} else {
} else if(device.updater.canRollback(firmwareUpdates.latestVersion)) {
return qsTr("Rollback");
} else {
return qsTr("Reinstall");
}
}

suggested: {
if(device.isDFU || (firmwareUpdates.channelNames.length === 0)) {
return false;
}

const channelName = "release";
const latestVersion = firmwareUpdates.channel(channelName).latestVersion;

return (latestVersion.number > device.version) || ((latestVersion.number !== device.version) && (device.version.includes(latestVersion.number)));
}

visible: (firmwareUpdates.channelNames.length > 0) && !(device.isPersistent || device.isError)
suggested: device.state.isRecoveryMode ? false : device.updater.canUpdate(firmwareUpdates.latestVersion)
visible: firmwareUpdates.isReady && !(device.state.isPersistent || device.state.isError)

anchors.right: menuButton.left
anchors.rightMargin: 10
Expand All @@ -127,8 +110,8 @@ Item {

Text {
id: versionLabel
visible: !(messageLabel.visible || device.isDFU)
text: qsTr("version ") + device.version
visible: !(messageLabel.visible || device.state.isRecoveryMode)
text: qsTr("version ") + device.state.version
font.pixelSize: 13

anchors.left: nameLabel.right
Expand All @@ -140,9 +123,9 @@ Item {

Text {
id: messageLabel
text: device.isError ? device.errorString : device.messageString
visible: device.isPersistent || device.isError
color: device.isError ? "#ddd" : "white"
text: device.state.isError ? device.state.errorString : device.state.statusString
visible: device.state.isPersistent || device.state.isError
color: device.state.isError ? "#ddd" : "white"

font.pixelSize: 13

Expand All @@ -168,66 +151,36 @@ Item {
MenuItem {
text: qsTr("Other versions...")
onTriggered: versionListRequested(device)
enabled: firmwareUpdates.channelNames.length > 0
enabled: firmwareUpdates.isReady
}

MenuItem {
text: qsTr("Update from local file...")
onTriggered: localUpdateRequested(device)
}

MenuSeparator {}

MenuItem {
text: qsTr("Screen Streaming...")
onTriggered: screenStreamRequested(device)
enabled: !device.isDFU
enabled: !device.state.isRecoveryMode
}

MenuSeparator {}

Menu {
title: qsTr("Backup && Restore")

MenuItem {
text: qsTr("Backup User Data...")
onTriggered: backupRequested(device)
}
title: qsTr("Install from file")

MenuItem {
text: qsTr("Restore User Data...")
onTriggered: restoreRequested(device)
}
MenuItem {
text: qsTr("Application firmware...")
onTriggered: localUpdateRequested(device)
}

Menu {
title: qsTr("Expert options")

MenuItem {
text: qsTr("Update Databases...")
onTriggered: localAssetsUpdateRequested(device)
}

MenuItem {
text: qsTr("Update Wireless stack...")
text: qsTr("Wireless stack...")
onTriggered: localRadioUpdateRequested(device)
}

MenuItem {
text: qsTr("Update FUS...")
text: qsTr("FUS (not recommended)...")
onTriggered: localFUSUpdateRequested(device)
}

MenuItem {
text: qsTr("Fix Option Bytes...")
onTriggered: fixOptionBytesRequested(device)
}

MenuItem {
text: qsTr("Fix boot issues")
onTriggered: fixBootRequested(device)
enabled: device.isDFU
}
}
}
}
1 change: 1 addition & 0 deletions application/components/StyledToolButton.qml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import QtQuick.Controls 2.12
Item {
id: control
property alias icon: button.icon.source
property alias color: button.icon.color

width: 50
height: width
Expand Down
1 change: 1 addition & 0 deletions application/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,6 @@ Window {
function onHomeRequested() { mainLoader.setSource("qrc:/screens/homescreen.qml"); }
function onVersionsRequested(device) { mainLoader.setSource("qrc:/screens/versionscreen.qml", {device: device}); }
function onStreamRequested(device) { mainLoader.setSource("qrc:/screens/streamscreen.qml", {device: device}); }
function onPrefsRequested() { mainLoader.setSource("qrc:/screens/prefscreen.qml") }
}
}
2 changes: 2 additions & 0 deletions application/qml.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,7 @@
<file>assets/arrow-down.svg</file>
<file>assets/symbol-back.svg</file>
<file>components/StyledRoundButton.qml</file>
<file>screens/prefscreen.qml</file>
<file>assets/symbol-gear.svg</file>
</qresource>
</RCC>
Loading

0 comments on commit 078c140

Please sign in to comment.