1// Aseprite
2// Copyright (C) 2020 Igara Studio S.A.
3// Copyright (C) 2001-2017 David Capello
4//
5// This program is distributed under the terms of
6// the End-User License Agreement for Aseprite.
7
8#ifdef HAVE_CONFIG_H
9#include "config.h"
10#endif
11
12#include "app/commands/command.h"
13#include "app/commands/params.h"
14#include "app/launcher.h"
15#include "base/fs.h"
16#include "ver/info.h"
17
18namespace app {
19
20class LaunchCommand : public Command {
21public:
22 LaunchCommand();
23
24protected:
25 void onLoadParams(const Params& params) override;
26 void onExecute(Context* context) override;
27
28private:
29 enum Type { Url };
30
31 Type m_type;
32 std::string m_path;
33};
34
35LaunchCommand::LaunchCommand()
36 : Command(CommandId::Launch(), CmdUIOnlyFlag)
37 , m_type(Url)
38 , m_path("")
39{
40}
41
42void LaunchCommand::onLoadParams(const Params& params)
43{
44 m_path = params.get("path");
45
46 if (m_type == Url && !m_path.empty() && m_path[0] == '/') {
47 m_path = std::string(get_app_url()) + m_path.substr(1);
48 }
49}
50
51void LaunchCommand::onExecute(Context* context)
52{
53 switch (m_type) {
54
55 case Url:
56 launcher::open_url(m_path);
57 break;
58
59 }
60}
61
62Command* CommandFactory::createLaunchCommand()
63{
64 return new LaunchCommand;
65}
66
67} // namespace app
68