diff --git a/rpm/patchmanager.spec b/rpm/patchmanager.spec
index 571bfd629..41cf3e16c 100644
--- a/rpm/patchmanager.spec
+++ b/rpm/patchmanager.spec
@@ -112,6 +112,8 @@ dbus-send --system --type=method_call \
%{_datadir}/%{name}/tools
%{_datadir}/dbus-1/
%{_sysconfdir}/dbus-1/system.d/
+%{_datadir}/patchmanager/patches/sailfishos-patchmanager-unapplyall/patch.json
+%{_datadir}/patchmanager/patches/sailfishos-patchmanager-unapplyall/unified_diff.patch
# >> files
# << files
diff --git a/rpm/patchmanager.yaml b/rpm/patchmanager.yaml
index 93a49b39b..6cf171fa0 100644
--- a/rpm/patchmanager.yaml
+++ b/rpm/patchmanager.yaml
@@ -29,6 +29,8 @@ Files:
- '%{_datadir}/%{name}/tools'
- '%{_datadir}/dbus-1/'
- '%{_sysconfdir}/dbus-1/system.d/'
+- '%{_datadir}/patchmanager/patches/sailfishos-patchmanager-unapplyall/patch.json'
+- '%{_datadir}/patchmanager/patches/sailfishos-patchmanager-unapplyall/unified_diff.patch'
SubPackages:
- Name: ui
Summary: GUI for patchmanager
diff --git a/src/bin/patchmanager-daemon/dbus/org.SfietKonstantin.patchmanager.xml b/src/bin/patchmanager-daemon/dbus/org.SfietKonstantin.patchmanager.xml
index 76369f678..86ca82754 100644
--- a/src/bin/patchmanager-daemon/dbus/org.SfietKonstantin.patchmanager.xml
+++ b/src/bin/patchmanager-daemon/dbus/org.SfietKonstantin.patchmanager.xml
@@ -21,7 +21,9 @@
-
+
+
+
diff --git a/src/bin/patchmanager-daemon/patch/patch.json b/src/bin/patchmanager-daemon/patch/patch.json
new file mode 100644
index 000000000..f8c84c3e2
--- /dev/null
+++ b/src/bin/patchmanager-daemon/patch/patch.json
@@ -0,0 +1,8 @@
+{
+ "name": "Unapply all patches on Upgrade",
+ "description": "Patch for unapplying all patches when upgrading SailfishOS version. Do not unapply this patch manually, unless you want to completely uninstall Patchmanager.",
+ "category": "settings",
+ "infos": {
+ "maintainer": "coderus"
+ }
+}
diff --git a/src/bin/patchmanager-daemon/patch/unified_diff.patch b/src/bin/patchmanager-daemon/patch/unified_diff.patch
new file mode 100644
index 000000000..01c4309a4
--- /dev/null
+++ b/src/bin/patchmanager-daemon/patch/unified_diff.patch
@@ -0,0 +1,81 @@
+diff --git a/usr/share/jolla-settings/pages/sailfishos/mainpage.qml b/usr/share/jolla-settings/pages/sailfishos/mainpage.qml
+index ca5c814..c330236 100644
+--- a/usr/share/jolla-settings/pages/sailfishos/mainpage.qml
++++ b/usr/share/jolla-settings/pages/sailfishos/mainpage.qml
+@@ -127,6 +127,25 @@ Page {
+ iface: "org.nemomobile.lipstick"
+ }
+
++ DBusInterface {
++ id: patchmanagerBus
++ busType: DBusInterface.SystemBus
++ destination: "org.SfietKonstantin.patchmanager"
++ path: "/org/SfietKonstantin/patchmanager"
++ iface: "org.SfietKonstantin.patchmanager"
++ }
++
++ function unapplyAllCallback(arg) {
++ if (arg) {
++ // Let the UI smoothly fade out first before doing anything scary
++ shutdownBus.call("setShutdownMode", ["upgrade"])
++ // Clear the cache and the system update notification
++ storeIf.clearOsUpdateCheckCache()
++ } else {
++ patchmanagerBus.call("applyPatch", ["sailfishos-patchmanager-unapplyall"])
++ }
++ }
++
+ SilicaFlickable {
+ anchors.fill: parent
+ contentHeight: content.height
+@@ -250,10 +269,7 @@ Page {
+ }
+ }
+ } else if (storeIf.mayInstall) {
+- // Let the UI smoothly fade out first before doing anything scary
+- shutdownBus.call("setShutdownMode", ["upgrade"])
+- // Clear the cache and the system update notification
+- storeIf.clearOsUpdateCheckCache()
++ patchmanagerBus.call("unapplyAllPatches", [], unapplyAllCallback)
+ }
+ }
+ }
+index ca5c814..4fd6f01 100644
+--- a/usr/share/jolla-settings/pages/sailfishos/mainpage.qml
++++ b/usr/share/jolla-settings/pages/sailfishos/mainpage.qml
+@@ -127,6 +127,23 @@ Page {
+ iface: "org.nemomobile.lipstick"
+ }
+
++ DBusInterface {
++ id: patchmanagerBus
++ busType: DBusInterface.SystemBus
++ destination: "org.SfietKonstantin.patchmanager"
++ path: "/org/SfietKonstantin/patchmanager"
++ iface: "org.SfietKonstantin.patchmanager"
++ }
++
++ function unapplyAllCallback(arg) {
++ if (arg) {
++ // Let the UI smoothly fade out first before doing anything scary
++ shutdownBus.call("setShutdownMode", ["upgrade"])
++ // Clear the cache and the system update notification
++ storeIf.clearOsUpdateCheckCache()
++ }
++ }
++
+ SilicaFlickable {
+ anchors.fill: parent
+ contentHeight: content.height
+@@ -250,10 +267,7 @@ Page {
+ }
+ }
+ } else if (storeIf.mayInstall) {
+- // Let the UI smoothly fade out first before doing anything scary
+- shutdownBus.call("setShutdownMode", ["upgrade"])
+- // Clear the cache and the system update notification
+- storeIf.clearOsUpdateCheckCache()
++ patchmanagerBus.call("unapplyAllPatches", [], unapplyAllCallback)
+ }
+ }
+ }
diff --git a/src/bin/patchmanager-daemon/patchmanager-daemon.pro b/src/bin/patchmanager-daemon/patchmanager-daemon.pro
index 4d40916ab..5a354b178 100644
--- a/src/bin/patchmanager-daemon/patchmanager-daemon.pro
+++ b/src/bin/patchmanager-daemon/patchmanager-daemon.pro
@@ -41,3 +41,8 @@ INSTALLS += dbusConf
tools.files = check-package.sh
tools.path = /usr/share/patchmanager/tools
INSTALLS += tools
+
+# Patch
+patch.path = /usr/share/patchmanager/patches/sailfishos-patchmanager-unapplyall
+patch.files = patch/patch.json patch/unified_diff.patch
+INSTALLS += patch
diff --git a/src/bin/patchmanager-daemon/patchmanagerobject.cpp b/src/bin/patchmanager-daemon/patchmanagerobject.cpp
index 73d72e144..4f85d42a1 100644
--- a/src/bin/patchmanager-daemon/patchmanagerobject.cpp
+++ b/src/bin/patchmanager-daemon/patchmanagerobject.cpp
@@ -345,16 +345,17 @@ bool PatchManagerObject::unapplyPatch(const QString &patch)
return ok;
}
-//void PatchManagerObject::unapplyAllPatches()
-//{
+bool PatchManagerObject::unapplyAllPatches()
+{
// checkPatches();
-
-// QStringList appliedPatches = m_appliedPatches.toList();
-// foreach (const QString &patch, appliedPatches) {
-// unapplyPatch(patch);
-// }
+ bool ok = true;
+ QStringList appliedPatches = m_appliedPatches.toList();
+ foreach (const QString &patch, appliedPatches) {
+ ok &= unapplyPatch(patch);
+ }
+ return ok;
// quit();
-//}
+}
//void PatchManagerObject::checkPatches()
//{
diff --git a/src/bin/patchmanager-daemon/patchmanagerobject.h b/src/bin/patchmanager-daemon/patchmanagerobject.h
index a749c9d8f..01467684b 100644
--- a/src/bin/patchmanager-daemon/patchmanagerobject.h
+++ b/src/bin/patchmanager-daemon/patchmanagerobject.h
@@ -75,7 +75,7 @@ public slots:
bool isPatchApplied(const QString &patch);
bool applyPatch(const QString &patch);
bool unapplyPatch(const QString &patch);
-// void unapplyAllPatches();
+ bool unapplyAllPatches();
PackageBackupStatus checkLipstick();
void quit();
protected: