init<K extends SessionStatusInfo> method
Initialize the state of the renovation instance
Implementation
Future<void> init<K extends SessionStatusInfo>(
String hostUrl, {
RenovationBackend backend = RenovationBackend.frappe,
String? clientId,
K? sessionStatusInfo,
bool useJWT = false,
bool isBenchEnabled = false,
bool disableLog = false,
Logger? customLogger,
/// Cookie JAR options
String? cookieDir,
bool persistSession = true,
bool ignoreExpires = false,
}) async {
final logger = customLogger ??
Logger(
filter: DebugFilter(disableLog: disableLog),
printer: PrettyPrinter(colors: true, methodCount: 0),
);
final startTime = DateTime.now();
if (clientId != null) {
Request.setClientId(clientId);
}
config = RenovationConfig(this, backend, hostUrl, logger);
RenovationConfig.renovationInstance = config;
socketIo = SocketIOClient(config);
if (backend == RenovationBackend.frappe) {
RenovationRequestOptions.headers = <String, String?>{
'Accept': 'application/json',
'X-Requested-With': 'XMLHttpRequest'
};
frappe = Frappe(config);
translate = FrappeTranslationController(config);
model = FrappeModelController(config);
meta = FrappeMetaController(config);
perm = FrappePermissionController(config);
storage = FrappeStorageController(config);
defaults = FrappeDefaultsController(config);
log = FrappeLogManager(config);
auth = FrappeAuthController(
config,
sessionStatusInfo: sessionStatusInfo as FrappeSessionStatusInfo?,
);
// Manage sessions using cookies instead of JWT
if (!useJWT) {
if (cookieDir != null) {
Request.setupPersistentCookie(
PersistCookieJar(
storage: FileStorage(cookieDir),
ignoreExpires: ignoreExpires,
persistSession: persistSession),
);
} else {
throw CookieDirNotSet();
}
} else {
getFrappeAuthController().enableJWT();
}
// unawaited(frappe.loadAppVersions());
// TODO:
// dashboard = FrappeDashboardController(config);
}
if (isBenchEnabled && clientId == null) {
await frappe.updateClientId();
}
logger.v(
'Renovation Core Took ${DateTime.now().difference(startTime).inMilliseconds.toString()}ms to initialize');
}