Skip to content

Commit

Permalink
Add option to exit app when user disconnects from server
Browse files Browse the repository at this point in the history
Also update zig-discord to fix a memory leak
  • Loading branch information
Beyley committed Aug 20, 2023
1 parent 10595a7 commit e27fe50
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
4 changes: 2 additions & 2 deletions build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
.version = "0.0.0",
.dependencies = .{
.@"zig-discord" = .{
.url = "https://github.com/Beyley/zig-discord/archive/d5af305592f5712a0731554e2afd10afbea293cc.tar.gz",
.hash = "1220af3afee845035705462f357f7ca70b964787a94ff3ae39a6ee779f3cca452880",
.url = "https://github.com/Beyley/zig-discord/archive/535bbf730616887e48d7f36c01a04a3bb1ecd81f.tar.gz",
.hash = "1220274bcea2b0b0e4429f56903c89f78caf6cf28082d8dc07778e84a0c3780b4db2",
},
.zBoxer = .{
.url = "https://github.com/Beyley/zBoxer/archive/8ba46a2fe50d658f1406c9681b8b931df24edf37.tar.gz",
Expand Down
15 changes: 9 additions & 6 deletions src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ const Rpc = @import("rpc");
const Lbp = @import("lbp.zig");

const Config = struct {
instance_url: []const u8,
username: []const u8,
instance_url: []const u8 = "https://refresh.jvyden.xyz/",
username: []const u8 = "Username",
close_upon_game_exit: bool = false,
pub fn deinit(self: Config, allocator: std.mem.Allocator) void {
allocator.free(self.instance_url);
allocator.free(self.username);
Expand All @@ -25,10 +26,7 @@ pub fn getConfig(allocator: std.mem.Allocator) !Config {

var file = cwd.openFile(config_path, .{}) catch |err| {
if (err == std.fs.File.OpenError.FileNotFound) {
const default_config = Config{
.username = "Username",
.instance_url = "https://refresh.jvyden.xyz",
};
const default_config = Config{};

var file = try cwd.createFile(config_path, .{});
defer file.close();
Expand Down Expand Up @@ -62,6 +60,7 @@ pub fn getConfig(allocator: std.mem.Allocator) !Config {
const config = Config{
.username = try allocator.dupe(u8, temp_config.value.username),
.instance_url = try allocator.dupe(u8, temp_config.value.instance_url),
.close_upon_game_exit = temp_config.value.close_upon_game_exit,
};

return config;
Expand Down Expand Up @@ -338,6 +337,10 @@ pub fn runApp(allocator: std.mem.Allocator) !void {
rpc_thread = null;
}

if (config.close_upon_game_exit) {
return;
}

//Sleep for 60s
std.time.sleep(std.time.ns_per_s * 60);
}
Expand Down

0 comments on commit e27fe50

Please sign in to comment.