/loggerouter/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/loggerouter/trunk

« back to all changes in this revision

Viewing changes to src/settings.vala

  • Committer: Gustav Hartvigsson
  • Date: 2025-06-04 14:25:01 UTC
  • Revision ID: gustav.hartvigsson@gmail.com-20250604142501-uhe0ukoxuwcku2bt
Fixed crash caused from missing config file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
  private static GLib.Once<LO.Settings?> instance;
26
26
 
27
27
  public bool? dark_theme;
 
28
  
 
29
  //TODO: Timer countdown setting.
 
30
 
 
31
  string to_string () {
 
32
    var builder = new StringBuilder ();
 
33
    builder.append_printf ("key_file: %px\n", key_file);
 
34
    builder.append_printf ("config_path: %s", config_path);
 
35
    builder.append_printf ("dark_theme: %s", dark_theme.to_string ());
 
36
    return builder.str;
 
37
  }
28
38
 
29
39
  public static unowned LO.Settings? get_instance () {
30
40
    return instance.once (() => {
35
45
  private Settings () {}
36
46
 
37
47
  public void load_settings (string config_path) {
 
48
    print ("path\n");
38
49
    key_file = new GLib.KeyFile ();
39
 
  this.config_path = config_path;
 
50
    this.config_path = config_path;
40
51
    parse_key_file ();
41
52
  }
42
53
 
43
54
  public void load_setting_from_xdg () {
 
55
    print ("xdg\n");
44
56
    key_file = new GLib.KeyFile ();
45
57
    this.config_path = LO_XDG_CONFIG_PATH;
 
58
    if (GLib.File.new_for_path (this.config_path).query_exists ()) {
 
59
      parse_key_file ();
 
60
    } else {
 
61
      stderr.printf ("Colud not find file: %s", this.config_path);
 
62
      this.dark_theme = false;
 
63
    }
46
64
  }
47
65
 
48
66
  private void parse_key_file ()
49
67
  requires (key_file != null) {
 
68
    print ("Hello!\n");
50
69
    try {
51
70
      key_file.load_from_file (this.config_path, GLib.KeyFileFlags.NONE);
52
71
    } catch (GLib.FileError e) {
53
72
      string message = @"ERROR: $(e.message)\n";
54
73
      stderr.printf (message);
 
74
      GLib.Process.exit (41);
55
75
    } catch (GLib.KeyFileError e) {
56
76
      string message = @"ERROR: $(e.message)\n";
57
77
      stderr.printf (message);
 
78
      GLib.Process.exit (42);
58
79
    }
59
80
 
60
81
    try {
61
82
      if( key_file.has_key (CONFIG_INI_NAMESPACE_MAIN, "DarkTheme") ) {
62
83
        this.dark_theme = key_file.get_boolean (CONFIG_INI_NAMESPACE_MAIN, "DarkTheme");
 
84
      } else {
 
85
        this.dark_theme = true;
63
86
      }
64
87
    } catch (GLib.KeyFileError e) {
65
88
      string message = @"ERROR: $(e.message)\n";
66
89
      stderr.printf (message);
 
90
      GLib.Process.exit (43);
67
91
    }
68
92
  }
69
93
}