示例#1
0
        public App()
        {
            Exception exLog = Logger.CreateLog("AirPodsUI Settings");

            if (exLog != null)
            {
                MessageBox.Show("Unable to create logging component. Logging will be unavailable.\n\n" + exLog.Message, "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
            }

            Logger.Log(LogType.Information, "Created logger!");

            try
            {
                NavPages = new Dictionary <string, Type>();
                Devices  = new List <Device>();
                Devices  = DevicesJson.GetDevices();
                OnDevicesChanged?.Invoke(this, new EventArgs());
            }
            catch (Exception e)
            {
                Logger.Log(LogType.Error, "Unable to get devices!", e);
                MessageBox.Show("There was an error trying to get the devices. Please see the log for more details. Shutting down.\n\n" + Logger.LogFile, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                Shutdown();
            }
        }
示例#2
0
        public void Setup()
        {
            try
            {
                devices = DevicesJson.GetDevices();

                if (devices.Count <= 0)
                {
                    MessageBox.Show("There are no devices added, please run the configurator to add devices.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    Environment.Exit(-1);
                }

                Settings settings = new Settings();

                lastTick = PNP.GetPNPDevices();

                timer  = new System.Threading.Timer(OnTick, null, 0, settings.RefreshRate);
                offset = settings.Offset;

                settings.Dispose();

                TrayService.Visible = true;
            }
            catch (Exception e)
            {
                Logger.Log("An error occured trying to setup the tray service", e);
                MessageBox.Show("An error occured trying to setup the tray service", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
示例#3
0
        private async void OnAddClick(object sender, RoutedEventArgs e)
        {
            try
            {
                foreach (var i in App.Devices)
                {
                    if (i.Identifier == sID.Text)
                    {
                        Logger.Log(LogType.Warning, $"Unable to add device \"{i.Name}\" with ID \"{i.Identifier}\" because it already exists");
                        await Dialog.ShowDialogAsync("Warning", $"A device with the name \"{i.Name}\" already exists with the same ID!", "OK");

                        return;
                    }
                }

                ContentDialogResult result = await Dialog.ShowDialogAsync(
                    "Add Device",
                    $"Are you sure you want to add the following device?\n\nName: {sName.Text}\n\nID: {sID.Text}",
                    "No",
                    "Yes");

                if (result == ContentDialogResult.Primary)
                {
                    try
                    {
                        Logger.Log(LogType.Information, $"Attempting to add device \"{sName.Text}\" with ID \"{sID.Text}\"");
                        Device dev = new Device
                        {
                            DarkMode   = true,
                            Identifier = sID.Text,
                            Name       = sName.Text,
                            ToastType  = Toast.Pencil
                        };

                        App.Devices.Add(dev);
                        DevicesJson.SaveDevices(App.Devices);

                        App.InvokeDeviceChange(this);

                        Logger.Log(LogType.Information, $"Successfully saved device \"{sName.Text}\" with ID \"{sID.Text}\"");
                        await Dialog.ShowDialogAsync("Success", $"Device \"{sName.Text}\" added successfully!", "OK");
                    }
                    catch (Exception ex)
                    {
                        Logger.Log(LogType.Warning, $"Was unable to add device \"{sName.Text}\" with ID \"{sID.Text}\"", ex);
                        await Dialog.ShowDialogAsync("Error", $"Unable to add device \"{sName.Text}\"", "OK");
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Log(LogType.Warning, $"Was unable to add device \"{sName.Text}\" with ID \"{sID.Text}\" because an unknown error occured", ex);
                await Dialog.ShowDialogAsync("Error", "An unknown error occured trying to add the device", "OK");
            }
        }
示例#4
0
        public void Refresh()
        {
            busy    = true;
            devices = DevicesJson.GetDevices();
            if (devices.Count <= 0)
            {
                MessageBox.Show("There are no devices added, please run the configurator to add devices.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Environment.Exit(-1);
            }

            Settings settings = new Settings();

            lastTick = PNP.GetPNPDevices();

            offset = settings.Offset;

            settings.Dispose();
            busy = false;
        }
示例#5
0
        private void OnDeleteClicked(object sender, RoutedEventArgs e)
        {
            Logger.Log("Deleting current device");

            try
            {
                sDeleteFlyout.Hide();

                App.Devices.Remove(selectedDevice);
                DevicesJson.SaveDevices(App.Devices);

                App.InvokeDeviceChange(this);

                this.NavigationService.Navigate(null);
            }
            catch (Exception ex)
            {
                Logger.Log("Unable to delete device/an error occured deleting the device", ex);
            }
        }
示例#6
0
        private async void OnApplyClicked(object sender, RoutedEventArgs e)
        {
            selectedDevice.Name       = sName.Text;
            selectedDevice.Identifier = sID.Text;

            Logger.Log(LogType.Information, "Saving device information");

            try
            {
                int index = App.Devices.FindIndex((e) =>
                {
                    return(e == selectedDevice);
                });

                if (index < 0)
                {
                    await Dialog.ShowDialogAsync("Error", "Unable to save changes!", "OK");
                }
                else
                {
                    if (sToastType.SelectedIndex != 0)
                    {
                        await Dialog.ShowDialogAsync("Notice", "More toast types are coming soon!", "Great!");

                        return;
                    }

                    App.Devices[index].Name       = sName.Text;
                    sNameTitle.Content            = sName.Text;
                    App.Devices[index].Identifier = sID.Text;
                    App.Devices[index].DarkMode   = sDarkMode.IsOn;
                    DevicesJson.SaveDevices(App.Devices);
                    App.InvokeDeviceChange(this);
                    await Dialog.ShowDialogAsync("Success", "Successfully applied changed to device!", "OK");
                }
            }
            catch (Exception ex)
            {
                Logger.Log("Unable to save device changes", ex);
            }
        }
示例#7
0
        private void OnDoneClicked(object sender, RoutedEventArgs e)
        {
            try
            {
                Device dev = new Device
                {
                    DarkMode   = true,
                    Identifier = sID.Text,
                    Name       = sName.Text,
                    ToastType  = Toast.Pencil
                };

                App.Devices.Add(dev);
                DevicesJson.SaveDevices(App.Devices);
                App.InvokeDeviceChange(this);
            }
            catch (Exception ex)
            {
                Logger.Log("Unable to save the device from the pairing wizard", ex);
            }

            Window.GetWindow(this).Close();
        }