Skip to content

Commit 2299b45

Browse files
committed
ensure tor singleton
1 parent b97aad3 commit 2299b45

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

tool/wl_templates/TOR_tor_service_impl.template.dart

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,15 @@ FusionTorService _getFusionInterface() => throw Exception("TOR not enabled!");
2121

2222
//END_OFF
2323
//ON
24-
TorService _getInterface() => _TorServiceImpl();
25-
FusionTorService _getFusionInterface() => _FusionTorServiceImpl();
24+
TorService _getInterface() => _TorServiceImpl.instance;
25+
FusionTorService _getFusionInterface() => _FusionTorServiceImpl.instance;
2626

2727
class _TorServiceImpl extends TorService {
28+
static _TorServiceImpl? _instance;
29+
static _TorServiceImpl get instance => _instance ??= _TorServiceImpl._();
30+
31+
_TorServiceImpl._();
32+
2833
Tor? _tor;
2934
String? _torDataDirPath;
3035
TorConnectionStatus _status = TorConnectionStatus.disconnected;
@@ -131,6 +136,12 @@ class _TorServiceImpl extends TorService {
131136
}
132137

133138
class _FusionTorServiceImpl extends FusionTorService {
139+
static _FusionTorServiceImpl? _instance;
140+
static _FusionTorServiceImpl get instance =>
141+
_instance ??= _FusionTorServiceImpl._();
142+
143+
_FusionTorServiceImpl._();
144+
134145
Tor? _tor;
135146
String? _torDataDirPath;
136147

0 commit comments

Comments
 (0)