/// <summary>
        /// Because we are creating our own mac application delegate we are removing / overriding
        /// the one that Avalonia creates. This causes the application to not be handled as it should.
        /// This is the Avalonia Implementation: https://github.com/AvaloniaUI/Avalonia/blob/5a2ef35dacbce0438b66d9f012e5f629045beb3d/native/Avalonia.Native/src/OSX/app.mm
        /// So what we are doing here is re-creating this implementation to mimick their behavior.
        /// </summary>
        /// <param name="notification"></param>
        public override void DidFinishLaunching(NSNotification notification)
        {
#if !NETSTANDARD && !NET5_0 && !NET6_0
            VisualStudioAppCenterSDK.Init();
#endif

            NSRunningApplication.CurrentApplication.Activate(NSApplicationActivationOptions.ActivateIgnoringOtherWindows);
        }
Example #2
0
        //
        // This method is invoked when the application has loaded and is ready to run. In this
        // method you should instantiate the window, load the UI into it and then make the window
        // visible.
        //
        // You have 17 seconds to return from this method, or iOS will terminate your application.
        //
        public override bool FinishedLaunching(UIApplication app, NSDictionary options)
        {
            VisualStudioAppCenterSDK.Init();

            DILevel level;

            /*if (isMainProcess)*/
            level = DILevel.MainProcess;
            //level = DILevel.Min;
            Startup.Init(level);

            Forms.Init();
            FormsMaterial.Init();
            LoadApplication(new App());

            return(base.FinishedLaunching(app, options));
        }
