File tree Expand file tree Collapse file tree 1 file changed +25
-2
lines changed
Expand file tree Collapse file tree 1 file changed +25
-2
lines changed Original file line number Diff line number Diff line change @@ -178,8 +178,31 @@ void main(List<String> args) async {
178178 (await StackFileSystem .applicationHiveDirectory ()).path,
179179 );
180180
181- await DB .instance.hive.openBox <dynamic >(DB .boxNameDBInfo);
182- await DB .instance.hive.openBox <dynamic >(DB .boxNamePrefs);
181+ try {
182+ await DB .instance.hive.openBox <dynamic >(DB .boxNameDBInfo);
183+ await DB .instance.hive.openBox <dynamic >(DB .boxNamePrefs);
184+ } on FileSystemException catch (e) {
185+ if (e.osError? .errorCode == 11 || e.message.contains ('lock failed' )) {
186+ // Another instance of the app already holds the Hive database lock.
187+ // Show a simple error screen rather than crashing to a black screen.
188+ runApp (
189+ MaterialApp (
190+ debugShowCheckedModeBanner: false ,
191+ home: Scaffold (
192+ body: Center (
193+ child: Text (
194+ '${AppConfig .appName } is already running.\n '
195+ 'Close the other window and try again.' ,
196+ textAlign: TextAlign .center,
197+ ),
198+ ),
199+ ),
200+ ),
201+ );
202+ return ;
203+ }
204+ rethrow ;
205+ }
183206 await Prefs .instance.init ();
184207
185208 await Logging .instance.initialize (
You can’t perform that action at this time.
0 commit comments