Search in sources :

Example 1 with Analytics

use of io.flutter.analytics.Analytics in project flutter-intellij by flutter.

the class FlutterInitializer method getAnalytics.

@NotNull
public static Analytics getAnalytics() {
    if (analytics == null) {
        final PropertiesComponent properties = PropertiesComponent.getInstance();
        String clientId = properties.getValue(analyticsClientIdKey);
        if (clientId == null) {
            clientId = UUID.randomUUID().toString();
            properties.setValue(analyticsClientIdKey, clientId);
        }
        final IdeaPluginDescriptor descriptor = PluginManager.getPlugin(FlutterUtils.getPluginId());
        assert descriptor != null;
        final ApplicationInfo info = ApplicationInfo.getInstance();
        analytics = new Analytics(clientId, descriptor.getVersion(), info.getVersionName(), info.getFullVersion());
        // Set up reporting prefs.
        analytics.setCanSend(getCanReportAnalytics());
        // Send initial loading hit.
        analytics.sendScreenView("main");
        FlutterSettings.getInstance().sendSettingsToAnalytics(analytics);
    }
    return analytics;
}
Also used : ApplicationInfo(com.intellij.openapi.application.ApplicationInfo) IdeaPluginDescriptor(com.intellij.ide.plugins.IdeaPluginDescriptor) PropertiesComponent(com.intellij.ide.util.PropertiesComponent) Analytics(io.flutter.analytics.Analytics) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with Analytics

use of io.flutter.analytics.Analytics in project flutter-intellij by flutter.

the class FlutterInitializer method runActivity.

@Override
public void runActivity(@NotNull Project project) {
    // Convert all modules of deprecated type FlutterModuleType.
    if (FlutterModuleUtils.convertFromDeprecatedModuleType(project)) {
        // If any modules were converted over, create a notification
        FlutterMessages.showInfo(FlutterBundle.message("flutter.initializer.module.converted.title"), "Converted from '" + FlutterModuleUtils.DEPRECATED_FLUTTER_MODULE_TYPE_ID + "' to '" + FlutterModuleUtils.getModuleTypeIDForFlutter() + "'.");
    }
    // Disable the 'Migrate Project to Gradle' notification.
    FlutterUtils.disableGradleProjectMigrationNotification(project);
    // Start watching for devices.
    DeviceService.getInstance(project);
    // Start watching for Flutter debug active events.
    FlutterViewFactory.init(project);
    // If the project declares a Flutter dependency, do some extra initialization.
    final PubRoot root = PubRoot.singleForProjectWithRefresh(project);
    if (root != null && root.declaresFlutter()) {
        // Set Android SDK.
        if (root.hasAndroidModule(project)) {
            ensureAndroidSdk(project);
        }
        // Setup a default run configuration for 'main.dart' (if it's not there already and the file exists).
        FlutterModuleUtils.autoCreateRunConfig(project, root);
        // Ensure a run config is selected and ready to go.
        FlutterModuleUtils.ensureRunConfigSelected(project);
        // If there are no open editors, show main.
        final FileEditorManager editorManager = FileEditorManager.getInstance(project);
        if (editorManager.getOpenFiles().length == 0) {
            FlutterModuleUtils.autoShowMain(project, root);
        }
    }
    FlutterRunNotifications.init(project);
    // Watch save actions for reload on save.
    FlutterReloadManager.init(project);
    // Watch save actions for format on save.
    FlutterSaveActionsManager.init(project);
    // Start watching for project structure and .packages file changes.
    final FlutterPluginsLibraryManager libraryManager = new FlutterPluginsLibraryManager(project);
    libraryManager.startWatching();
    // Initialize the analytics notification group.
    NotificationsConfiguration.getNotificationsConfiguration().register(Analytics.GROUP_DISPLAY_ID, NotificationDisplayType.STICKY_BALLOON, false);
    // Initialize analytics.
    final PropertiesComponent properties = PropertiesComponent.getInstance();
    if (!properties.getBoolean(analyticsToastShown)) {
        properties.setValue(analyticsToastShown, true);
        final Notification notification = new Notification(Analytics.GROUP_DISPLAY_ID, "Welcome to Flutter!", FlutterBundle.message("flutter.analytics.notification.content"), NotificationType.INFORMATION, (notification1, event) -> {
            if (event.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
                if ("url".equals(event.getDescription())) {
                    BrowserUtil.browse("https://www.google.com/policies/privacy/");
                }
            }
        });
        notification.addAction(new AnAction("Sounds good!") {

            @Override
            public void actionPerformed(AnActionEvent event) {
                notification.expire();
                final Analytics analytics = getAnalytics();
                // We only track for flutter projects.
                if (FlutterModuleUtils.usesFlutter(project)) {
                    ToolWindowTracker.track(project, analytics);
                }
            }
        });
        notification.addAction(new AnAction("No thanks") {

            @Override
            public void actionPerformed(AnActionEvent event) {
                notification.expire();
                setCanReportAnalytics(false);
            }
        });
        Notifications.Bus.notify(notification);
    } else {
        // We only track for flutter projects.
        if (FlutterModuleUtils.usesFlutter(project)) {
            ToolWindowTracker.track(project, getAnalytics());
        }
    }
}
Also used : FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) PubRoot(io.flutter.pub.PubRoot) FlutterPluginsLibraryManager(io.flutter.sdk.FlutterPluginsLibraryManager) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) PropertiesComponent(com.intellij.ide.util.PropertiesComponent) AnAction(com.intellij.openapi.actionSystem.AnAction) Analytics(io.flutter.analytics.Analytics)

Aggregations

PropertiesComponent (com.intellij.ide.util.PropertiesComponent)2 Analytics (io.flutter.analytics.Analytics)2 IdeaPluginDescriptor (com.intellij.ide.plugins.IdeaPluginDescriptor)1 AnAction (com.intellij.openapi.actionSystem.AnAction)1 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)1 ApplicationInfo (com.intellij.openapi.application.ApplicationInfo)1 FileEditorManager (com.intellij.openapi.fileEditor.FileEditorManager)1 PubRoot (io.flutter.pub.PubRoot)1 FlutterPluginsLibraryManager (io.flutter.sdk.FlutterPluginsLibraryManager)1 NotNull (org.jetbrains.annotations.NotNull)1