public MyCustomApplicationContext() { Application.ApplicationExit += OnApplicationExit; SystemEvents.PowerModeChanged += OnPowerChange; _wallcatService = new WallcatService(); _googleAnalytics = new GoogleAnalytics(); _contextMenu = new ContextMenu(); _trayIcon = new NotifyIcon { Icon = Resources.AppIcon, ContextMenu = _contextMenu, Visible = true }; using (var iconAnimation = new IconAnimation(ref _trayIcon)) { // Add Menu items var channels = _wallcatService.GetChannels().Result; _contextMenu.MenuItems.Add(new MenuItem("Featured Channels") { Enabled = false }); _contextMenu.MenuItems.AddRange(channels.Select(channel => new MenuItem(channel.title, SelectChannel) { Tag = channel, Checked = IsCurrentChannel(channel) }).ToArray()); _contextMenu.MenuItems.AddRange(new[] { new MenuItem("-") { Enabled = false }, new MenuItem("Create Channel...", (sender, args) => ChannelCreateWebpage()), new MenuItem("Start at login", (sender, args) => CreateStartupShortcut()) { Checked = IsEnabledAtStartup() }, new MenuItem("-") { Enabled = false }, new MenuItem("Quit Wallcat", (sender, args) => Application.Exit()) }); // Set Current Image Info if (Properties.Settings.Default.CurrentWallpaper != null) { UpdateMenuCurrentImage(Properties.Settings.Default.CurrentWallpaper); } // Onboarding if (Properties.Settings.Default.CurrentChannel == null) { var channel = channels.FirstOrDefault(x => x.isDefault); if (channel != null) { Properties.Settings.Default.CurrentChannel = channel; Properties.Settings.Default.Save(); _trayIcon.ShowBalloonTip(10 * 1000, "Welcome to Wallcat", $"Enjoy the {channel.title} channel!", ToolTipIcon.Info); } Properties.Settings.Default.UniqueIdentifier = Guid.NewGuid(); _googleAnalytics.SubmitEvent(GoogleAnalyticsCategory.system, GoogleAnalyticsAction.appInstalled).Wait(); } _googleAnalytics.SubmitEvent(GoogleAnalyticsCategory.system, GoogleAnalyticsAction.appLaunched).Wait(); UpdateWallpaper(); MidnightUpdate(); } }
private async void SelectChannel(object sender, EventArgs e) { using (var iconAnimation = new IconAnimation(ref _trayIcon)) { if (Properties.Settings.Default.CurrentChannel != null && e != null) { await _googleAnalytics.SubmitEvent(GoogleAnalyticsCategory.channel, GoogleAnalyticsAction.channelUnsubscribed, Properties.Settings.Default.CurrentChannel.title, new[] { new DimensionTuple(GoogleAnalyticsDimension.channelId, Properties.Settings.Default.CurrentChannel.id), new DimensionTuple(GoogleAnalyticsDimension.channelTitle, Properties.Settings.Default.CurrentChannel.title) }); } var channel = (Channel)((MenuItem)sender).Tag; var wallpaper = await _wallcatService.GetWallpaper(channel.id); if (wallpaper.id == Properties.Settings.Default.CurrentWallpaper?.id) { return; } var filePath = await DownloadFile.Get(wallpaper.url.o); if (Environment.OSVersion.Version.Major >= 8) { SetWallpaper.Apply(null, filePath, DesktopWallpaperPosition.Fill); } else { SetWallpaperLegacy.Apply(filePath, DesktopWallpaperPosition.Fill); } // Update Settings Properties.Settings.Default.CurrentChannel = channel; Properties.Settings.Default.CurrentWallpaper = wallpaper; Properties.Settings.Default.LastChecked = DateTime.Now.Date; Properties.Settings.Default.Save(); // Update Menu UpdateMenuCurrentImage(wallpaper); await _googleAnalytics.SubmitEvent(GoogleAnalyticsCategory.wallpaper, GoogleAnalyticsAction.wallpaperSet, wallpaper.id, new[] { new DimensionTuple(GoogleAnalyticsDimension.wallpaperId, wallpaper.id), new DimensionTuple(GoogleAnalyticsDimension.wallpaperTitle, wallpaper.title), new DimensionTuple(GoogleAnalyticsDimension.channelId, channel.id), new DimensionTuple(GoogleAnalyticsDimension.channelTitle, channel.title), new DimensionTuple(GoogleAnalyticsDimension.partnerId, wallpaper.partner.id), new DimensionTuple(GoogleAnalyticsDimension.partnerName, wallpaper.partner.name) }); if (e != null) { await _googleAnalytics.SubmitEvent(GoogleAnalyticsCategory.channel, GoogleAnalyticsAction.channelSubscribed, channel.title, new[] { new DimensionTuple(GoogleAnalyticsDimension.channelId, channel.id), new DimensionTuple(GoogleAnalyticsDimension.channelTitle, channel.title) }); } } }