mirror of
https://github.com/zebrajr/SamRewritten.git
synced 2025-12-06 12:19:51 +01:00
Not much, todo: more on loading times
This commit is contained in:
parent
8058b6cd3d
commit
799edb845f
|
|
@ -143,7 +143,7 @@ He's pretty confident they won't take much longer to arrive, but is also wrong m
|
|||
<property name="can_focus">False</property>
|
||||
<property name="icon_name">face-wink</property>
|
||||
<signal name="delete-event" handler="on_close_button_clicked" swapped="no"/>
|
||||
<signal name="show" handler="on_main_window_show" swapped="no"/>
|
||||
<signal name="show" handler="on_main_window_show" after="yes" swapped="no"/>
|
||||
<child type="titlebar">
|
||||
<object class="GtkHeaderBar">
|
||||
<property name="visible">True</property>
|
||||
|
|
@ -174,12 +174,12 @@ He's pretty confident they won't take much longer to arrive, but is also wrong m
|
|||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">True</property>
|
||||
<property name="popover">search_popover</property>
|
||||
<property name="popover">popovermenu</property>
|
||||
<child>
|
||||
<object class="GtkImage">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="icon_name">edit-find-symbolic</property>
|
||||
<property name="icon_name">open-menu-symbolic</property>
|
||||
<property name="icon_size">1</property>
|
||||
</object>
|
||||
</child>
|
||||
|
|
@ -194,12 +194,12 @@ He's pretty confident they won't take much longer to arrive, but is also wrong m
|
|||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">True</property>
|
||||
<property name="popover">popovermenu</property>
|
||||
<property name="popover">search_popover</property>
|
||||
<child>
|
||||
<object class="GtkImage">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="icon_name">open-menu-symbolic</property>
|
||||
<property name="icon_name">edit-find-symbolic</property>
|
||||
<property name="icon_size">1</property>
|
||||
</object>
|
||||
</child>
|
||||
|
|
|
|||
|
|
@ -87,33 +87,36 @@ MySteam::quit_game() {
|
|||
void
|
||||
MySteam::refresh_owned_apps() {
|
||||
/*
|
||||
TODO: Scanning through all apps with this method results in not receiving
|
||||
any apps
|
||||
Works for me please comment what errors you are getting or open an issue
|
||||
|
||||
Hypothesis: the steamclient.so file must be from the same version than the currently installed
|
||||
Steam version.
|
||||
*/
|
||||
Game_t game;
|
||||
SteamAppDAO* appDAO = SteamAppDAO::get_instance();
|
||||
|
||||
// The whole update will really occur only once in a while, no worries
|
||||
appDAO->update_name_database(); // Downloads and parses app list from Steam
|
||||
m_all_subscribed_apps.clear();
|
||||
if(m_owned_games_lock.try_lock()) {
|
||||
Game_t game;
|
||||
SteamAppDAO* appDAO = SteamAppDAO::get_instance();
|
||||
|
||||
auto all_apps = appDAO->get_all_apps();
|
||||
for (auto pair : all_apps) {
|
||||
auto app_id = pair.first;
|
||||
if (appDAO->app_is_owned(app_id))
|
||||
{
|
||||
game.app_id = pair.first;
|
||||
game.app_name = pair.second;
|
||||
// The whole update will really occur only once in a while, no worries
|
||||
appDAO->update_name_database(); // Downloads and parses app list from Steam
|
||||
m_all_subscribed_apps.clear();
|
||||
|
||||
m_all_subscribed_apps.push_back(game);
|
||||
auto all_apps = appDAO->get_all_apps();
|
||||
for (auto pair : all_apps) {
|
||||
auto app_id = pair.first;
|
||||
if (appDAO->app_is_owned(app_id))
|
||||
{
|
||||
game.app_id = pair.first;
|
||||
game.app_name = pair.second;
|
||||
|
||||
m_all_subscribed_apps.push_back(game);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::sort(m_all_subscribed_apps.begin(), m_all_subscribed_apps.end(), comp_app_name);
|
||||
std::sort(m_all_subscribed_apps.begin(), m_all_subscribed_apps.end(), comp_app_name);
|
||||
m_owned_games_lock.unlock();
|
||||
}
|
||||
else {
|
||||
std::cerr << "Will not refresh owned apps because the lock is already accquired" << std::endl;
|
||||
}
|
||||
}
|
||||
// => refresh_owned_apps
|
||||
|
||||
|
|
@ -202,7 +205,7 @@ MySteam::remove_modification_ach(const std::string& ach_id) {
|
|||
* Commit pending achievement changes
|
||||
*/
|
||||
void
|
||||
MySteam::commit_changes(void) {
|
||||
MySteam::commit_changes() {
|
||||
std::vector<AchievementChange_t> changes;
|
||||
|
||||
for ( const auto& [key, val] : m_pending_ach_modifications) {
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@
|
|||
#include <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <mutex>
|
||||
|
||||
/**
|
||||
* MySteam is the highest-level class of the program. Use it to
|
||||
|
|
@ -66,7 +67,7 @@ public:
|
|||
* in user. Make sure to call refresh_owned_apps at least once to get
|
||||
* correct results
|
||||
*/
|
||||
std::vector<Game_t> get_all_games_with_stats() { return m_all_subscribed_apps; };
|
||||
std::vector<Game_t> get_subscribed_apps() { return m_all_subscribed_apps; };
|
||||
|
||||
/**
|
||||
* Get achievements of the launched app
|
||||
|
|
@ -97,7 +98,7 @@ public:
|
|||
/**
|
||||
* Commit pending changes
|
||||
*/
|
||||
void commit_changes(void);
|
||||
void commit_changes();
|
||||
|
||||
MySteam(MySteam const&) = delete;
|
||||
void operator=(MySteam const&) = delete;
|
||||
|
|
@ -115,4 +116,5 @@ private:
|
|||
std::vector<Game_t> m_all_subscribed_apps;
|
||||
std::map<std::string, bool> m_pending_ach_modifications;
|
||||
std::map<std::string, double> m_pending_stat_modifications;
|
||||
std::mutex m_owned_games_lock;
|
||||
};
|
||||
24
src/common/PerfMon.cpp
Normal file
24
src/common/PerfMon.cpp
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
#include "PerfMon.h"
|
||||
#include <iostream>
|
||||
#include <thread>
|
||||
#include <unistd.h>
|
||||
|
||||
PerfMon::PerfMon() : m_start(std::clock())
|
||||
{
|
||||
log("PerfMon started.");
|
||||
}
|
||||
|
||||
PerfMon::~PerfMon()
|
||||
{
|
||||
log("PerfMon shutdown.");
|
||||
}
|
||||
|
||||
void
|
||||
PerfMon::log(const std::string& what)
|
||||
{
|
||||
std::cerr
|
||||
<< "[PID:" << getpid()
|
||||
<< " TRD:" << std::this_thread::get_id()
|
||||
<< " TME:" << double(std::clock() - m_start) / CLOCKS_PER_SEC
|
||||
<< "] \t" << what << std::endl;
|
||||
}
|
||||
15
src/common/PerfMon.h
Normal file
15
src/common/PerfMon.h
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
#pragma once
|
||||
#include <ctime>
|
||||
#include <string>
|
||||
|
||||
class PerfMon
|
||||
{
|
||||
private:
|
||||
std::clock_t m_start;
|
||||
public:
|
||||
PerfMon();
|
||||
~PerfMon();
|
||||
void log(const std::string& what);
|
||||
};
|
||||
|
||||
|
||||
|
|
@ -3,6 +3,7 @@
|
|||
class MySteam;
|
||||
class MainPickerWindow;
|
||||
class MySteamClient;
|
||||
class PerfMon;
|
||||
|
||||
// Reason for the globals is that it's easier to access them in GTK callbacks
|
||||
// All those variables are initialised in main.cpp
|
||||
|
|
@ -35,3 +36,8 @@ extern MainPickerWindow *g_main_gui;
|
|||
* ~/.SamRewritten
|
||||
*/
|
||||
extern char *g_cache_folder;
|
||||
|
||||
/**
|
||||
* A basic performance monitor
|
||||
*/
|
||||
extern PerfMon *g_perfmon;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
#include "MainPickerWindow.h"
|
||||
#include <iostream>
|
||||
#include "../common/functions.h"
|
||||
#include "../common/PerfMon.h"
|
||||
#include "../globals.h"
|
||||
#include "../types/Achievement.h"
|
||||
#include "gtk_callbacks.h"
|
||||
|
|
@ -183,17 +184,15 @@ MainPickerWindow::refresh_app_icon(const unsigned long app_id) {
|
|||
g_list_free(children);
|
||||
|
||||
pixbuf = gdk_pixbuf_new_from_file(path.c_str(), &error);
|
||||
if (error != NULL) {
|
||||
std::cerr << "Error while loading an app's logo: " << std::endl;
|
||||
std::cerr << "AppId: " << app_id << std::endl;
|
||||
std::cerr << "Message: " << error->message << std::endl;
|
||||
}
|
||||
else {
|
||||
//Quick and jerky, quality isn't key here
|
||||
if (error == NULL) {
|
||||
// Quick and jerky, quality isn't key here
|
||||
// Is the excess of memory freed though?
|
||||
pixbuf = gdk_pixbuf_scale_simple(pixbuf, 146, 68, GDK_INTERP_NEAREST);
|
||||
gtk_image_set_from_pixbuf(img, pixbuf);
|
||||
}
|
||||
else {
|
||||
std::cerr << "Error loading banner: " << error->message << std::endl;
|
||||
}
|
||||
|
||||
}
|
||||
// => refresh_app_icon
|
||||
|
|
@ -268,4 +267,18 @@ MainPickerWindow::switch_to_games_page() {
|
|||
}
|
||||
m_achievement_list_rows.clear();
|
||||
}
|
||||
// => switch_to_games_page
|
||||
// => switch_to_games_page
|
||||
|
||||
void
|
||||
MainPickerWindow::show() {
|
||||
gtk_widget_show( get_main_window() );
|
||||
gtk_main();
|
||||
}
|
||||
// => show
|
||||
|
||||
void
|
||||
MainPickerWindow::stop() {
|
||||
gtk_main_quit();
|
||||
gtk_widget_destroy( get_main_window() );
|
||||
}
|
||||
// => stop
|
||||
|
|
@ -21,6 +21,16 @@ public:
|
|||
*/
|
||||
MainPickerWindow();
|
||||
|
||||
/**
|
||||
* Starts a gtk_main
|
||||
*/
|
||||
void show();
|
||||
|
||||
/**
|
||||
* Quit all
|
||||
*/
|
||||
void stop();
|
||||
|
||||
/**
|
||||
* Empty the game list, leaving only the placeholder widget,
|
||||
* which means the loading widget.
|
||||
|
|
@ -101,6 +111,7 @@ private:
|
|||
GtkStack *m_main_stack;
|
||||
GtkScrolledWindow *m_game_list_view;
|
||||
GtkScrolledWindow *m_stats_list_view;
|
||||
|
||||
std::map<unsigned long, GtkWidget*> m_game_list_rows;
|
||||
std::vector<GtkAchievementBoxRow*> m_achievement_list_rows;
|
||||
};
|
||||
|
|
@ -1,6 +1,8 @@
|
|||
#include "gtk_callbacks.h"
|
||||
#include <iostream>
|
||||
#include <thread>
|
||||
#include "MainPickerWindow.h"
|
||||
#include "../common/PerfMon.h"
|
||||
#include "../MySteam.h"
|
||||
#include "../globals.h"
|
||||
|
||||
|
|
@ -29,11 +31,10 @@ extern "C"
|
|||
|
||||
void
|
||||
on_close_button_clicked() {
|
||||
gtk_main_quit();
|
||||
gtk_widget_destroy(g_main_gui->get_main_window());
|
||||
|
||||
g_main_gui->stop();
|
||||
|
||||
delete g_main_gui;
|
||||
g_main_gui = NULL;
|
||||
g_main_gui = nullptr;
|
||||
|
||||
g_steam->quit_game();
|
||||
}
|
||||
|
|
@ -51,22 +52,28 @@ extern "C"
|
|||
|
||||
void
|
||||
on_ask_game_refresh() {
|
||||
|
||||
g_perfmon->log("Starting library parsing.");
|
||||
|
||||
g_main_gui->reset_game_list();
|
||||
g_steam->refresh_owned_apps();
|
||||
|
||||
for(Game_t app : g_steam->get_all_games_with_stats()) {
|
||||
for(Game_t app : g_steam->get_subscribed_apps()) {
|
||||
g_main_gui->add_to_game_list(app);
|
||||
}
|
||||
|
||||
g_steam->refresh_icons();
|
||||
g_main_gui->confirm_game_list();
|
||||
|
||||
g_perfmon->log("Library parsed.");
|
||||
|
||||
}
|
||||
// => on_ask_game_refresh
|
||||
|
||||
|
||||
void
|
||||
on_main_window_show() {
|
||||
on_ask_game_refresh(); //Run this async?
|
||||
on_ask_game_refresh();
|
||||
}
|
||||
// => on_main_window_show
|
||||
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@
|
|||
#include "globals.h"
|
||||
#include "cli_funcs.h"
|
||||
#include "common/functions.h"
|
||||
#include "common/PerfMon.h"
|
||||
|
||||
/**************************************
|
||||
* Declare global variables imported from globals.h
|
||||
|
|
@ -20,6 +21,7 @@ MySteam* g_steam = nullptr;
|
|||
MainPickerWindow* g_main_gui = nullptr;
|
||||
char* g_cache_folder = nullptr;
|
||||
MySteamClient* g_steamclient = nullptr;
|
||||
PerfMon* g_perfmon = nullptr;
|
||||
|
||||
|
||||
/**************************************
|
||||
|
|
@ -34,20 +36,21 @@ main(int argc, char *argv[])
|
|||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
g_perfmon = new PerfMon();
|
||||
gtk_init(&argc, &argv);
|
||||
|
||||
g_steamclient = new MySteamClient();
|
||||
g_cache_folder = concat( getenv("HOME"), "/.SamRewritten" );
|
||||
g_steam = MySteam::get_instance();
|
||||
g_main_gui = new MainPickerWindow();
|
||||
g_perfmon->log("Globals initialized.");
|
||||
|
||||
// Check for command-line options, which may prevent showing the GUI
|
||||
// Note that a rewriting should be done to further separate the GUI
|
||||
// from a command-line interface
|
||||
if(!go_cli_mode(argc, argv)) {
|
||||
gtk_widget_show( g_main_gui->get_main_window() );
|
||||
gtk_main();
|
||||
g_main_gui->show();
|
||||
}
|
||||
|
||||
return 0;
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user