void Unloaded(object sender, VisualTreeAttachmentEventArgs e) { lock (locker) { Timer?.Dispose(); Disposed = true; } }
static void Dispose() { if (!Initialized) { return; } lock (locker) { courier.Dispose(); Initialized = false; Presence.ClearPresence(); Presence.Dispose(); } }
public override void OnFrameworkInitializationCompleted() { if (!(ApplicationLifetime is IClassicDesktopStyleApplicationLifetime lifetime)) { throw new ApplicationException("Invalid ApplicationLifetime"); } if (Args.Length > 0 && Args[0] == "--update") { lifetime.MainWindow = new UpdateWindow(); } else { if (!DriverChecker.Run(out MessageWindow driverError)) { lifetime.MainWindow = driverError; base.OnFrameworkInitializationCompleted(); return; } if (!AbletonConnector.Connected) { lifetime.MainWindow = new MessageWindow( $"Another instance of Apollo Studio is currently running.\n\n" + "Please close other instances of Apollo Studio before launching Apollo Studio." ); base.OnFrameworkInitializationCompleted(); return; } Program.HadCrashed = Preferences.Crashed; Preferences.Crashed = true; if (Preferences.DiscordPresence) { Discord.Set(true); } MIDI.Start(); foreach (int i in Preferences.VirtualLaunchpads) { LaunchpadWindow.Create(MIDI.ConnectVirtual(i), null); MIDI.Update(); } Courier autosave = new Courier() { Interval = 180000 }; autosave.Elapsed += async(_, __) => { if (Preferences.Autosave && Program.Project != null && File.Exists(Program.Project.FilePath) && !Program.Project.Undo.Saved) { try { string dir = Path.Combine(Path.GetDirectoryName(Program.Project.FilePath), $"{Program.Project.FileName} Backups"); if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } await Program.Project.WriteFile( null, Path.Join(dir, $"{Program.Project.FileName} Autosave {DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss")}.approj"), false ); } catch {} } Preferences.Save(); }; autosave.Start(); lifetime.Exit += (_, __) => { autosave.Dispose(); MIDI.Stop(); Discord.Set(false); AbletonConnector.Dispose(); Preferences.Crashed = Program.HadCrashed; Preferences.Save(); }; lifetime.MainWindow = new SplashWindow(); base.OnFrameworkInitializationCompleted(); } }