Skip to content

Commit 210e7bb

Browse files
committed
feat: Re-add system notification support
1 parent f9a157f commit 210e7bb

File tree

3 files changed

+52
-2
lines changed

3 files changed

+52
-2
lines changed

src/Utilities/System.luau

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
local process = require("@lune/process")
2+
3+
local Logging = require("Logging")
4+
5+
local System = {}
6+
7+
--[=[
8+
Sends a notification using notify-send.
9+
Currently uses notify-send (again) due to limitations with Lune that should be lifted with FFI support.
10+
11+
@param title string -- The notification's title.
12+
@param message string -- The notification's message.
13+
@param urgency string -- The notification's urgency. Default : nil
14+
@param transient boolean -- Whether the notification should be transient. Default : false
15+
@param time number -- The notification's time. Default : nil
16+
@return nil
17+
]=]
18+
function System.sendNotification(title: string, message: string, urgency: ("normal" | "critical")?, transient: boolean?, time: number?)
19+
local arguments = {
20+
title,
21+
message,
22+
}
23+
if transient then
24+
table.insert(arguments, "-e")
25+
end
26+
27+
if urgency then
28+
table.insert(arguments, "-u")
29+
table.insert(arguments, urgency)
30+
end
31+
if time then
32+
table.insert(arguments, "-t")
33+
table.insert(arguments, tostring(time))
34+
end
35+
36+
local execution = process.spawn("notify-send", arguments)
37+
38+
if not execution.ok then
39+
Logging.write("error", "Unable to send notification : " .. execution.stderr)
40+
end
41+
end
42+
43+
return System

src/Utilities/init.luau

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ return {
22
Logging = require("./Logging"),
33
Filesystem = require("./Filesystem"),
44
Async = require("./Async"),
5+
System = require("./System"),
56
}

src/init.luau

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ local Application = {}
33
local fs = require("@lune/fs")
44
local process = require("@lune/process")
55

6+
local Utilities = require("./Utilities")
67
local metadata = require("./Metadata")
7-
local Filesystem = require("./Utilities").Filesystem
8-
local Logging = require("./Utilities").Logging
8+
local Filesystem = Utilities.Filesystem
9+
local Logging = Utilities.Logging
10+
local System = Utilities.System
911
local Steam = require("./Steam")
1012

1113
function Application.start()
@@ -43,19 +45,23 @@ function Application.start()
4345
local ok, steamConfig = pcall(Steam.Configuration.getSteamConfiguration)
4446
if not ok then
4547
Logging.write("error", "Failed to load Steam games.")
48+
System.sendNotification(metadata.name, "Failed to load Steam games.", "critical", true)
4649
process.exit(1)
4750
end
4851

4952
-- Load the game's data
5053
local gameData = steamConfig[launchedAppID]
5154
if not gameData then
5255
Logging.write("error", "No data found for game with AppID " .. launchedAppID .. ".")
56+
System.sendNotification(metadata.name, "No data found for game with AppID " .. launchedAppID .. ".", "critical", true)
5357
process.exit(1)
5458
end
5559

5660
Logging.write("success", 'Detected "' .. gameData.name .. '" (' .. gameData.appID .. ") !")
61+
System.sendNotification(metadata.name, "Detected " .. gameData.name .. ".", "normal", true)
5762
else
5863
Logging.write("info", "Launched without Steam.")
64+
System.sendNotification(metadata.name, "No graphical interface implemented yet.", "critical", true)
5965
error("No graphical interface implemented yet.")
6066
end
6167
end

0 commit comments

Comments
 (0)