forked from foss42/apidash
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request foss42#464 from foss42/dev-workspace
Users can select the persistent data location
- Loading branch information
Showing
19 changed files
with
478 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,82 @@ | ||
import 'package:apidash/providers/settings_providers.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_riverpod/flutter_riverpod.dart'; | ||
import 'package:google_fonts/google_fonts.dart'; | ||
import 'models/models.dart'; | ||
import 'providers/providers.dart'; | ||
import 'services/services.dart'; | ||
import 'consts.dart' show kIsLinux, kIsMacOS, kIsWindows; | ||
import 'consts.dart'; | ||
import 'app.dart'; | ||
|
||
void main() async { | ||
WidgetsFlutterBinding.ensureInitialized(); | ||
|
||
await initApp(); | ||
await initWindow(); | ||
var settingsModel = await getSettingsFromSharedPrefs(); | ||
final initStatus = await initApp( | ||
kIsDesktop, | ||
settingsModel: settingsModel, | ||
); | ||
if (kIsDesktop) { | ||
await initWindow(settingsModel: settingsModel); | ||
} | ||
if (!initStatus) { | ||
settingsModel = settingsModel?.copyWithPath(workspaceFolderPath: null); | ||
} | ||
|
||
runApp( | ||
const ProviderScope( | ||
child: DashApp(), | ||
ProviderScope( | ||
overrides: [ | ||
settingsProvider.overrideWith( | ||
(ref) => ThemeStateNotifier(settingsModel: settingsModel), | ||
) | ||
], | ||
child: const DashApp(), | ||
), | ||
); | ||
} | ||
|
||
Future<void> initApp() async { | ||
Future<bool> initApp( | ||
bool initializeUsingPath, { | ||
SettingsModel? settingsModel, | ||
}) async { | ||
GoogleFonts.config.allowRuntimeFetching = false; | ||
await openBoxes(); | ||
await autoClearHistory(); | ||
try { | ||
debugPrint("initializeUsingPath: $initializeUsingPath"); | ||
debugPrint("workspaceFolderPath: ${settingsModel?.workspaceFolderPath}"); | ||
final openBoxesStatus = await openBoxes( | ||
initializeUsingPath, | ||
settingsModel?.workspaceFolderPath, | ||
); | ||
debugPrint("openBoxesStatus: $openBoxesStatus"); | ||
if (openBoxesStatus) { | ||
await autoClearHistory(settingsModel: settingsModel); | ||
} | ||
return openBoxesStatus; | ||
} catch (e) { | ||
debugPrint("initApp failed due to $e"); | ||
return false; | ||
} | ||
} | ||
|
||
Future<void> initWindow({Size? sz}) async { | ||
Future<void> initWindow({ | ||
Size? sz, | ||
SettingsModel? settingsModel, | ||
}) async { | ||
if (kIsLinux) { | ||
await setupInitialWindow(sz: sz); | ||
await setupInitialWindow( | ||
sz: sz ?? settingsModel?.size, | ||
); | ||
} | ||
if (kIsMacOS || kIsWindows) { | ||
var win = sz != null ? (sz, const Offset(100, 100)) : getInitialSize(); | ||
await setupWindow(sz: win.$1, off: win.$2); | ||
if (sz != null) { | ||
await setupWindow( | ||
sz: sz, | ||
off: const Offset(100, 100), | ||
); | ||
} else { | ||
await setupWindow( | ||
sz: settingsModel?.size, | ||
off: settingsModel?.offset, | ||
); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.