Example #1
0
        static void SetupInit(IMauiContext context, InitializationOptions?maybeOptions = null)
        {
            MauiContext = context;

            Microsoft.Maui.Controls.Internals.Registrar.RegisterRendererToHandlerShim(RendererToHandlerShim.CreateShim);

            Application.AccentColor = Color.FromRgba(50, 79, 133, 255);

            if (!IsInitialized)
            {
                // Only need to do this once
                Log.Listeners.Add(new DelegateLogListener((c, m) => Trace.WriteLine(m, c)));
            }

#if __MOBILE__
            Device.SetIdiom(UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad ? TargetIdiom.Tablet : TargetIdiom.Phone);
            Device.SetFlowDirection(UIApplication.SharedApplication.UserInterfaceLayoutDirection.ToFlowDirection());
#else
            if (!IsInitialized)
            {
                // Only need to do this once
                // Subscribe to notifications in OS Theme changes
                NSDistributedNotificationCenter.GetDefaultCenter().AddObserver((NSString)"AppleInterfaceThemeChangedNotification", (n) =>
                {
                    var interfaceStyle = NSUserDefaults.StandardUserDefaults.StringForKey("AppleInterfaceStyle");

                    var aquaAppearance = NSAppearance.GetAppearance(interfaceStyle == "Dark" ? NSAppearance.NameDarkAqua : NSAppearance.NameAqua);
                    NSApplication.SharedApplication.Appearance = aquaAppearance;

                    Application.Current?.TriggerThemeChanged(new AppThemeChangedEventArgs(interfaceStyle == "Dark" ? OSAppTheme.Dark : OSAppTheme.Light));
                });
            }

            Device.SetIdiom(TargetIdiom.Desktop);
            Device.SetFlowDirection(NSApplication.SharedApplication.UserInterfaceLayoutDirection.ToFlowDirection());

            if (IsMojaveOrNewer)
            {
                var interfaceStyle = NSUserDefaults.StandardUserDefaults.StringForKey("AppleInterfaceStyle");
                var aquaAppearance = NSAppearance.GetAppearance(interfaceStyle == "Dark" ? NSAppearance.NameDarkAqua : NSAppearance.NameAqua);
                NSApplication.SharedApplication.Appearance = aquaAppearance;
            }
#endif
            Device.SetFlags(s_flags);
            var platformServices = new IOSPlatformServices();

            Device.PlatformServices = platformServices;

            // use field and not property to avoid exception in getter
            if (Device.info is IDisposable infoDisposable)
            {
                infoDisposable.Dispose();
                Device.info = null;
            }

#if __MOBILE__
            Device.PlatformInvalidator = platformServices;
            Device.Info = new IOSDeviceInfo();
#else
            Device.Info = new Platform.macOS.MacDeviceInfo();
#endif
            if (maybeOptions?.Flags.HasFlag(InitializationFlags.SkipRenderers) != true)
            {
                RegisterCompatRenderers();
            }

            ExpressionSearch.Default = new iOSExpressionSearch();

            IsInitialized = true;
        }
