on xenial help sign in
Improve check if update or new install logic

This uses a little more logical way to check if there is an update if wizard-has-run does NOT exists == is new install if wizard-has-run does exists but does NOT match current framework == is update if wizard-has-run does exists but does match current framework == show no wizard

commit6c010807db43de139217fbc5aa92405084f2c069 authorMarius Gripsgard <marius@ubports.com> dateTue 7 Aug 2018, 18:45 (8 years ago) parent5fd3516
15 files changed+120−70
plugins/Wizard/System.cpp+48−24 plugins/Wizard/System.h+9−18 qml/Wizard/Page.qml+3−4 qml/Wizard/Pages.qml+4−12 qml/Wizard/Pages/10-welcome-update.qml+46 qml/Wizard/Pages/10-welcome.qml+1−2 qml/Wizard/Pages/11-changelog.qml+1−2 qml/Wizard/Pages/30-wifi.qml+1−2 qml/Wizard/Pages/50-timezone.qml+1 qml/Wizard/Pages/60-account.qml+1 qml/Wizard/Pages/70-passwd-type.qml+1 qml/Wizard/Pages/75-report-check.qml+1 qml/Wizard/Pages/78-app-update.qml+1−1 qml/Wizard/Pages/80-finished.qml+1−1 qml/Wizard/Wizard.qml+1−4
plugins/Wizard/System.cpp+48−24
@@ -20,7 +20,6 @@
2020#include <QDBusMessage>
2121#include <QDBusConnection>
2222#include <QDBusMetaType>
23−#include <QVersionNumber>
2423#include <QDir>
2524#include <QFile>
2625#include <QLocale>
@@ -44,53 +43,78 @@ System::System()
4443QString System::wizardEnabledPath()
4544{
4645 // Uses ubuntu-system-settings namespace for historic compatibility reasons
47− return QDir::home().filePath(QStringLiteral(".config/ubuntu-system-settings/wizard-has-run/"));
46+ return QDir::home().filePath(QStringLiteral(".config/ubuntu-system-settings/wizard-has-run"));
4847}
4948
49+QString System::currentFrameworkPath()
50+{
51+ return QDir::home().filePath(QStringLiteral("/usr/share/click/framework/current"));
52+}
53+
54+/*
55+wizardEnabled and isUpdate logic
56+
57+if wizard-has-run does NOT exists == is new install
58+if wizard-has-run does exists but does NOT match current framework == is update
59+if wizard-has-run does exists but does match current framework == show no wizard
60+*/
61+
5062bool System::wizardEnabled() const
5163{
52− return (versionToShow() >= 0);
64+ return !QFile::exists(wizardEnabledPath());
5365}
5466
55−signed int System::versionToShow() const
67+QString System::readCurrentFramework()
5668{
57− if (!(QFile::exists(wizardEnabledPath()))) {
58− return 0;
59− }
69+ QFile f(currentFrameworkPath());
70+ if (!f.open(QFile::ReadOnly | QFile::Text)) return "";
71+ QTextStream in(&f);
72+ return in.readAll();
73+}
6074
61− QString pathToCheck = QDir(wizardEnabledPath()).filePath(QString::number(CURRENT_VERSION));
62−
63− if (!(QFile::exists(pathToCheck))) {
64− return CURRENT_VERSION;
65− }
75+QString System::readWizardEnabled()
76+{
77+ QFile f(wizardEnabledPath());
78+ if (!f.open(QFile::ReadOnly | QFile::Text)) return "";
79+ QTextStream in(&f);
80+ return in.readAll();
81+}
6682
67− return -1;
68−
83+QString System::version() const
84+{
85+ return readCurrentFramework();
86+}
87+
88+bool System::isUpdate() const
89+{
90+ if (!wizardEnabled())
91+ return false;
92+
93+ return readCurrentFramework() != readWizardEnabled();
6994}
7095
7196void System::setWizardEnabled(bool enabled)
7297{
73− if (wizardEnabled() == enabled)
98+ if (wizardEnabled() == enabled && !isUpdate())
7499 return;
75100
76101 if (enabled) {
77− QDir(wizardEnabledPath()).removeRecursively();
102+ QFile::remove(wizardEnabledPath());
78103 } else {
79− QDir(wizardEnabledPath()).mkpath(QStringLiteral("."));
104+ QDir(wizardEnabledPath()).mkpath(QStringLiteral(".."));
105+ if (QFile::exists(wizardEnabledPath()))
106+ QFile::remove(wizardEnabledPath());
107+ QFile::copy(currentFrameworkPath(), wizardEnabledPath());
80108 m_fsWatcher.addPath(wizardEnabledPath());
81−
82− // Disable the newest non-first-run wizard, too
83− QFile(QDir(wizardEnabledPath()).filePath(QString::number(CURRENT_VERSION))).open(QIODevice::WriteOnly);
109+ Q_EMIT wizardEnabledChanged();
110+ Q_EMIT isUpdateChanged();
84111 }
85−
86− Q_EMIT wizardEnabledChanged();
87− Q_EMIT versionToShowChanged();
88112}
89113
90114void System::watcherFileChanged()
91115{
92116 Q_EMIT wizardEnabledChanged();
93− Q_EMIT versionToShowChanged();
117+ Q_EMIT isUpdateChanged();
94118 m_fsWatcher.removePath(wizardEnabledPath());
95119}
96120
plugins/Wizard/System.h+9−18
@@ -26,7 +26,8 @@ class System : public QObject
2626{
2727 Q_OBJECT
2828 Q_PROPERTY(bool wizardEnabled READ wizardEnabled WRITE setWizardEnabled NOTIFY wizardEnabledChanged)
29− Q_PROPERTY(int versionToShow READ versionToShow NOTIFY versionToShowChanged)
29+ Q_PROPERTY(QString version READ version NOTIFY versionChanged)
30+ Q_PROPERTY(bool isUpdate READ isUpdate NOTIFY isUpdateChanged)
3031
3132public:
3233 System();
@@ -37,22 +38,8 @@ public:
3738 */
3839 bool wizardEnabled() const;
3940
40− /**
41− * Returns the version of the wizard that should be run
42− * -1 denotes that no wizard should be run. 0 denotes that the first-run
43− * wizard should be run. If we determine that the first-run wizard has run
44− * but ::CURRENT_VERSION has not, we return ::CURRENT_VERSION.
45− * For example, if ::CURRENT_VERSION is 4, version 4 has not run, but the
46− * first-run wizard has run, this method will return 4
47− */
48− int versionToShow() const;
49−
50− /**
51− * The update version for the Wizard in this version of Unity8. Bump this
52− * version then set the showOnVersions property for the pages you would like
53− * to run on the current update to the new value.
54− */
55− int CURRENT_VERSION = 1;
41+ QString version() const;
42+ bool isUpdate() const;
5643
5744 void setWizardEnabled(bool enabled);
5845
@@ -65,7 +52,8 @@ public Q_SLOTS:
6552
6653Q_SIGNALS:
6754 void wizardEnabledChanged();
68− void versionToShowChanged();
55+ void versionChanged();
56+ void isUpdateChanged();
6957
7058private Q_SLOTS:
7159 void watcherFileChanged();
@@ -74,7 +62,10 @@ private:
7462 Q_DISABLE_COPY(System)
7563
7664 static QString wizardEnabledPath();
65+ static QString currentFrameworkPath();
7766 static void setSessionVariable(const QString &variable, const QString &value);
67+ static QString readCurrentFramework();
68+ static QString readWizardEnabled();
7869
7970 QFileSystemWatcher m_fsWatcher;
8071};
qml/Wizard/Page.qml+3−4
@@ -50,10 +50,9 @@ Item {
5050 property bool skipValid: true
5151 property bool skip: false
5252
53− // Marks the wizard versions that this page should be displayed on.
54− // [0] marks a page to run on first-boot only. [] marks it to run on all wizard runs.
55− // Other valid values can be found in ../../plugins/Wizard/System.h
56− property var showOnVersions: [0]
53+ // Marks if should be only shown if update or install
54+ property bool onlyOnUpdate: false
55+ property bool onlyOnInstall: false
5756
5857 property bool hasBackButton: true
5958 property string backButtonText: i18n.ctr("Button: Go back one page in the Wizard", "Back")
qml/Wizard/Pages.qml+4−12
@@ -127,7 +127,7 @@ StyledItem {
127127 // impatientLoadingLabel.text = ""
128128 }
129129 }
130− }
130+ }
131131
132132 Timer {
133133 id: impatientLoadingTimer
@@ -195,14 +195,7 @@ StyledItem {
195195 currentPage.aboutToShowSecondary(UbuntuAnimation.BriskDuration);
196196 }
197197 }
198−
199− /**
200− * Determine if array contains item
201− */
202− function itemInArray(item, array) {
203− return array.indexOf(item) >= 0;
204− }
205−
198+
206199 function checkSkip() {
207200 if (!currentPage) { // may have had a parse error
208201 console.warn("Wizard page skipped due to possible parse error.");
@@ -210,9 +203,8 @@ StyledItem {
210203 } else if (currentPage.skipValid) {
211204 if (currentPage.skip) {
212205 next();
213− } else if ( !(itemInArray(wizard.runningWizardVersion, currentPage.showOnVersions)) &&
214− (currentPage.showOnVersions.length > 0) ) {
215− // The page is not supposed to run on this version of the wizard
206+ } else if ((currentPage.onlyOnUpdate && !wizard.isUpdate) ||
207+ (currentPage.onlyOnInstall && wizard.isUpdate)) {
216208 next();
217209 } else {
218210 impatientLoadingTimer.stop()
qml/Wizard/Pages/10-welcome-update.qmlnew file+46
@@ -0,0 +1,46 @@
1+/*
2+ * Copyright (C) 2015-2016 Canonical, Ltd.
3+ *
4+ * This program is free software; you can redistribute it and/or modify
5+ * it under the terms of the GNU General Public License as published by
6+ * the Free Software Foundation; version 3.
7+ *
8+ * This program is distributed in the hope that it will be useful,
9+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+ * GNU General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ */
16+
17+import QtQuick 2.4
18+import Ubuntu.Components 1.3
19+import AccountsService 0.1
20+import Wizard 0.1
21+import ".." as LocalComponents
22+
23+LocalComponents.Page {
24+ objectName: "welcomeUpdate"
25+ title: i18n.tr("Welcome to " + System.version)
26+
27+ forwardButtonSourceComponent: forwardButton
28+ onlyOnUpdate: true
29+
30+ Label {
31+ text: "This is where cool stuff would go"
32+ }
33+
34+ Component {
35+ id: forwardButton
36+ LocalComponents.StackButton {
37+ text: i18n.tr("Next")
38+ onClicked: {
39+ if (d.validName) {
40+ AccountsService.realName = d.validName;
41+ }
42+ pageStack.next();
43+ }
44+ }
45+ }
46+}
qml/Wizard/Pages/10-welcome.qml+1−2
@@ -27,8 +27,7 @@ LocalComponents.Page {
2727
2828 title: i18n.tr("Language")
2929 forwardButtonSourceComponent: forwardButton
30−
31− showOnVersions: []
30+ onlyOnInstall: true
3231
3332 UbuntuLanguagePlugin {
3433 id: plugin
qml/Wizard/Pages/11-changelog.qml+1−2
@@ -24,8 +24,7 @@ LocalComponents.Page {
2424 title: i18n.tr("What's new")
2525
2626 forwardButtonSourceComponent: forwardButton
27−
28− showOnVersions: []
27+ onlyOnUpdate: true
2928
3029 Label {
3130 text: "This is where cool stuff would go"
qml/Wizard/Pages/30-wifi.qml+1−2
@@ -31,9 +31,8 @@ LocalComponents.Page {
3131 title: i18n.tr("Connect to Wi‑Fi")
3232 forwardButtonSourceComponent: forwardButton
3333
34− showOnVersions: []
35−
3634 readonly property bool connected: Connectivity.online
35+ skip: connected
3736
3837 function getExtendedProperty(object, propertyName, defaultValue) {
3938 if (object && object.hasOwnProperty(propertyName)) {
qml/Wizard/Pages/50-timezone.qml+1
@@ -36,6 +36,7 @@ LocalComponents.Page {
3636
3737 // for testing
3838 readonly property alias tdModule: timeDatePanel
39+ onlyOnInstall: true
3940
4041 function highlightTimezone(offset) {
4142 highlightImage.source = "data/timezonemap/timezone_" + offset + ".png";
qml/Wizard/Pages/60-account.qml+1
@@ -24,6 +24,7 @@ LocalComponents.Page {
2424 title: i18n.tr("Personalize Your Device")
2525
2626 forwardButtonSourceComponent: forwardButton
27+ onlyOnInstall: true
2728
2829 QtObject {
2930 id: d
qml/Wizard/Pages/70-passwd-type.qml+1
@@ -44,6 +44,7 @@ LocalComponents.Page {
4444 // or this isn't the first time the wizard has been run, etc). We can't
4545 // properly set the password again, so let's not pretend we can.
4646 skip: securityPrivacy.securityType !== UbuntuSecurityPrivacyPanel.Swipe
47+ onlyOnInstall: true
4748
4849 function indexToMethod(index) {
4950 if (index === 0/* || index === 1*/)
qml/Wizard/Pages/75-report-check.qml+1
@@ -27,6 +27,7 @@ LocalComponents.Page {
2727 forwardButtonSourceComponent: !webview.visible ? forwardButton : null
2828 customBack: true
2929 customTitle: webview.visible
30+ onlyOnInstall: true
3031
3132 skip: !diagnostics.reportCrashes // skip the page when the system is configured not to report crashes
3233
qml/Wizard/Pages/78-app-update.qml+1−1
@@ -42,7 +42,7 @@ LocalComponents.Page {
4242 property bool online: NetworkingStatus.online
4343 property bool authenticated: UpdateManager.authenticated
4444
45− showOnVersions: [1]
45+ onlyOnUpdate: true
4646
4747 property int updatesCount: {
4848 var count = 0;
qml/Wizard/Pages/80-finished.qml+1−1
@@ -25,7 +25,7 @@ LocalComponents.Page {
2525 customTitle: true
2626 lastPage: true
2727 buttonBarVisible: false
28− showOnVersions: []
28+ onlyOnInstall: true
2929
3030 Component.onCompleted: {
3131 state = "reanchored";
qml/Wizard/Wizard.qml+1−4
@@ -29,10 +29,7 @@ Showable {
2929 // expected behavior of no emission on startup.
3030 readonly property bool active: loader.active
3131
32− // Hold the version of the wizard that is currently running. 0 means the
33− // first-run wizard, -1 means no wizard, a higher number signifies the
34− // wizard version that is running.
35− property int runningWizardVersion: System.versionToShow
32+ property bool isUpdate: System.isUpdate
3633
3734 // The wizard should be run at a later time if, for example, unity8 is
3835 // in greeter mode