return nil
case ":del", ":delete":
- profile_filename := strings.concatenate({ app.config.selected_profile.?, ".json" }, context.temp_allocator)
+ profile_filename := strings.concatenate({ app.config.?.selected_profile.?, ".json" }, context.temp_allocator)
profile_path := fpath.join({ app.profiles_path, profile_filename }, context.temp_allocator)
os.remove(profile_path)
room_name = room_name_bytes,
}
- err := request_host(app, request, &app.profile.private_key, nil)
+ err := request_host(app, request, &(&app.profile.?).private_key, nil)
if err != nil {
app_set_info_bar(app, "Could not subscribe to room.")
}
}
- err := request_host(app, request, &app.profile.private_key, callback)
+ err := request_host(app, request, &(&app.profile.?).private_key, callback)
if err != nil {
app_set_info_bar(app, "Could not subscribe to room.")
return nil
case ":k", ":key":
- selected_room := &app.profile.rooms[app.selected_room]
+ selected_room := &(&app.profile.?).rooms[app.selected_room]
key_string_buffer: [44]u8
key_string_builder := strings.builder_from_bytes(key_string_buffer[:])
return nil
}
- room := &app.profile.rooms[app.selected_room]
+ room := &(&app.profile.?).rooms[app.selected_room]
request := common.Unsubscribe_Request{
room_id = room_get_id(room),
}
- err := request_host(app, request, &app.profile.private_key, nil)
+ err := request_host(app, request, &(&app.profile.?).private_key, nil)
if err != nil {
app_set_info_bar(app, "Could not subscribe to room.")
return nil
case "hosts":
- app_set_info_bar(app, "%v", app.profile.hosts)
+ app_set_info_bar(app, "%v", app.profile.?.hosts)
return nil
- case:
- app_set_info_bar(app, "Invalid field name.")
- return .Invalid_Arguments
+ case "profile":
+ app_set_info_bar(app, "%v", app.config.?.selected_profile.?)
+ return nil
+ }
+ } else if len(args) == 2 {
+ value := args[1]
+
+ switch field_name {
+ case "seed_phrqse":
+ app_set_info_bar(app, "TODO")
+ return nil
+
+ case "hosts":
+ sync.mutex_lock(&app.data_mutex)
+ defer sync.mutex_unlock(&app.data_mutex)
+
+ profile_set_hosts(&app.profile.?, value)
+
+ return nil
+
+ case "profile":
+ sync.mutex_lock(&app.data_mutex)
+ defer sync.mutex_unlock(&app.data_mutex)
+
+ config_set_selected_profile(&app.config.?, value)
+ config_update(app.config.?, app)
+
+ // app_set_state(app, .Load_Config)
+
+ return nil
}
}
- return nil
+ app_set_info_bar(app, "Invalid field name.")
+ return .Invalid_Arguments
case ":q", ":quit":
app.running = false
return
}
}
+
+config_set_selected_profile :: proc(config: ^Config, selected_profile: string) {
+ delete(config.selected_profile.?)
+ config.selected_profile = strings.clone(selected_profile)
+}
info_bar_content: string,
- config: Config,
+ config: Maybe(Config),
profile_password: string,
- profile: Profile,
+ profile: Maybe(Profile),
seed_phrase_entropy: u128,
seed_phrase_checksum: u8,
net.close(host)
}
- profile_deinit(app.profile)
+ if profile, ok := app.profile.?; ok {
+ profile_deinit(profile)
+ }
if app.profile_password != "" {
delete(app.profile_password)
}
- config_deinit(app.config)
+ if config, ok := app.config.?; ok {
+ config_deinit(config)
+ }
if app.info_bar_content != "" {
delete(app.info_bar_content)
c_room_name_buffer: [common.ROOM_NAME_SIZE + 1]u8
- for &room, i in app.profile.rooms {
+ for &room, i in app.profile.?.rooms {
room_color := nc.COLOR_PAIR(3)
if i == app.selected_room {
app_room_key_exists :: proc(app: ^App, key: [common.ROOM_KEY_SIZE]u8) -> bool {
key := key
- for &room in app.profile.rooms {
+ for &room in app.profile.?.rooms {
if slice.equal(room.key[:], key[:]) {
return true
}
sync.mutex_lock(&app.data_mutex)
defer sync.mutex_unlock(&app.data_mutex)
- append(&app.profile.rooms, room)
- profile_update(app.profile, app)
+ append(&(&app.profile.?).rooms, room)
+ profile_update(app.profile.?, app)
}
app_update_room_list_window(app)
sync.mutex_lock(&app.data_mutex)
defer sync.mutex_unlock(&app.data_mutex)
- ordered_remove(&app.profile.rooms, index)
+ ordered_remove(&(&app.profile.?).rooms, index)
- if app.selected_room != 0 && app.selected_room >= len(app.profile.rooms) {
- app.selected_room = len(app.profile.rooms) - 1
+ if app.selected_room != 0 && app.selected_room >= len(app.profile.?.rooms) {
+ app.selected_room = len(app.profile.?.rooms) - 1
}
- profile_update(app.profile, app)
+ profile_update(app.profile.?, app)
}
app_update_room_list_window(app)
}
profile_update :: proc(profile: Profile, app: ^App) {
- profile_filename := strings.concatenate({ app.config.selected_profile.?, ".json" }, context.temp_allocator)
+ profile_filename := strings.concatenate({ app.config.?.selected_profile.?, ".json" }, context.temp_allocator)
profile_path := fpath.join({ app.profiles_path, profile_filename }, context.temp_allocator)
profile_file, err1 := os.open(profile_path, os.O_WRONLY | os.O_CREATE | os.O_TRUNC, 0o664)
return nil
}
+
+profile_set_hosts :: proc(profile: ^Profile, hosts: string) {
+ if len(profile.hosts) != 0 {
+ delete(profile.hosts)
+ }
+
+ profile.hosts, _ = strings.clone(hosts)
+}
sync.mutex_lock(&app.data_mutex)
defer sync.mutex_unlock(&app.data_mutex)
+ if config_, ok := app.config.?; ok {
+ config_deinit(config_)
+ }
+
app.config = config
}
}
state_load_profile :: proc(app: ^App) {
- selected_profile, ok := app.config.selected_profile.?
+ selected_profile, ok := app.config.?.selected_profile.?
if !ok {
app_set_state(app, .Ask_Profile)
sync.mutex_lock(&app.data_mutex)
defer sync.mutex_unlock(&app.data_mutex)
+ if profile, ok := app.profile.?; ok {
+ profile_deinit(profile)
+ }
+
app.profile = profile
}
sync.mutex_lock(&app.data_mutex)
defer sync.mutex_unlock(&app.data_mutex)
- app.config.selected_profile = input
+ (&app.config.?).selected_profile = input
}
- config_update(app.config, app)
+ config_update(app.config.?, app)
app_set_state(app, .Load_Profile)
}
return
}
- err2 := profile_set_private_key_from_seed_phrase(&app.profile, app, input)
+ err2 := profile_set_private_key_from_seed_phrase(&app.profile.?, app, input)
if err2 != nil {
log.errorf("Invalid seed phrase with error %v", err2)
sync.mutex_lock(&app.data_mutex)
defer sync.mutex_unlock(&app.data_mutex)
- app.profile.hosts = input
+ profile_set_hosts(&app.profile.?, input)
}
app_set_state(app, .Ask_Profile_Set_Password)
return
}
- profile_update(app.profile, app)
+ profile_update(app.profile.?, app)
app_set_state(app, .Connect_To_Host)
}
app_set_info_bar(app, "Connecting to host...")
maybe_host: Maybe(net.TCP_Socket)
- hosts := strings.clone(app.profile.hosts, context.temp_allocator)
+ hosts := strings.clone(app.profile.?.hosts, context.temp_allocator)
for host_address in strings.split_iterator(&hosts, " ") {
host_endpoint: net.Endpoint
return
}
- delete(app.profile.hosts)
- app.profile.hosts = input
-
- profile_update(app.profile, app)
+ profile_set_hosts(&app.profile.?, input)
+ profile_update(app.profile.?, app)
app_set_state(app, .Connect_To_Host)
}
}
case Event.down:
- if app.selected_room + 1 != len(app.profile.rooms) {
+ if app.selected_room + 1 != len(app.profile.?.rooms) {
app.selected_room += 1
app_update_room_list_window(app)
}
return
}
- selected_room := &app.profile.rooms[app.selected_room]
+ selected_room := &(&app.profile.?).rooms[app.selected_room]
iv: [chacha.IV_SIZE]u8
_ = rand.read(iv[:])
message = encrypted_message,
}
- err := request_host(app, request, &app.profile.private_key, nil)
+ err := request_host(app, request, &(&app.profile.?).private_key, nil)
if err != nil {
app_set_info_bar(app, "Failed to send message.")