notify.cpp 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. /*
  2. * Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibCore/ArgsParser.h>
  7. #include <LibGUI/Application.h>
  8. #include <LibGUI/Notification.h>
  9. #include <LibGfx/Bitmap.h>
  10. #include <LibMain/Main.h>
  11. ErrorOr<int> serenity_main(Main::Arguments arguments)
  12. {
  13. auto app = TRY(GUI::Application::create(arguments));
  14. Core::ArgsParser args_parser;
  15. String title {};
  16. String message {};
  17. StringView icon_path {};
  18. args_parser.add_positional_argument(title, "Title of the notification", "title");
  19. args_parser.add_positional_argument(message, "Message to display in the notification", "message");
  20. args_parser.add_positional_argument(icon_path, "Path of icon to display in the notification", "icon-path", Core::ArgsParser::Required::No);
  21. args_parser.parse(arguments);
  22. auto notification = GUI::Notification::construct();
  23. notification->set_text(message);
  24. notification->set_title(title);
  25. if (!icon_path.is_empty()) {
  26. notification->set_icon(TRY(Gfx::Bitmap::load_from_file(icon_path)));
  27. }
  28. notification->show();
  29. return 0;
  30. }