Skip to content

Commit 68e77aa

Browse files
committed
Fix thread cancel crash
1 parent 2a1102f commit 68e77aa

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

plugin/src/App/Components/Notifications/FullscreenNotification.lua

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,15 @@ local FullscreenNotification = Roact.Component:extend("FullscreeFullscreenNotifi
1919
function FullscreenNotification:init()
2020
self.transparency, self.setTransparency = Roact.createBinding(0)
2121
self.lifetime = self.props.timeout
22+
self.dismissed = false
2223
end
2324

2425
function FullscreenNotification:dismiss()
26+
if self.dismissed then
27+
return
28+
end
29+
self.dismissed = true
30+
2531
if self.props.onClose then
2632
self.props.onClose()
2733
end
@@ -59,8 +65,9 @@ function FullscreenNotification:didMount()
5965
end
6066

6167
function FullscreenNotification:willUnmount()
62-
if self.timeout and coroutine.status(self.timeout) ~= "dead" then
68+
if self.timeout and coroutine.status(self.timeout) == "suspended" then
6369
task.cancel(self.timeout)
70+
self.timeout = nil
6471
end
6572
end
6673

plugin/src/App/Components/Notifications/Notification.lua

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ function Notification:init()
2525
self.binding = bindingUtil.fromMotor(self.motor)
2626

2727
self.lifetime = self.props.timeout
28+
self.dismissed = false
2829

2930
self.motor:onStep(function(value)
3031
if value <= 0 and self.props.onClose then
@@ -34,6 +35,11 @@ function Notification:init()
3435
end
3536

3637
function Notification:dismiss()
38+
if self.dismissed then
39+
return
40+
end
41+
self.dismissed = true
42+
3743
self.motor:setGoal(Flipper.Spring.new(0, {
3844
frequency = 5,
3945
dampingRatio = 1,
@@ -75,8 +81,9 @@ function Notification:didMount()
7581
end
7682

7783
function Notification:willUnmount()
78-
if self.timeout and coroutine.status(self.timeout) ~= "dead" then
84+
if self.timeout and coroutine.status(self.timeout) == "suspended" then
7985
task.cancel(self.timeout)
86+
self.timeout = nil
8087
end
8188
end
8289

0 commit comments

Comments
 (0)