initialize method

Future<bool> initialize()
override

Implementation

Future<bool> initialize() async
{
  // build stash
  stash = Scope(id: 'STASH');
  if (domain != null) _stash = await Stash.get(domain!);
  _stash.map.entries.forEach((entry) => stash.setObservable(entry.key, entry.value));

  // add SYSTEM scope
  this.scopeManager.add(System().scope!);

  // add THEME scope
  this.scopeManager.add(System.theme.scope!);

  // add STASH scope
  this.scopeManager.add(stash);

  // add USER scope
  this.scopeManager.add(_user.scope!);

  // add GLOBAL alias to this scope
  this.scopeManager.add(scope!, alias: "GLOBAL");

  // build config
  var config = await _getConfig(true);
  if (config != null) _config = config;

  // get global template
  // get global.xml
  if (domain != null)
  {
    var uri = Uri.tryParse(domain!)?.setPage("global.xml");
    XmlDocument? template;
    if (uri != null) template = await Template.fetchTemplate(url: uri.url, refresh: true);

    // deserialize the returned template
    if (template != null) this.deserialize(template.rootElement);
  }

  return true;
}