-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(telemetry): allow to disable telemetry through settings INTELLIJ…
…-12 (#8) Co-authored-by: Anna Henningsen <[email protected]>
- Loading branch information
Showing
23 changed files
with
695 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
packages/jetbrains-plugin/src/main/kotlin/com/mongodb/jbplugin/i18n/SettingsMessages.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.mongodb.jbplugin.i18n | ||
|
||
import com.intellij.DynamicBundle | ||
import org.jetbrains.annotations.Nls | ||
import org.jetbrains.annotations.NonNls | ||
import org.jetbrains.annotations.PropertyKey | ||
|
||
object SettingsMessages { | ||
@NonNls | ||
private const val BUNDLE = "messages.SettingsBundle" | ||
private val instance = DynamicBundle(SettingsMessages::class.java, BUNDLE) | ||
|
||
fun message( | ||
key: | ||
@PropertyKey(resourceBundle = BUNDLE) | ||
String, | ||
vararg params: Any, | ||
): @Nls String = instance.getMessage(key, *params) | ||
} |
19 changes: 19 additions & 0 deletions
19
packages/jetbrains-plugin/src/main/kotlin/com/mongodb/jbplugin/i18n/TelemetryMessages.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.mongodb.jbplugin.i18n | ||
|
||
import com.intellij.DynamicBundle | ||
import org.jetbrains.annotations.Nls | ||
import org.jetbrains.annotations.NonNls | ||
import org.jetbrains.annotations.PropertyKey | ||
|
||
object TelemetryMessages { | ||
@NonNls | ||
private const val BUNDLE = "messages.TelemetryBundle" | ||
private val instance = DynamicBundle(TelemetryMessages::class.java, BUNDLE) | ||
|
||
fun message( | ||
key: | ||
@PropertyKey(resourceBundle = BUNDLE) | ||
String, | ||
vararg params: Any, | ||
): @Nls String = instance.getMessage(key, *params) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
packages/jetbrains-plugin/src/main/kotlin/com/mongodb/jbplugin/settings/PluginSettings.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/** | ||
* Settings state for the plugin. These classes are responsible for the persistence of the plugin | ||
* settings. | ||
*/ | ||
|
||
package com.mongodb.jbplugin.settings | ||
|
||
import com.intellij.openapi.application.ApplicationManager | ||
import com.intellij.openapi.components.* | ||
import java.io.Serializable | ||
|
||
/** | ||
* The state component represents the persisting state. Don't use directly, this is only necessary | ||
* for the state to be persisted. Use PluginSettings instead. | ||
* | ||
* @see PluginSettings | ||
*/ | ||
@Service | ||
@State( | ||
name = "com.mongodb.jbplugin.settings.PluginSettings", | ||
storages = [Storage(value = "MongoDBPluginSettings.xml")], | ||
) | ||
class PluginSettingsStateComponent : SimplePersistentStateComponent<PluginSettings>(PluginSettings()) | ||
|
||
/** | ||
* The settings themselves. They are tracked, so any change on the settings properties will be eventually | ||
* persisted by IntelliJ. To access the settings, use the useSettings provider. | ||
* | ||
* @see useSettings | ||
*/ | ||
class PluginSettings : BaseState(), Serializable { | ||
var isTelemetryEnabled by property(true) | ||
var hasTelemetryOptOutputNotificationBeenShown by property(false) | ||
} | ||
|
||
/** | ||
* Function that provides a reference to the current PluginSettings. | ||
* | ||
* @see PluginSettings | ||
* | ||
* @return | ||
*/ | ||
fun useSettings(): PluginSettings = | ||
ApplicationManager.getApplication().getService( | ||
PluginSettingsStateComponent::class.java, | ||
).state |
73 changes: 73 additions & 0 deletions
73
...brains-plugin/src/main/kotlin/com/mongodb/jbplugin/settings/PluginSettingsConfigurable.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/** | ||
* These classes represent the settings modal. | ||
*/ | ||
|
||
package com.mongodb.jbplugin.settings | ||
|
||
import com.intellij.ide.BrowserUtil | ||
import com.intellij.openapi.options.Configurable | ||
import com.intellij.ui.components.JBCheckBox | ||
import com.intellij.util.ui.FormBuilder | ||
import com.mongodb.jbplugin.i18n.SettingsMessages | ||
import com.mongodb.jbplugin.i18n.TelemetryMessages | ||
import javax.swing.JButton | ||
import javax.swing.JComponent | ||
import javax.swing.JPanel | ||
|
||
/** | ||
* This class represents a section in the settings modal. The UI will be implemented by | ||
* PluginSettingsComponent. | ||
*/ | ||
class PluginSettingsConfigurable : Configurable { | ||
private lateinit var settingsComponent: PluginSettingsComponent | ||
|
||
override fun createComponent(): JComponent { | ||
settingsComponent = PluginSettingsComponent() | ||
return settingsComponent.root | ||
} | ||
|
||
override fun isModified(): Boolean { | ||
val savedSettings = useSettings() | ||
return settingsComponent.isTelemetryEnabledCheckBox.isSelected != savedSettings.isTelemetryEnabled | ||
} | ||
|
||
override fun apply() { | ||
val savedSettings = | ||
useSettings().apply { | ||
isTelemetryEnabled = settingsComponent.isTelemetryEnabledCheckBox.isSelected | ||
} | ||
} | ||
|
||
override fun reset() { | ||
val savedSettings = useSettings() | ||
settingsComponent.isTelemetryEnabledCheckBox.isSelected = savedSettings.isTelemetryEnabled | ||
} | ||
|
||
override fun getDisplayName() = SettingsMessages.message("settings.display-name") | ||
} | ||
|
||
/** | ||
* The panel that is shown in the settings section for MongoDB. | ||
*/ | ||
private class PluginSettingsComponent { | ||
val root: JPanel | ||
val isTelemetryEnabledCheckBox = JBCheckBox(TelemetryMessages.message("settings.telemetry-collection-checkbox")) | ||
val privacyPolicyButton = JButton(TelemetryMessages.message("action.view-privacy-policy")) | ||
|
||
init { | ||
privacyPolicyButton.addActionListener { | ||
BrowserUtil.browse(TelemetryMessages.message("settings.telemetry-privacy-policy")) | ||
} | ||
|
||
root = | ||
FormBuilder.createFormBuilder() | ||
.addComponent(isTelemetryEnabledCheckBox) | ||
.addTooltip(TelemetryMessages.message("settings.telemetry-collection-tooltip")) | ||
.addComponent(privacyPolicyButton) | ||
.addComponentFillVertically(JPanel(), 0) | ||
.panel | ||
|
||
root.accessibleContext.accessibleName = "MongoDB Settings" | ||
isTelemetryEnabledCheckBox.accessibleContext.accessibleName = "MongoDB Enable Telemetry" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
packages/jetbrains-plugin/src/main/resources/messages/SettingsBundle.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
settings.display-name=MongoDB |
8 changes: 8 additions & 0 deletions
8
packages/jetbrains-plugin/src/main/resources/messages/TelemetryBundle.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
notification.group.name=MongoDB telemetry | ||
notification.title=MongoDB plugin telemetry | ||
notification.message=Anonymous telemetry is enabled by default because it helps us improve the plugin. | ||
action.disable-telemetry=Disable Telemetry | ||
action.view-privacy-policy=View Privacy Policy | ||
settings.telemetry-collection-tooltip=Allow the collection of anonymous diagnostics and usage telemetry data to help improve the product. | ||
settings.telemetry-collection-checkbox=Enable telemetry | ||
settings.telemetry-privacy-policy=https://www.mongodb.com/legal/privacy/privacy-policy |
Oops, something went wrong.