Line data Source code
1 : /*
2 : * SPDX-License-Identifier: GPL-3.0-only
3 : * MuseScore-CLA-applies
4 : *
5 : * MuseScore Studio
6 : * Music Composition & Notation
7 : *
8 : * Copyright (C) 2025 MuseScore Limited and others
9 : *
10 : * This program is free software: you can redistribute it and/or modify
11 : * it under the terms of the GNU General Public License version 3 as
12 : * published by the Free Software Foundation.
13 : *
14 : * This program is distributed in the hope that it will be useful,
15 : * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 : * GNU General Public License for more details.
18 : *
19 : * You should have received a copy of the GNU General Public License
20 : * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 : */
22 :
23 : #pragma once
24 :
25 : #include "update/iappupdatescenario.h"
26 : #include "async/asyncable.h"
27 : #include "modularity/ioc.h"
28 :
29 : #include "interactive/iinteractive.h"
30 : #include "rcommand/icommanddispatcher.h"
31 : #include "multiwindows/imultiwindowsprovider.h"
32 : #include "network/inetworkinformation.h"
33 : #include "toast/itoastservice.h"
34 : #include "update/iupdateconfiguration.h"
35 : #include "update/iappupdateservice.h"
36 : #include "global/iapplication.h"
37 :
38 : namespace muse::update {
39 : class AppUpdateScenario : public IAppUpdateScenario, public Contextable, public async::Asyncable
40 : {
41 : GlobalInject<IApplication> application;
42 : GlobalInject<mi::IMultiWindowsProvider> multiwindowsProvider;
43 : GlobalInject<IUpdateConfiguration> configuration;
44 : GlobalInject<network::INetworkInformation> networkInformation;
45 : GlobalInject<toast::IToastService> toastService;
46 : ContextInject<IInteractive> interactive = { this };
47 : ContextInject<rcommand::ICommandDispatcher> commandDispatcher = { this };
48 : ContextInject<IAppUpdateService> service = { this };
49 :
50 : public:
51 36 : AppUpdateScenario(const modularity::ContextPtr& iocCtx)
52 36 : : Contextable(iocCtx) {}
53 :
54 : void delayedInit();
55 :
56 : bool needCheckForUpdate() const override;
57 : void checkForUpdate(bool manual) override;
58 :
59 : private:
60 : friend class AppUpdateScenarioTests;
61 :
62 : bool hasUpdate() const;
63 :
64 : muse::async::Promise<Ret> processUpdateError(const Ret& error);
65 :
66 : async::Promise<IInteractive::Result> showNoUpdateMsg();
67 : muse::async::Promise<Ret> showReleaseInfo(const ReleaseInfo& info, bool readyToInstall);
68 : void showUpdateAvailableToast(const ReleaseInfo& info, bool downloaded);
69 : void showUpdateCompletedToast();
70 : std::string applyReleaseInfoResult(const Val& result);
71 : async::Promise<IInteractive::Result> showServerErrorMsg();
72 : async::Promise<Ret> askToRetryOnNotEnoughDiskSpace(const Ret& error, const std::function<async::Promise<Ret>()>& retry);
73 :
74 : void downloadUpdateInBackground();
75 :
76 : muse::async::Promise<Ret> downloadRelease(bool confirmRestart = true);
77 : muse::async::Promise<Ret> askToCloseAppAndCompleteInstall();
78 : void closeAppAndCompleteInstall();
79 :
80 : bool shouldIgnoreUpdate(const ReleaseInfo& info) const;
81 : void skipRelease(const std::string& version);
82 : void unskipRelease(const std::string& version);
83 :
84 : bool m_checkInProgress = false;
85 : bool m_bgDownloadInProgress = false;
86 : };
87 : }
|