From c34997fd7a9541eeae24fc54d2fe06424801c0ab Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Wed, 24 May 2023 00:13:28 +0300 Subject: [PATCH] don't use app.coroutineScope GitOrigin-RevId: d06592f38d02ccb50976b1b96ee710e23d431f24 --- .../com/intellij/ide/RecentProjectsManager.kt | 5 ++-- .../src/com/intellij/idea/IdeStarter.kt | 23 ++++++++++--------- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/platform/ide-core/src/com/intellij/ide/RecentProjectsManager.kt b/platform/ide-core/src/com/intellij/ide/RecentProjectsManager.kt index b60b7923ce06..ad5d60c96bd9 100644 --- a/platform/ide-core/src/com/intellij/ide/RecentProjectsManager.kt +++ b/platform/ide-core/src/com/intellij/ide/RecentProjectsManager.kt @@ -1,8 +1,9 @@ -// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package com.intellij.ide import com.intellij.openapi.actionSystem.AnAction import com.intellij.openapi.application.ApplicationManager +import com.intellij.openapi.components.service import com.intellij.openapi.project.Project import com.intellij.util.PathUtil import com.intellij.util.concurrency.annotations.RequiresEdt @@ -17,7 +18,7 @@ interface RecentProjectsManager { val RECENT_PROJECTS_CHANGE_TOPIC: Topic = Topic(RecentProjectsChange::class.java, Topic.BroadcastDirection.NONE) @JvmStatic - fun getInstance(): RecentProjectsManager = ApplicationManager.getApplication().getService(RecentProjectsManager::class.java) + fun getInstance(): RecentProjectsManager = ApplicationManager.getApplication().service() } // a path pointing to a directory where the last project was created or null if not available diff --git a/platform/platform-impl/src/com/intellij/idea/IdeStarter.kt b/platform/platform-impl/src/com/intellij/idea/IdeStarter.kt index d3097596a7b2..ad012d450603 100644 --- a/platform/platform-impl/src/com/intellij/idea/IdeStarter.kt +++ b/platform/platform-impl/src/com/intellij/idea/IdeStarter.kt @@ -22,6 +22,7 @@ import com.intellij.openapi.application.ex.ApplicationEx import com.intellij.openapi.application.ex.ApplicationManagerEx import com.intellij.openapi.components.Service import com.intellij.openapi.components.service +import com.intellij.openapi.components.serviceAsync import com.intellij.openapi.diagnostic.Logger import com.intellij.openapi.diagnostic.logger import com.intellij.openapi.project.Project @@ -68,7 +69,7 @@ open class IdeStarter : ModernApplicationStarter() { coroutineScope { val app = ApplicationManagerEx.getApplicationEx() val lifecyclePublisher = app.messageBus.syncPublisher(AppLifecycleListener.TOPIC) - openProjectIfNeeded(args = args, app = app, lifecyclePublisher = lifecyclePublisher) + openProjectIfNeeded(args = args, app = app, asyncCoroutineScope = this, lifecyclePublisher = lifecyclePublisher) launch { reportPluginErrors() } @@ -84,6 +85,7 @@ open class IdeStarter : ModernApplicationStarter() { @OptIn(IntellijInternalApi::class) protected open suspend fun openProjectIfNeeded(args: List, app: ApplicationEx, + asyncCoroutineScope: CoroutineScope, lifecyclePublisher: AppLifecycleListener) { val frameInitActivity = startActivity("frame initialization") frameInitActivity.runChild("app frame created callback") { @@ -97,16 +99,14 @@ open class IdeStarter : ModernApplicationStarter() { return } - if (app.isInternal) { - @Suppress("DEPRECATION") - app.coroutineScope.launch(Dispatchers.EDT + ModalityState.any().asContextElement()) { - UiInspectorAction.initGlobalInspector() - } + asyncCoroutineScope.launch { + LifecycleUsageTriggerCollector.onIdeStart() } - @Suppress("DEPRECATION") - app.coroutineScope.launch { - LifecycleUsageTriggerCollector.onIdeStart() + if (app.isInternal) { + asyncCoroutineScope.launch(Dispatchers.EDT + ModalityState.any().asContextElement()) { + UiInspectorAction.initGlobalInspector() + } } if (uriToOpen != null || args.isNotEmpty() && args.first().contains(SCHEME_SEPARATOR)) { @@ -115,7 +115,7 @@ open class IdeStarter : ModernApplicationStarter() { return } - val recentProjectManager = RecentProjectsManager.getInstance() + val recentProjectManager = ApplicationManager.getApplication().serviceAsync() val willReopenRecentProjectOnStart = recentProjectManager.willReopenProjectOnStart() val willOpenProject = willReopenRecentProjectOnStart || !args.isEmpty() || !filesToLoad.isEmpty() val needToOpenProject = willOpenProject || showWelcomeFrame(lifecyclePublisher) @@ -175,6 +175,7 @@ open class IdeStarter : ModernApplicationStarter() { internal class StandaloneLightEditStarter : IdeStarter() { override suspend fun openProjectIfNeeded(args: List, app: ApplicationEx, + asyncCoroutineScope: CoroutineScope, lifecyclePublisher: AppLifecycleListener) { val project = when { filesToLoad.isNotEmpty() -> ProjectUtil.openOrImportFilesAsync(list = filesToLoad, location = "MacMenu") @@ -189,7 +190,7 @@ open class IdeStarter : ModernApplicationStarter() { val recentProjectManager = RecentProjectsManager.getInstance() val isOpened = (if (recentProjectManager.willReopenProjectOnStart()) recentProjectManager.reopenLastProjectsOnStart() else true) if (!isOpened) { - ApplicationManager.getApplication().invokeLater { + asyncCoroutineScope.launch(Dispatchers.EDT) { LightEditService.getInstance().showEditorWindow() } }