public override async Task <IWorkbook> ConfigureAsync(Frame rootFrame) { if (rootFrame == null) { throw new ArgumentNullException(nameof(rootFrame)); } bool sendAnalytics = WinSettings.Instance.GetValue <bool>(CoreSettings.SendAnalytics); string deviceId = "n/a"; try { var settings = WinSettings.Instance; if (!settings.HasValue(CoreSettings.DeviceId) || settings.GetValue <string>(CoreSettings.DeviceId) == "N/A") { string id = this.ComputeDeviceId(); settings.SetValue(CoreSettings.DeviceId, id); } deviceId = settings.GetValue <string>(CoreSettings.DeviceId); } catch (Exception ex) { TrackingManagerHelper.Exception(ex, "Error while setting device id"); } var platformService = new PlatformService(this.version, deviceId, () => CrashHandler.GetDiagnosticsInformation()); Ioc.RegisterInstance <IPlatformService, PlatformService>(platformService); TrackingManager trackingManager = new TrackingManager(sendAnalytics, platformService.DeviceFamily); Ioc.RegisterInstance <ITrackingManager, TrackingManager>(trackingManager); HttpClientHandler.Setup(); ResourcesLocator.Initialize("ms-appx://", UriKind.Absolute); if (!WinSettings.Instance.GetValue <bool>(CoreSettings.UseDarkTheme)) { ResourcesLocator.UpdateTheme(true); } var persistence = Ioc.RegisterInstance <IPersistenceLayer, WinPersistenceLayer>(new WinPersistenceLayer(automaticSave: true)); LogService.Log("Bootstraper", string.Format("Version: {0}", ApplicationVersion.GetAppVersion())); var navigationService = new NavigationService(rootFrame, platformService); Ioc.RegisterInstance <INavigationService, NavigationService>(navigationService); var messageBoxService = new MessageBoxService(navigationService); Ioc.RegisterInstance <IMessageBoxService, MessageBoxService>(messageBoxService); Ioc.RegisterInstance <ISpeechService, SpeechService>(new SpeechService(messageBoxService)); var workbook = this.InitializeWorkbook(persistence, platformService); // we just read the latest value of data from the DB, so even if there was a background sync // we now have the latest version, so we remove the background sync flag here workbook.Settings.SetValue(CoreSettings.SyncBackgroundOccured, false); this.keyboardShortcutManager = new KeyboardShortcutManager(workbook, rootFrame, navigationService, trackingManager); var backgroundTaskManager = new BackgroundTaskManager(workbook); backgroundTaskManager.InitializeAsync(); Ioc.RegisterInstance <IBackgroundTaskManager, BackgroundTaskManager>(backgroundTaskManager); var notificationService = new NotificationService(); Ioc.RegisterInstance <INotificationService, NotificationService>(notificationService); var startupManager = Ioc.Build <StartupManager>(); Ioc.RegisterInstance <IStartupManager, StartupManager>(startupManager); Ioc.RegisterInstance <IAlarmManager, AlarmManager>(new AlarmManager(workbook)); var tileManager = new TileManager(workbook, trackingManager, notificationService, false); tileManager.LoadSecondaryTilesAsync(); Ioc.RegisterInstance <ITileManager, TileManager>(tileManager); var synchronizationManager = await InitializeSyncAsync(workbook, platformService, trackingManager); // it is important to remove old task after sync is initialized otherwise changes would not // tracked and put in the changelog for the next sync workbook.RemoveOldTasks(); var cortanaService = new CortanaRuntimeService(workbook); // no need to await this call because it can runs in the background Task.Run(() => { JumpListManager.SetupJumpListAsync(); cortanaService.SetupDefinitionsAsync(); }); Ioc.RegisterInstance <ICortanaRuntimeService, CortanaRuntimeService>(cortanaService); return(workbook); }
public static void TryHandleArgs(object args) { try { if (!Ioc.HasType <IWorkbook>() || !Ioc.HasType <ITileManager>() || !Ioc.HasType <INavigationService>()) { return; } var workbook = Ioc.Resolve <IWorkbook>(); var platformService = Ioc.Resolve <IPlatformService>(); var navigationService = Ioc.Resolve <INavigationService>(); Frame rootFrame = Window.Current.Content as Frame; MainPage mainPage = null; MainPageViewModel viewModel = null; if (rootFrame != null && rootFrame.Content is MainPage) { mainPage = (MainPage)rootFrame.Content; } if (mainPage != null && mainPage.DataContext is MainPageViewModel) { viewModel = (MainPageViewModel)mainPage.DataContext; } string arguments = args as string; if (args is IActivatedEventArgs) { var activatedEventArgs = (IActivatedEventArgs)args; if (activatedEventArgs.Kind == ActivationKind.VoiceCommand) { var cortanaService = new CortanaRuntimeService(workbook); cortanaService.TryHandleActivation(new CortanaRuntimeAction(), activatedEventArgs); return; } } if (arguments == LaunchArgumentsHelper.QuickAddTask) { navigationService.FlyoutTo(typeof(TaskPage), null); return; } if (args is ToastNotificationActivatedEventArgs) { arguments = ((ToastNotificationActivatedEventArgs)args).Argument; if (!string.IsNullOrWhiteSpace(arguments) && arguments.ToLowerInvariant().StartsWith("http")) { platformService.OpenWebUri(arguments); } } var descriptor = LaunchArgumentsHelper.GetDescriptorFromArgument(workbook, arguments); if (descriptor.Task != null && descriptor.Type == LaunchArgumentType.EditTask) { navigationService.FlyoutTo(typeof(TaskPage), descriptor.Task); } else if (descriptor.Folder != null && descriptor.Type == LaunchArgumentType.Select && viewModel != null) { if (descriptor.Folder is IFolder) { SelectMenuItem <IFolder>(viewModel, descriptor.Folder.Id); } else if (descriptor.Folder is ITag) { SelectMenuItem <ITag>(viewModel, descriptor.Folder.Id); } else if (descriptor.Folder is ISmartView) { SelectMenuItem <ISmartView>(viewModel, descriptor.Folder.Id); } else if (descriptor.Folder is IView) { SelectMenuItem <IView>(viewModel, descriptor.Folder.Id); } else if (descriptor.Folder is IContext) { SelectMenuItem <IContext>(viewModel, descriptor.Folder.Id); } } else if (descriptor.Type == LaunchArgumentType.Sync && viewModel != null) { viewModel.SyncCommand.Execute(null); } } catch (Exception ex) { TrackingManagerHelper.Exception(ex, string.Format("LauncherHelper.TryHandleArgs: {0} {1}", args, ex)); } }