Example #2
0
        public ViewPreferences(IInvoker aInvoker, Model aModel, HelperAutoUpdate aHelperAutoUpdate)
        {
            iInvoker          = aInvoker;
            iAppId            = "uk.co.linn.songcast.app";
            iModel            = aModel;
            iHelperAutoUpdate = aHelperAutoUpdate;

            // register the preference keys and default values
            object[] keys = new object[] { kPreferenceEnabled,
                                           kPreferenceReceiverList,
                                           kPreferenceSubnetList,
                                           kPreferenceSelectedReceiverUdn,
                                           kPreferenceSelectedSubnetAddress,
                                           kPreferenceMulticastEnabled,
                                           kPreferenceMulticastChannel,
                                           kPreferenceMusicLatencyMs,
                                           kPreferenceVideoLatencyMs,
                                           kPreferenceRotaryVolumeControl,
                                           kPreferenceAutoUpdatesEnabled,
                                           kPreferenceBetaUpdatesEnabled,
                                           kPreferenceUsageDataEnabled };
            object[] vals = new object[] { false,
                                           new NSArray(),
                                           new NSArray(),
                                           string.Empty,
                                           0,
                                           false,
                                           0,
                                           iModel.Preferences.DefaultMusicLatencyMs,
                                           iModel.Preferences.DefaultVideoLatencyMs,
                                           true,
                                           true,
                                           false,
                                           true };

            NSUserDefaults.StandardUserDefaults.RegisterDefaults(NSDictionary.FromObjectsAndKeys(vals, keys));

            // check the multicast channel - if it is currently the default (0), set it to a random value - this ensures that this
            // preference is always set to a valid value
            if (GetIntegerValue(kPreferenceMulticastChannel) == 0)
            {
                Random r       = new Random();
                int    byte1   = r.Next(254) + 1; // in range [1,254]
                int    byte2   = r.Next(254) + 1; // in range [1,254]
                int    channel = byte1 << 8 | byte2;
                NSUserDefaults.StandardUserDefaults.SetInt(channel, kPreferenceMulticastChannel);
            }

            // add observers for the distributed notifications from the preferences pane app
            NSDistributedNotificationCenter centre = NSDistributedNotificationCenter.DefaultCenter as NSDistributedNotificationCenter;
            NSString prefAppId = new NSString("uk.co.linn.songcast.prefs");

            centre.AddObserver(this, new Selector("selectedReceiverChanged:"), new NSString("PreferenceSelectedReceiverChanged"), prefAppId);
            centre.AddObserver(this, new Selector("selectedSubnetChanged:"), new NSString("PreferenceSelectedSubnetChanged"), prefAppId);
            centre.AddObserver(this, new Selector("multicastEnabledChanged:"), new NSString("PreferenceMulticastEnabledChanged"), prefAppId);
            centre.AddObserver(this, new Selector("multicastChannelChanged:"), new NSString("PreferenceMulticastChannelChanged"), prefAppId);
            centre.AddObserver(this, new Selector("musicLatencyMsChanged:"), new NSString("PreferenceMusicLatencyMsChanged"), prefAppId);
            centre.AddObserver(this, new Selector("videoLatencyMsChanged:"), new NSString("PreferenceVideoLatencyMsChanged"), prefAppId);
            centre.AddObserver(this, new Selector("volumeControlClicked:"), new NSString("PreferenceRotaryVolumeControlChanged"), prefAppId);
            centre.AddObserver(this, new Selector("autoUpdatesEnabledChanged:"), new NSString("PreferenceAutoUpdatesEnabledChanged"), prefAppId);
            centre.AddObserver(this, new Selector("betaUpdatesEnabledChanged:"), new NSString("PreferenceBetaUpdatesEnabledChanged"), prefAppId);
            centre.AddObserver(this, new Selector("usageDataEnabledChanged:"), new NSString("PreferenceUsageDataEnabledChanged"), prefAppId);
            centre.AddObserver(this, new Selector("refreshReceiverListClicked:"), new NSString("RefreshReceiverList"), prefAppId);
            centre.AddObserver(this, new Selector("checkForUpdatesClicked:"), new NSString("CheckForUpdates"), prefAppId);

            // hook up event handlers from model events - these changes in the model are reflected in the preference pane
            iHelperAutoUpdate.OptionPageUpdates.EventChanged += OptionPageUpdatesChanged;
            iModel.EventEnabledChanged      += ModelEnabledChanged;
            iModel.EventReceiverListChanged += ModelReceiverListChanged;
            iModel.EventSubnetListChanged   += ModelSubnetListChanged;

            // hook up event handlers from preferences events - the model can change these preferences - all other preferences
            // are only changed by the preference pane
            iModel.Preferences.EventSelectedReceiverChanged += PreferencesSelectedReceiverChanged;
            iModel.Preferences.EventSelectedSubnetChanged   += PreferencesSelectedSubnetChanged;

            // initialise the view with current values of defaults
            NSUserDefaults.StandardUserDefaults.SetBool(iModel.Enabled, kPreferenceEnabled);
            NSUserDefaults.StandardUserDefaults[kPreferenceReceiverList] = BuildReceiverList();
            NSUserDefaults.StandardUserDefaults[kPreferenceSubnetList]   = BuildSubnetList();
            NSUserDefaults.StandardUserDefaults.SetString(iModel.Preferences.SelectedReceiverUdn, kPreferenceSelectedReceiverUdn);
            NSUserDefaults.StandardUserDefaults.SetInt((int)iModel.Preferences.SelectedSubnetAddress, kPreferenceSelectedSubnetAddress);
            NSUserDefaults.StandardUserDefaults.SetBool(iModel.Preferences.MulticastEnabled, kPreferenceMulticastEnabled);
            NSUserDefaults.StandardUserDefaults.SetInt((int)iModel.Preferences.MulticastChannel, kPreferenceMulticastChannel);

            NSUserDefaults.StandardUserDefaults.SetInt((int)iModel.Preferences.MusicLatencyMs, kPreferenceMusicLatencyMs);
            NSUserDefaults.StandardUserDefaults.SetInt((int)iModel.Preferences.VideoLatencyMs, kPreferenceVideoLatencyMs);
            NSUserDefaults.StandardUserDefaults.SetBool(iModel.Preferences.RotaryVolumeControl, kPreferenceRotaryVolumeControl);
            NSUserDefaults.StandardUserDefaults.SetBool(iHelperAutoUpdate.OptionPageUpdates.AutoUpdate, kPreferenceAutoUpdatesEnabled);
            NSUserDefaults.StandardUserDefaults.SetBool(iHelperAutoUpdate.OptionPageUpdates.BetaVersions, kPreferenceBetaUpdatesEnabled);
            NSUserDefaults.StandardUserDefaults.SetBool(iModel.Preferences.UsageData, kPreferenceUsageDataEnabled);
            NSUserDefaults.StandardUserDefaults.Synchronize();
            centre.PostNotificationName("PreferenceAllChanged", iAppId, null, true);
        }
Example #3
0
 public SystemResPool()
 {
     NSNotificationCenter.DefaultCenter.AddObserver(new NSString("NSSystemColorsDidChangeNotification"), (obj) => { Invalidate(); });
     NSDistributedNotificationCenter.GetDefaultCenter().AddObserver(new NSString("AppleInterfaceThemeChangedNotification"), (obj) => { Invalidate(); });
 }