diff options
author | Aylur <[email protected]> | 2024-10-14 09:39:32 +0000 |
---|---|---|
committer | Aylur <[email protected]> | 2024-10-14 09:39:48 +0000 |
commit | f8745db77f62c743496a6b22211a4ac1ca7c86e3 (patch) | |
tree | dcd48137279ee98853ccb738fee53cd45f03df61 /lib | |
parent | 25528b00006745b4def7d2f61cc910592b4b3ae9 (diff) |
lib(hyprland): check if conn and strea is not null
Diffstat (limited to 'lib')
-rw-r--r-- | lib/hyprland/hyprland.vala | 36 |
1 files changed, 17 insertions, 19 deletions
diff --git a/lib/hyprland/hyprland.vala b/lib/hyprland/hyprland.vala index 8834ea2..ea95cab 100644 --- a/lib/hyprland/hyprland.vala +++ b/lib/hyprland/hyprland.vala @@ -161,42 +161,40 @@ public class Hyprland : Object { if (conn != null) { conn.output_stream.write(message.data, null); stream = new DataInputStream(conn.input_stream); + } else { + stream = null; + critical("could not write to the Hyprland socket"); } } public string message(string message) { - SocketConnection conn; - DataInputStream stream; + SocketConnection? conn; + DataInputStream? stream; try { write_socket(message, out conn, out stream); - return stream.read_upto("\x04", -1, null, null); + if (stream != null && conn != null) { + var res = stream.read_upto("\x04", -1, null, null); + conn.close(null); + return res; + } } catch (Error err) { critical(err.message); - } finally { - try { - if (conn != null) - conn.close(null); - } catch (Error err) { - critical(err.message); - } } return ""; } public async string message_async(string message) { - SocketConnection conn; - DataInputStream stream; + SocketConnection? conn; + DataInputStream? stream; try { write_socket(message, out conn, out stream); - return yield stream.read_upto_async("\x04", -1, Priority.DEFAULT, null, null); - } catch (Error err) { - critical(err.message); - } finally { - try { + if (stream != null && conn != null) { + var res = yield stream.read_upto_async("\x04", -1, Priority.DEFAULT, null, null); conn.close(null); - } catch (Error err) { - critical(err.message); + return res; } + } catch (Error err) { + critical(err.message); } return ""; } |