Skip to content

Commit 1e981f7

Browse files
committed
Added extension update modal dialog
(cherry picked from commit 585139b)
1 parent 430475f commit 1e981f7

8 files changed

+53
-2
lines changed

Diff for: src/framework/extensions/extensionstypes.h

+1
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ struct Manifest {
218218
};
219219

220220
Uri uri;
221+
io::path_t path;
221222
Type type = Type::Undefined;
222223
String title;
223224
String description;

Diff for: src/framework/extensions/iextensionsprovider.h

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class IExtensionsProvider : MODULE_EXPORT_INTERFACE
3838
virtual ~IExtensionsProvider() = default;
3939

4040
virtual void reloadExtensions() = 0;
41+
virtual Ret removeExtension(const Uri& uri) = 0;
4142

4243
virtual ManifestList manifestList(Filter filter = Filter::All) const = 0;
4344
virtual async::Notification manifestListChanged() const = 0;

Diff for: src/framework/extensions/internal/extensioninstaller.cpp

+22-2
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,31 @@ Ret ExtensionInstaller::installExtension(const io::path_t srcPath)
3636
ExtensionsLoader loader;
3737
Manifest m = loader.parseManifest(data);
3838

39-
bool hasSame = provider()->manifest(m.uri).isValid();
40-
if (hasSame) {
39+
Manifest existingManifest = provider()->manifest(m.uri);
40+
bool alreadyInstalled = existingManifest.isValid();
41+
if (alreadyInstalled && existingManifest.version == m.version) {
4142
LOGI() << "already installed: " << m.uri;
43+
44+
interactive()->info("Info", "The extension is already installed.", { interactive()->buttonData(IInteractive::Button::Ok) });
45+
4246
return make_ok();
4347
}
48+
49+
if (alreadyInstalled) {
50+
std::stringstream text;
51+
text << "The extension \"" << existingManifest.title.toStdString() <<
52+
"\" is already installed in a different version.\nDo you want to upgrade?\n\nCurrent version: " <<
53+
existingManifest.version.toStdString() << "\nNew version: " << m.version.toStdString();
54+
IInteractive::Result result = interactive()->question("Update Extension", text.str(), {
55+
interactive()->buttonData(IInteractive::Button::Cancel), interactive()->buttonData(IInteractive::Button::Ok)
56+
});
57+
58+
if (result.button() == int(IInteractive::Button::Ok)) {
59+
provider()->removeExtension(existingManifest.uri);
60+
} else {
61+
return make_ok();
62+
}
63+
}
4464
}
4565

4666
// unpack

Diff for: src/framework/extensions/internal/extensioninstaller.h

+4
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,16 @@
55
#include "modularity/ioc.h"
66
#include "../iextensionsconfiguration.h"
77
#include "../iextensionsprovider.h"
8+
#include "global/iinteractive.h"
9+
#include "io/ifilesystem.h"
810

911
namespace muse::extensions {
1012
class ExtensionInstaller : public IExtensionInstaller
1113
{
1214
muse::GlobalInject<IExtensionsConfiguration> configuration;
1315
muse::GlobalInject<IExtensionsProvider> provider;
16+
muse::GlobalInject<muse::IInteractive> interactive;
17+
muse::GlobalInject<io::IFileSystem> fileSystem;
1418

1519
public:
1620
ExtensionInstaller() = default;

Diff for: src/framework/extensions/internal/extensionsloader.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ ManifestList ExtensionsLoader::manifestList(const io::path_t& rootPath) const
8080
for (const io::path_t& path : paths) {
8181
LOGD() << "parsing manifest: " << path;
8282
Manifest manifest = parseManifest(path);
83+
manifest.path = path;
8384
resolvePaths(manifest, io::FileInfo(path).dirPath());
8485
manifests.push_back(manifest);
8586
}

Diff for: src/framework/extensions/internal/extensionsprovider.cpp

+20
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
#include "global/containers.h"
2525
#include "global/async/async.h"
26+
#include "global/io/fileinfo.h"
2627

2728
#include "extensionsloader.h"
2829
#include "legacy/extpluginsloader.h"
@@ -68,6 +69,25 @@ void ExtensionsProvider::reloadExtensions()
6869
m_manifestListChanged.notify();
6970
}
7071

72+
muse::Ret ExtensionsProvider::removeExtension(const Uri& uri)
73+
{
74+
const Manifest manifest = this->manifest(uri);
75+
if (!manifest.isValid()) {
76+
return make_ret(Ret::Code::UnknownError);
77+
}
78+
79+
io::path_t path = manifest.path;
80+
81+
if (!fileSystem()->remove(io::FileInfo(path).dirPath())) {
82+
LOGE() << "Failed to delete the folder: " << path;
83+
return make_ok();
84+
} else {
85+
LOGI() << "Successfully deleted the folder: " << path;
86+
this->reloadExtensions();
87+
return make_ret(Ret::Code::UnknownError);
88+
}
89+
}
90+
7191
ManifestList ExtensionsProvider::manifestList(Filter filter) const
7292
{
7393
if (filter == Filter::Enabled) {

Diff for: src/framework/extensions/internal/extensionsprovider.h

+3
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,22 @@
2929
#include "../iextensionsprovider.h"
3030
#include "../iextensionsexecpointsregister.h"
3131
#include "global/iinteractive.h"
32+
#include "io/ifilesystem.h"
3233

3334
namespace muse::extensions {
3435
class ExtensionsProvider : public IExtensionsProvider, public Injectable, public async::Asyncable
3536
{
3637
Inject<IExtensionsConfiguration> configuration = { this };
3738
Inject<IExtensionsExecPointsRegister> execPointsRegister = { this };
3839
Inject<IInteractive> interactive = { this };
40+
Inject<io::IFileSystem> fileSystem = { this };
3941

4042
public:
4143
ExtensionsProvider(const modularity::ContextPtr& iocCtx)
4244
: Injectable(iocCtx) {}
4345

4446
void reloadExtensions() override;
47+
Ret removeExtension(const Uri& uri) override;
4548

4649
ManifestList manifestList(Filter filter = Filter::All) const override;
4750
async::Notification manifestListChanged() const override;

Diff for: src/framework/extensions/internal/legacy/extpluginsloader.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ ManifestList ExtPluginsLoader::manifestList(const io::path_t& rootPath) const
9595
if (!manifest.isValid()) {
9696
continue;
9797
}
98+
manifest.path = path;
9899
resolvePaths(manifest, io::FileInfo(path).dirPath());
99100
manifests.push_back(manifest);
100101
}

0 commit comments

Comments
 (0)