play_time_manager.h 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // SPDX-FileCopyrightText: 2023 yuzu Emulator Project & 2024 suyu Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #pragma once
  4. #include <QString>
  5. #include <map>
  6. #include "common/common_funcs.h"
  7. #include "common/common_types.h"
  8. #include "common/polyfill_thread.h"
  9. namespace Service::Account {
  10. class ProfileManager;
  11. }
  12. namespace PlayTime {
  13. using ProgramId = u64;
  14. using PlayTime = u64;
  15. using PlayTimeDatabase = std::map<ProgramId, PlayTime>;
  16. class PlayTimeManager {
  17. public:
  18. explicit PlayTimeManager(Service::Account::ProfileManager& profile_manager);
  19. ~PlayTimeManager();
  20. SUYU_NON_COPYABLE(PlayTimeManager);
  21. SUYU_NON_MOVEABLE(PlayTimeManager);
  22. u64 GetPlayTime(u64 program_id) const;
  23. void ResetProgramPlayTime(u64 program_id);
  24. void SetProgramId(u64 program_id);
  25. void Start();
  26. void Stop();
  27. private:
  28. void AutoTimestamp(std::stop_token stop_token);
  29. void Save();
  30. PlayTimeDatabase database;
  31. u64 running_program_id;
  32. std::jthread play_time_thread;
  33. Service::Account::ProfileManager& manager;
  34. };
  35. QString ReadablePlayTime(qulonglong time_seconds);
  36. } // namespace PlayTime