Exemplo n.º 1
0
        public sealed override void OnCreate()
        {
            base.OnCreate();

            if (EnableThreadUncaughtExceptionHandler)
            {
                ThreadUncaughtExceptionHandler.Initialize();
            }

            CrossCurrentActivity.Current.Init(this);

            var options = AppSettings;

            #region Visual Studio App Center

            if (options.AppSecretVisualStudioAppCenter != null)
            {
                // Visual Studio App Center
                // 将移动开发人员常用的多种服务整合到一个集成的产品中。
                // 您可以构建,测试,分发和监控移动应用程序,还可以实施推送通知。
                // https://docs.microsoft.com/zh-cn/appcenter/sdk/getting-started/xamarin
                // https://visualstudio.microsoft.com/zh-hans/app-center
                AppCenter.Start(options.AppSecretVisualStudioAppCenter, typeof(Analytics), typeof(Crashes));
            }

            #endregion

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

            var isMainProcess = IsMainProcess();

            DI.Init(ConfigureServices);

            void ConfigureServices(IServiceCollection services)
            {
                ConfigureRequiredServices(services, options);
                if (isMainProcess)
                {
                    ConfigureMainProcessServices(services, options);
                }
            }

            if (isMainProcess)
            {
                XEVersionTracking.Track();

                // 厂商ROM检测
                AndroidROM.Initialize();

                // Emoji表情
                EmojiCompatLibrary.Init(this);
            }

            OnCreated(options, isMainProcess);

#if DEBUG
            Log.Debug("Application", "OnCreate Complete.");
#endif
        }
Exemplo n.º 2
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
        }
Exemplo n.º 3
0
        //#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
        }