Example #3
0
        public override void OnCreate()
        {
            base.OnCreate();

            VisualStudioAppCenterSDK.Init();

            XEFileProvider.TemporaryLocation = FileProviderLocation.Internal;
            XEPlatform.Init(this); // 初始化 Xamarin.Essentials.Platform.Init

            bool GetIsMainProcess()
            {
                // 注意:进程名可以自定义,默认是包名,如果自定义了主进程名,这里就有误,所以不要自定义主进程名!
                var name = this.GetCurrentProcessName();

                return(name == PackageName);
            }

            IsMainProcess = GetIsMainProcess();

            DILevel level = DILevel.Min;

            if (IsMainProcess)
            {
                level = DILevel.MainProcess;
            }
            Startup.Init(level);

            if (IsMainProcess)
            {
                XEVersionTracking.Track();
            }

#if DEBUG
            Log.Debug("Application", "OnCreate Complete.");
#endif
        }
        //#if DEBUG
        //RefWatcher? _refWatcher;

        //void SetupLeakCanary()
        //{
        //    // “A small leak will sink a great ship.” - Benjamin Franklin
        //    if (LeakCanaryXamarin.IsInAnalyzerProcess(this))
        //    {
        //        // This process is dedicated to LeakCanary for heap analysis.
        //        // You should not init your app in this process.
        //        return;
        //    }
        //    _refWatcher = LeakCanaryXamarin.Install(this);
        //}
        //#endif

        public override void OnCreate()
        {
            base.OnCreate();
            //#if DEBUG
            //            //SetupLeakCanary();
            //#endif
            var stopwatch  = Stopwatch.StartNew();
            var startTrace = new StringBuilder();

            FileSystem2.InitFileSystem();

            stopwatch.Stop();
            startTrace.AppendFormatLine("init FileSystem {0}ms", stopwatch.ElapsedMilliseconds);
            stopwatch.Restart();

            IApplication.InitLogDir();

            stopwatch.Stop();
            startTrace.AppendFormatLine("init NLog {0}ms", stopwatch.ElapsedMilliseconds);
            stopwatch.Restart();

            Startup.InitGlobalExceptionHandler();

            stopwatch.Stop();
            startTrace.AppendFormatLine("init ExceptionHandler {0}ms", stopwatch.ElapsedMilliseconds);
            stopwatch.Restart();

            VisualStudioAppCenterSDK.Init();

            stopwatch.Stop();
            startTrace.AppendFormatLine("init AppCenter {0}ms", stopwatch.ElapsedMilliseconds);
            stopwatch.Restart();

            XEFileProvider.TemporaryLocation = FileProviderLocation.Internal;
            XEPlatform.Init(this); // 初始化 Xamarin.Essentials.Platform.Init

            XEPlatform.ActivityStateChanged += OnActivityStateChanged;

            stopwatch.Stop();
            startTrace.AppendFormatLine("init Essentials {0}ms", stopwatch.ElapsedMilliseconds);
            stopwatch.Restart();

            bool GetIsMainProcess()
            {
                // 注意:进程名可以自定义,默认是包名,如果自定义了主进程名,这里就有误,所以不要自定义主进程名!
                var name = this.GetCurrentProcessName();

                return(name == PackageName);
            }

            IsMainProcess = GetIsMainProcess();

            stopwatch.Stop();
            startTrace.AppendFormatLine("init IsMainProcess {0}ms", stopwatch.ElapsedMilliseconds);
            stopwatch.Restart();

            SettingsHost.Load();

            stopwatch.Stop();
            startTrace.AppendFormatLine("init SettingsHost {0}ms", stopwatch.ElapsedMilliseconds);
            stopwatch.Restart();

            InitSettingSubscribe();

            stopwatch.Stop();
            startTrace.AppendFormatLine("init SettingSubscribe {0}ms", stopwatch.ElapsedMilliseconds);
            stopwatch.Restart();

            var level = DILevel.Min;

            if (IsMainProcess)
            {
                level = DILevel.MainProcess;
            }
            Startup.Init(level);

            stopwatch.Stop();
            startTrace.AppendFormatLine("init Startup {0}ms", stopwatch.ElapsedMilliseconds);
            stopwatch.Restart();

            if (IsMainProcess)
            {
                XEVersionTracking.Track();

                stopwatch.Stop();
                startTrace.AppendFormatLine("init VersionTracking {0}ms", stopwatch.ElapsedMilliseconds);
                stopwatch.Restart();

                if (XEVersionTracking.IsFirstLaunchForCurrentVersion)
                {
                    // 当前版本第一次启动时,清除存放升级包缓存文件夹的目录
                    IApplicationUpdateService.ClearAllPackCacheDir();

                    stopwatch.Stop();
                    startTrace.AppendFormatLine("init ClearAllPackCacheDir {0}ms", stopwatch.ElapsedMilliseconds);
                    stopwatch.Restart();
                }
            }
            UISettings.Language.Subscribe(x => R.ChangeLanguage(x));

            stopwatch.Stop();
            startTrace.AppendFormatLine("init Language.Subscribe {0}ms", stopwatch.ElapsedMilliseconds);
            stopwatch.Restart();

            Startup.OnStartup(IsMainProcess);

            stopwatch.Stop();
            startTrace.AppendFormatLine("init OnStartup {0}ms", stopwatch.ElapsedMilliseconds);
            stopwatch.Restart();

            if (IsMainProcess)
            {
                var vmService = IViewModelManager.Instance;
                vmService.InitViewModels();

                stopwatch.Stop();
                startTrace.AppendFormatLine("init ViewModels {0}ms", stopwatch.ElapsedMilliseconds);
                stopwatch.Restart();

#if __XAMARIN_FORMS__
                Forms.Init(this, null);
                FormsMaterial.Init(this, null);
                ImageCircleRenderer.Init();

                stopwatch.Stop();
                startTrace.AppendFormatLine("init XF {0}ms", stopwatch.ElapsedMilliseconds);
                stopwatch.Restart();

                _Current = new(RealTheme);

                stopwatch.Stop();
                startTrace.AppendFormatLine("init XFApp {0}ms", stopwatch.ElapsedMilliseconds);
                stopwatch.Restart();
#endif
                vmService.MainWindow.Initialize();
            }

            stopwatch.Stop();
            StartupTrack = startTrace.ToString();
#if DEBUG
            Log.Warn("Application", $"OnCreate Complete({stopwatch.ElapsedMilliseconds}ms");
#endif
        }