/// <summary> /// Load an app package with the given name, stored on the device. /// This is a shorthand on calling yourself <see cref="RegisterAppStreamResolver"/> and <see cref="ReloadApplication"/> /// as the loading is managed by all the entries you get through <see cref="AddPackage(string, Stream)"/>, <see cref="RemovePackage(string)"/>, <see cref="ListPackages"/>. /// </summary> /// <param name="name">The package to load</param> /// <returns></returns> public static bool LoadPackage(string name) { if (string.IsNullOrEmpty(name)) { throw new NullReferenceException($"{nameof(name)} cannot be null"); } //TODO: Remove when ElectronNET is supported with a WASM behavior too if (BlazorDevice.IsElectronNET() && !BlazorDevice.IsUsingWASM()) { throw new NotImplementedException("This feature is not implemented on ElectronNET when the 'useWasm' option is set to false on UseBlazorMobileWithElectronNET method"); } var resolver = GetApplicationStoreService().GetPackageStreamResolver(name); if (resolver == null) { ConsoleHelper.WriteError($"{nameof(WebApplicationFactory)}.{nameof(LoadPackage)}: package '{name}' not found"); return(false); } _currentLoadedApplicationStorePackage = name; RegisterAppStreamResolver(resolver); ReloadApplication(); return(true); }
/// <summary> /// Set the delegate method to be executed when BlazorMobile finished loading /// </summary> /// <param name="onFinish"></param> public static void Init(Action <bool> onFinish = null) { if (!_isInit) { BlazorDevice.Init(onFinish); _isInit = true; } }
/// <summary> /// List available packages in the data store of the device /// </summary> /// <returns></returns> public static IEnumerable <string> ListPackages() { //TODO: Remove when ElectronNET is supported with a WASM behavior too if (BlazorDevice.IsElectronNET() && !BlazorDevice.IsUsingWASM()) { throw new NotImplementedException("This feature is not implemented on ElectronNET with 'useWasm' option set to false"); } return(GetApplicationStoreService().ListPackages()); }
/// <summary> /// Add the given Stream as a package in a data store on the device, with the given name /// </summary> /// <param name="name"></param> /// <param name="content"></param> public static bool AddPackage(string name, Stream content) { if (content == null) { throw new NullReferenceException($"{nameof(content)} cannot be null"); } //TODO: Remove when ElectronNET is supported with a WASM behavior too if (BlazorDevice.IsElectronNET() && !BlazorDevice.IsUsingWASM()) { throw new NotImplementedException("This feature is not implemented on ElectronNET with 'useWasm' option set to false"); } //Force position to Begin of the Stream content.Seek(0, SeekOrigin.Begin); return(GetApplicationStoreService().AddPackage(name, content)); }