popup_service.cpp 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. * progress_dialog.cpp
  3. *
  4. * Created on: 2021年10月30日
  5. * Author: pengzc
  6. */
  7. #include "popup_service.h"
  8. #include "entry/EasyuiContext.h"
  9. #include "utils/Log.h"
  10. #include "base/os.hpp"
  11. void NavibarSetProgressMessage(const std::string& msg);
  12. void NavibarProgressAnimation(bool visible);
  13. void NavibarSetDialog1Message(const std::string& msg);
  14. void NavibarSetProgressWindowVisible(bool visible);
  15. void NavibarSetDialog1WindowVisible(bool visible);
  16. PopupService::PopupService() {
  17. busy_ = false;
  18. }
  19. PopupService::~PopupService() {
  20. }
  21. PopupService* PopupService::instance() {
  22. static PopupService singleton;
  23. return &singleton;
  24. }
  25. void PopupService::Dialog(const std::string& text) {
  26. instance()->InternalShow([text](PopupService* dialog){
  27. NavibarSetDialog1Message(text);
  28. return 0;
  29. }, PopupType::Dialog);
  30. }
  31. bool PopupService::busy() {
  32. return instance()->busy_;
  33. }
  34. void PopupService::InternalShow(const Task& func, PopupType type) {
  35. if (busy_) {
  36. LOGD("popup service is busy");
  37. return;
  38. }
  39. busy_ = true;
  40. std::thread backend([this, func, type](){
  41. base::screensaver_guard guard;
  42. //EASYUICONTEXT->showNaviBar();
  43. NavibarSetProgressMessage("");
  44. NavibarSetDialog1Message("");
  45. NavibarSetProgressWindowVisible(type == PopupType::Progress);
  46. NavibarSetDialog1WindowVisible(type == PopupType::Dialog);
  47. NavibarProgressAnimation(type == PopupType::Progress);
  48. int ret = func(this);
  49. if (type == PopupType::Progress) {
  50. if (0 != ret) {
  51. usleep(1000 * 2000);
  52. }
  53. NavibarSetProgressWindowVisible(false);
  54. //EASYUICONTEXT->hideNaviBar();
  55. busy_ = false;
  56. }
  57. NavibarProgressAnimation(false);
  58. });
  59. backend.detach();
  60. }
  61. void PopupService::Show(Task task) {
  62. LOGD("%s", __PRETTY_FUNCTION__);
  63. instance()->InternalShow(task, PopupType::Progress);
  64. }
  65. void PopupService::Show(Task task, PopupType type) {
  66. instance()->InternalShow(task, type);
  67. }
  68. void PopupService::SetMessage(const std::string& msg) {
  69. NavibarSetProgressMessage(msg);
  70. }
  71. void PopupService::Animation(bool visible) {
  72. NavibarProgressAnimation(visible);
  73. }