Skip to content
This repository has been archived by the owner on Dec 1, 2024. It is now read-only.

Commit

Permalink
fix: fix multi window not work
Browse files Browse the repository at this point in the history
  • Loading branch information
ppvan committed May 17, 2024
1 parent e54bcfc commit 8173464
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 7 deletions.
16 changes: 10 additions & 6 deletions src/application.vala
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public class Application : Adw.Application {

public static List <uint> tasks;
public static bool is_running = false;
public static Settings settings;

public Application() {
Object(application_id: Config.APP_ID, flags: ApplicationFlags.DEFAULT_FLAGS);
Expand Down Expand Up @@ -102,14 +103,10 @@ public class Application : Adw.Application {
GtkSource.init();
set_up_logging();

var settings = new Settings(this.application_id);
Application.settings = new Settings(this.application_id);
settings.bind("color-scheme", this, "color_scheme", SettingsBindFlags.GET);
this.notify["color-scheme"].connect(update_color_scheme);

var container = Container.instance();
container.register(settings);
container.register(this);

Application.tasks = new List <uint> ();
Application.is_running = true;

Expand Down Expand Up @@ -235,7 +232,9 @@ public class Application : Adw.Application {
* This result to another event to notify window is ready and widget should setup signals
*/
private Window new_window() {
// give temp access because window is not created yet
// Clone all singleton instances for each window
Container.clone();
EventBus.clone();
create_viewmodels();
var window = new Window(this);

Expand All @@ -249,6 +248,11 @@ public class Application : Adw.Application {

var db_file = File.new_for_path(Path.build_filename(app_data_dir, "database.sqlite3"));

// global things
container.register(this);
container.register(Application.settings);


// services
var storage_service = new StorageService(db_file.get_path());
container.register(storage_service);
Expand Down
16 changes: 15 additions & 1 deletion src/services/Container.vala
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@ public class Container : Object {
private HashTable <GLib.Type, Object> dependencies;
private static Container ?_instance;


private static Vec <Container> protypes { get; private set; }

static construct {
Container._protypes = new Vec<Container>();
}

public static Container instance() {
if (_instance == null)
{
Expand All @@ -12,8 +19,15 @@ public class Container : Object {
return(_instance);
}

public static void clone() {
if (_instance != null) {
Container._protypes.append(_instance);
}
_instance = new Container();
}

/** Manual dependency injection map */
public Container() {
private Container() {
Object();
dependencies = new HashTable <GLib.Type, Object> (direct_hash, direct_equal);
}
Expand Down
14 changes: 14 additions & 0 deletions src/utils/Event.vala
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ public class EventBus : Object {
public signal void selected_view_changed(View view);
public signal void schema_reload();

private static Vec <EventBus> protypes { get; private set;}

static construct {
EventBus._protypes = new Vec <EventBus> ();
}

private static EventBus _instance;
public static EventBus instance() {
if (EventBus._instance == null)
Expand All @@ -17,6 +23,14 @@ public class EventBus : Object {
return(_instance);
}

public static void clone() {
if (_instance != null) {
_protypes.append(_instance);
}

_instance = new EventBus();
}

private EventBus() {
}
}
Expand Down

0 comments on commit 8173464

Please sign in to comment.