mirror of
https://github.com/foss42/apidash.git
synced 2025-12-02 10:49:49 +08:00
Initializes JavaScript runtime during application startup. Executes user-defined pre-request scripts before sending API requests, allowing modification of request details like URL, headers, and body. Updates script execution environment for better scoping and uses synchronous evaluation.
86 lines
2.2 KiB
Dart
86 lines
2.2 KiB
Dart
import 'package:apidash/services/flutter_js_service.dart';
|
|
import 'package:apidash_design_system/apidash_design_system.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
import 'models/models.dart';
|
|
import 'providers/providers.dart';
|
|
import 'services/services.dart';
|
|
import 'consts.dart';
|
|
import 'app.dart';
|
|
|
|
void main() async {
|
|
WidgetsFlutterBinding.ensureInitialized();
|
|
var settingsModel = await getSettingsFromSharedPrefs();
|
|
var onboardingStatus = await getOnboardingStatusFromSharedPrefs();
|
|
initializeJsRuntime();
|
|
final initStatus = await initApp(
|
|
kIsDesktop,
|
|
settingsModel: settingsModel,
|
|
);
|
|
if (kIsDesktop) {
|
|
await initWindow(settingsModel: settingsModel);
|
|
}
|
|
if (!initStatus) {
|
|
settingsModel = settingsModel?.copyWithPath(workspaceFolderPath: null);
|
|
}
|
|
|
|
runApp(
|
|
ProviderScope(
|
|
overrides: [
|
|
settingsProvider.overrideWith(
|
|
(ref) => ThemeStateNotifier(settingsModel: settingsModel),
|
|
),
|
|
userOnboardedProvider.overrideWith((ref) => onboardingStatus),
|
|
],
|
|
child: const DashApp(),
|
|
),
|
|
);
|
|
}
|
|
|
|
Future<bool> initApp(
|
|
bool initializeUsingPath, {
|
|
SettingsModel? settingsModel,
|
|
}) async {
|
|
GoogleFonts.config.allowRuntimeFetching = false;
|
|
try {
|
|
debugPrint("initializeUsingPath: $initializeUsingPath");
|
|
debugPrint("workspaceFolderPath: ${settingsModel?.workspaceFolderPath}");
|
|
final openBoxesStatus = await initHiveBoxes(
|
|
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,
|
|
SettingsModel? settingsModel,
|
|
}) async {
|
|
if (kIsLinux) {
|
|
await setupInitialWindow(
|
|
sz: sz ?? settingsModel?.size,
|
|
);
|
|
}
|
|
if (kIsMacOS || kIsWindows) {
|
|
if (sz != null) {
|
|
await setupWindow(
|
|
sz: sz,
|
|
off: const Offset(100, 100),
|
|
);
|
|
} else {
|
|
await setupWindow(
|
|
sz: settingsModel?.size,
|
|
off: settingsModel?.offset,
|
|
);
|
|
}
|
|
}
|
|
}
|