├── android
├── plugin
│ ├── consumer-rules.pro
│ ├── .gitignore
│ ├── src
│ │ └── main
│ │ │ ├── res
│ │ │ └── values
│ │ │ │ └── strings.xml
│ │ │ ├── AndroidManifest.xml
│ │ │ └── java
│ │ │ └── com
│ │ │ └── ddyos
│ │ │ └── flipper
│ │ │ └── mmkv
│ │ │ └── plugin
│ │ │ ├── MMKVDescriptor.kt
│ │ │ └── MMKVFlipperPlugin.kt
│ ├── proguard-rules.pro
│ └── build.gradle
├── sample
│ ├── .gitignore
│ ├── src
│ │ ├── main
│ │ │ ├── res
│ │ │ │ ├── values
│ │ │ │ │ ├── dimens.xml
│ │ │ │ │ ├── strings.xml
│ │ │ │ │ ├── colors.xml
│ │ │ │ │ └── styles.xml
│ │ │ │ ├── mipmap-xxhdpi
│ │ │ │ │ ├── ic_launcher.png
│ │ │ │ │ └── ic_launcher_round.png
│ │ │ │ ├── mipmap-anydpi-v26
│ │ │ │ │ ├── ic_launcher.xml
│ │ │ │ │ └── ic_launcher_round.xml
│ │ │ │ ├── layout
│ │ │ │ │ ├── content_main.xml
│ │ │ │ │ └── activity_main.xml
│ │ │ │ ├── drawable-v24
│ │ │ │ │ └── ic_launcher_foreground.xml
│ │ │ │ └── drawable
│ │ │ │ │ └── ic_launcher_background.xml
│ │ │ ├── java
│ │ │ │ └── com
│ │ │ │ │ └── ddyos
│ │ │ │ │ └── flipper
│ │ │ │ │ └── mmkv
│ │ │ │ │ └── sample
│ │ │ │ │ ├── MainActivity.kt
│ │ │ │ │ └── SampleApplication.kt
│ │ │ └── AndroidManifest.xml
│ │ ├── test
│ │ │ └── java
│ │ │ │ └── com
│ │ │ │ └── ddyos
│ │ │ │ └── flipper
│ │ │ │ └── mmkv
│ │ │ │ └── sample
│ │ │ │ └── ExampleUnitTest.kt
│ │ └── androidTest
│ │ │ └── java
│ │ │ └── com
│ │ │ └── ddyos
│ │ │ └── flipper
│ │ │ └── mmkv
│ │ │ └── sample
│ │ │ └── ExampleInstrumentedTest.kt
│ ├── proguard-rules.pro
│ └── build.gradle
├── settings.gradle
├── gradle
│ └── wrapper
│ │ ├── gradle-wrapper.jar
│ │ └── gradle-wrapper.properties
├── build.gradle
├── gradle.properties
├── gradlew.bat
└── gradlew
├── package.json
├── LICENSE
├── .gitignore
├── README.zh-cn.md
├── README.md
└── index.js
/android/plugin/consumer-rules.pro:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/android/plugin/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/android/sample/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/android/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':sample', ':plugin'
2 | rootProject.name='FlipperMMKVPlugin'
3 |
--------------------------------------------------------------------------------
/android/sample/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 | 16dp
3 |
4 |
--------------------------------------------------------------------------------
/android/plugin/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | MMKV Plugin
3 |
4 |
--------------------------------------------------------------------------------
/android/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ddyos/flipper-plugin-mmkv-viewer/HEAD/android/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/android/plugin/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
3 |
--------------------------------------------------------------------------------
/android/sample/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ddyos/flipper-plugin-mmkv-viewer/HEAD/android/sample/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/android/sample/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ddyos/flipper-plugin-mmkv-viewer/HEAD/android/sample/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/android/sample/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | FlipperMMKVPlugin
3 | Settings
4 |
5 |
--------------------------------------------------------------------------------
/android/sample/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #008577
4 | #00574B
5 | #D81B60
6 |
7 |
--------------------------------------------------------------------------------
/android/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Sat Jan 18 11:28:21 CST 2020
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
7 |
--------------------------------------------------------------------------------
/android/plugin/src/main/java/com/ddyos/flipper/mmkv/plugin/MMKVDescriptor.kt:
--------------------------------------------------------------------------------
1 | package com.ddyos.flipper.mmkv.plugin
2 |
3 | import com.tencent.mmkv.MMKV
4 |
5 | class MMKVDescriptor @JvmOverloads constructor(
6 | val name: String,
7 | val mode: Int = MMKV.SINGLE_PROCESS_MODE,
8 | val cryptKey: String? = null
9 | )
--------------------------------------------------------------------------------
/android/sample/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/android/sample/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/android/sample/src/test/java/com/ddyos/flipper/mmkv/sample/ExampleUnitTest.kt:
--------------------------------------------------------------------------------
1 | package com.ddyos.flipper.mmkv.sample
2 |
3 | import org.junit.Test
4 |
5 | import org.junit.Assert.*
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * See [testing documentation](http://d.android.com/tools/testing).
11 | */
12 | class ExampleUnitTest {
13 | @Test
14 | fun addition_isCorrect() {
15 | assertEquals(4, 2 + 2)
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/android/sample/src/main/java/com/ddyos/flipper/mmkv/sample/MainActivity.kt:
--------------------------------------------------------------------------------
1 | package com.ddyos.flipper.mmkv.sample
2 |
3 | import android.os.Bundle
4 | import androidx.appcompat.app.AppCompatActivity
5 | import com.tencent.mmkv.MMKV
6 | import kotlinx.android.synthetic.main.activity_main.*
7 | import kotlinx.android.synthetic.main.content_main.*
8 |
9 | class MainActivity : AppCompatActivity() {
10 |
11 | override fun onCreate(savedInstanceState: Bundle?) {
12 | super.onCreate(savedInstanceState)
13 | setContentView(R.layout.activity_main)
14 | setSupportActionBar(toolbar)
15 |
16 | btn_add.setOnClickListener {
17 | MMKV.mmkvWithID("other_mmkv").encode("time", System.currentTimeMillis())
18 | }
19 | }
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/android/sample/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/android/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | ext.kotlin_version = '1.3.61'
5 | repositories {
6 | google()
7 | jcenter()
8 |
9 | }
10 | dependencies {
11 | classpath 'com.android.tools.build:gradle:3.5.3'
12 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
13 | // NOTE: Do not place your application dependencies here; they belong
14 | // in the individual module build.gradle files
15 | classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
16 | }
17 | }
18 |
19 | allprojects {
20 | repositories {
21 | google()
22 | jcenter()
23 |
24 | }
25 | }
26 |
27 | task clean(type: Delete) {
28 | delete rootProject.buildDir
29 | }
30 |
--------------------------------------------------------------------------------
/android/plugin/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/android/sample/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/android/sample/src/androidTest/java/com/ddyos/flipper/mmkv/sample/ExampleInstrumentedTest.kt:
--------------------------------------------------------------------------------
1 | package com.ddyos.flipper.mmkv.sample
2 |
3 | import androidx.test.platform.app.InstrumentationRegistry
4 | import androidx.test.ext.junit.runners.AndroidJUnit4
5 |
6 | import org.junit.Test
7 | import org.junit.runner.RunWith
8 |
9 | import org.junit.Assert.*
10 |
11 | /**
12 | * Instrumented test, which will execute on an Android device.
13 | *
14 | * See [testing documentation](http://d.android.com/tools/testing).
15 | */
16 | @RunWith(AndroidJUnit4::class)
17 | class ExampleInstrumentedTest {
18 | @Test
19 | fun useAppContext() {
20 | // Context of the app under test.
21 | val appContext = InstrumentationRegistry.getInstrumentation().targetContext
22 | assertEquals("com.ddyos.flipper.mmkv.sample", appContext.packageName)
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/android/sample/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
13 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "https://fbflipper.com/schemas/plugin-package/v2.json",
3 | "name": "flipper-plugin-mmkv-viewer",
4 | "id": "flipper-plugin-mmkv-viewer",
5 | "version": "1.0.2",
6 | "description": "MMKV Viewer for Flipper",
7 | "homepage": "https://github.com/ddyos/flipper-plugin-mmkv-viewer",
8 | "repository": {
9 | "type": "git",
10 | "url": "https://github.com/ddyos/flipper-plugin-mmkv-viewer.git"
11 | },
12 | "main": "dist/bundle.js",
13 | "flipperBundlerEntry": "index.js",
14 | "license": "MIT",
15 | "keywords": [
16 | "flipper-plugin",
17 | "mmkv"
18 | ],
19 | "files": [
20 | "index.js"
21 | ],
22 | "dependencies": {
23 | "lodash": "^4.17.13"
24 | },
25 | "peerDependencies": {
26 | "flipper": "latest"
27 | },
28 | "devDependencies": {
29 | "flipper": "latest",
30 | "flipper-pkg": "latest"
31 | },
32 | "title": "MMKV Viewer",
33 | "scripts": {
34 | "prepack": "flipper-pkg lint && flipper-pkg bundle"
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/android/sample/src/main/res/layout/content_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
20 |
21 |
--------------------------------------------------------------------------------
/android/plugin/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'kotlin-android'
3 | apply plugin: 'kotlin-android-extensions'
4 |
5 | apply plugin: 'com.github.dcendents.android-maven'
6 | group='com.github.ddyos'
7 |
8 | android {
9 | compileSdkVersion 28
10 | buildToolsVersion "28.0.2"
11 |
12 |
13 | defaultConfig {
14 | minSdkVersion 18
15 | targetSdkVersion 28
16 | versionCode 1
17 | versionName "1.0.0"
18 |
19 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
20 | consumerProguardFiles 'consumer-rules.pro'
21 | }
22 |
23 | buildTypes {
24 | release {
25 | minifyEnabled false
26 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
27 | }
28 | }
29 |
30 | }
31 |
32 | dependencies {
33 | implementation fileTree(dir: 'libs', include: ['*.jar'])
34 |
35 | compileOnly 'com.facebook.flipper:flipper:0.30.1'
36 | compileOnly 'com.facebook.soloader:soloader:0.8.0'
37 | compileOnly "com.tencent:mmkv-static:1.0.22"
38 | }
39 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2020 ddyos
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy of
6 | this software and associated documentation files (the "Software"), to deal in
7 | the Software without restriction, including without limitation the rights to
8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9 | the Software, and to permit persons to whom the Software is furnished to do so,
10 | subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 |
--------------------------------------------------------------------------------
/android/sample/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
13 |
14 |
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/android/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx1536m
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. More details, visit
12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13 | # org.gradle.parallel=true
14 | # AndroidX package structure to make it clearer which packages are bundled with the
15 | # Android operating system, and which are packaged with your app's APK
16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn
17 | android.useAndroidX=true
18 | # Automatically convert third-party libraries to use AndroidX
19 | android.enableJetifier=true
20 | # Kotlin code style for this project: "official" or "obsolete":
21 | kotlin.code.style=official
22 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Modules
2 | node_modules
3 |
4 | # Bundling output
5 | dist
6 |
7 | # Built application files
8 | *.apk
9 | *.aar
10 | *.ap_
11 | *.aab
12 |
13 | # Files for the ART/Dalvik VM
14 | *.dex
15 |
16 | # Java class files
17 | *.class
18 |
19 | # Generated files
20 | bin/
21 | gen/
22 | out/
23 | # Uncomment the following line in case you need and you don't have the release build type files in your app
24 | # release/
25 |
26 | # Gradle files
27 | .gradle/
28 | build/
29 |
30 | # Local configuration file (sdk path, etc)
31 | local.properties
32 |
33 | # Proguard folder generated by Eclipse
34 | proguard/
35 |
36 | # Log Files
37 | *.log
38 |
39 | # Android Studio Navigation editor temp files
40 | .navigation/
41 |
42 | # Android Studio captures folder
43 | captures/
44 |
45 | # IntelliJ
46 | *.iml
47 | .metadata/
48 | .idea/
49 |
50 | # Keystore files
51 | # Uncomment the following lines if you do not want to check your keystore files in.
52 | #*.jks
53 | #*.keystore
54 |
55 | # External native build folder generated in Android Studio 2.2 and later
56 | .externalNativeBuild
57 | .cxx/
58 |
59 | # Google Services (e.g. APIs or Firebase)
60 | # google-services.json
61 |
62 | # Freeline
63 | freeline.py
64 | freeline/
65 | freeline_project_description.json
66 |
67 | # fastlane
68 | fastlane/report.xml
69 | fastlane/Preview.html
70 | fastlane/screenshots
71 | fastlane/test_output
72 | fastlane/readme.md
73 |
74 | # Version control
75 | vcs.xml
76 |
77 | # lint
78 | lint/intermediates/
79 | lint/generated/
80 | lint/outputs/
81 | lint/tmp/
82 | # lint/reports/
83 |
--------------------------------------------------------------------------------
/android/sample/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | apply plugin: 'kotlin-android'
4 |
5 | apply plugin: 'kotlin-android-extensions'
6 |
7 | android {
8 | compileSdkVersion 28
9 | buildToolsVersion "28.0.2"
10 | defaultConfig {
11 | applicationId "com.ddyos.flipper.mmkv.sample"
12 | minSdkVersion 18
13 | targetSdkVersion 28
14 | versionCode 1
15 | versionName "1.0"
16 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
17 | }
18 | buildTypes {
19 | release {
20 | minifyEnabled false
21 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
22 | }
23 | }
24 | }
25 |
26 | dependencies {
27 | implementation fileTree(dir: 'libs', include: ['*.jar'])
28 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
29 | implementation 'androidx.appcompat:appcompat:1.0.2'
30 | implementation 'androidx.core:core-ktx:1.0.2'
31 | implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
32 | implementation 'com.google.android.material:material:1.0.0'
33 | testImplementation 'junit:junit:4.12'
34 | androidTestImplementation 'androidx.test.ext:junit:1.1.0'
35 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
36 |
37 | debugImplementation 'com.facebook.flipper:flipper:0.30.1'
38 | debugImplementation 'com.facebook.soloader:soloader:0.8.0'
39 | releaseImplementation 'com.facebook.flipper:flipper-noop:0.30.1'
40 |
41 | implementation "com.tencent:mmkv-static:1.0.22"
42 |
43 | debugImplementation project(':plugin')
44 | }
45 |
--------------------------------------------------------------------------------
/android/sample/src/main/java/com/ddyos/flipper/mmkv/sample/SampleApplication.kt:
--------------------------------------------------------------------------------
1 | package com.ddyos.flipper.mmkv.sample
2 |
3 | import android.app.Application
4 | import com.ddyos.flipper.mmkv.plugin.MMKVDescriptor
5 | import com.ddyos.flipper.mmkv.plugin.MMKVFlipperPlugin
6 | import com.facebook.flipper.android.AndroidFlipperClient
7 | import com.facebook.soloader.SoLoader
8 | import com.tencent.mmkv.MMKV
9 |
10 | class SampleApplication : Application() {
11 |
12 | companion object {
13 | private const val cryptKey = "cryptKey"
14 | }
15 |
16 | override fun onCreate() {
17 | super.onCreate()
18 |
19 | SoLoader.init(this, false)
20 | MMKV.initialize(this)
21 |
22 | insertTestData()
23 |
24 | if (BuildConfig.DEBUG) {
25 | val client = AndroidFlipperClient.getInstance(this)
26 |
27 | // client.addPlugin(MMKVFlipperPlugin())
28 | // client.addPlugin(MMKVFlipperPlugin("other_mmkv"))
29 | client.addPlugin(
30 | MMKVFlipperPlugin(
31 | listOf(
32 | MMKVDescriptor("other_mmkv"),
33 | MMKVDescriptor("another_mmkv", MMKV.MULTI_PROCESS_MODE, cryptKey)
34 | )
35 | )
36 | )
37 |
38 | client.start()
39 | }
40 | }
41 |
42 | private fun insertTestData() {
43 | MMKV.defaultMMKV().encode("hello", "mmkv")
44 | MMKV.defaultMMKV().encode("key2", 123)
45 | MMKV.defaultMMKV().close()
46 |
47 | MMKV.mmkvWithID("other_mmkv").encode("key1", true)
48 | MMKV.mmkvWithID("other_mmkv").encode("test_mmkv2", "slidng")
49 | MMKV.mmkvWithID("other_mmkv").close()
50 |
51 | val cryptMMKV = MMKV.mmkvWithID("another_mmkv", MMKV.MULTI_PROCESS_MODE, cryptKey)
52 | cryptMMKV.encode("2key1", true)
53 | cryptMMKV.close()
54 | }
55 | }
--------------------------------------------------------------------------------
/android/sample/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/README.zh-cn.md:
--------------------------------------------------------------------------------
1 | # Flipper MMKV 调试插件
2 |
3 | [](https://jitpack.io/#ddyos/flipper-plugin-mmkv-viewer)
4 | [](https://www.npmjs.com/package/flipper-plugin-mmkv-viewer)
5 |
6 | *[English](README.md) | [简体中文](README.zh-cn.md)*
7 |
8 | ## 简介
9 |
10 | 一个基于 [Flipper](https://fbflipper.com) 的调试插件,可以用于浏览原生应用中的 [MMKV](https://github.com/Tencent/MMKV) 文件。
11 |
12 | 插件可以查看和修改MMKV文件中的数据。
13 |
14 | 
15 |
16 | 当前仅支持Android。
17 |
18 | 注意:
19 |
20 | 由于MMKV for Android没有实现OnSharedPreferenceChangeListener接口, 所以需要通过“Refresh”按钮去刷新数据。
21 |
22 | ## 安装
23 |
24 | ### Flipper Desktop
25 |
26 | 1. 安装 [Flipper Desktop](https://fbflipper.com)
27 | 2. 通过 Flipper Desktop 左下角的 **Manage Plugins** 按钮 或者 **View** 菜单项, 进入插件管理页面
28 | 3. 选择 **Install Plugins** 选项卡,并搜索 `mmkv-viewer` 关键词
29 | 4. 通过 **Install** 按钮安装插件
30 |
31 | 
32 |
33 | ### Android
34 |
35 | 1. 添加 [Flipper Android SDK](https://github.com/facebook/flipper) 到app模块的 `build.gradle` :
36 | ```gradle
37 | dependencies {
38 | // please use Latest Version
39 | debugImplementation 'com.facebook.flipper:flipper:0.30.1'
40 | debugImplementation 'com.facebook.soloader:soloader:0.8.0'
41 | releaseImplementation 'com.facebook.flipper:flipper-noop:0.30.1'
42 | }
43 | ```
44 | 2. 添加 JitPack源 到根目录的 build.gradle 中:
45 | ```gradle
46 | allprojects {
47 | repositories {
48 | ...
49 | maven { url 'https://jitpack.io' }
50 | }
51 | }
52 | ```
53 | 3. 添加插件依赖到 app 的 build.gradle 中:
54 | ```gradle
55 | dependencies {
56 | // please use Latest Version
57 | debugImplementation 'com.github.ddyos:flipper-plugin-mmkv-viewer:1.0.0'
58 | }
59 | ```
60 | 4. 初始化插件:
61 | ```Kotlin
62 | val client = AndroidFlipperClient.getInstance(this)
63 | client.addPlugin(MMKVFlipperPlugin("other_mmkv"))
64 | client.start()
65 | ```
66 |
67 | ## Android 示例
68 |
69 | 参见[`sample`](/android/sample) 文件夹中的项目。
70 |
71 | ## License
72 |
73 | 基于 MIT License, 参看 [LICENSE](/LICENSE) 文件。
74 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Flipper MMKV Viewer Plugin
2 |
3 | [](https://jitpack.io/#ddyos/flipper-plugin-mmkv-viewer)
4 | [](https://www.npmjs.com/package/flipper-plugin-mmkv-viewer)
5 |
6 | *[English](README.md) | [简体中文](README.zh-cn.md)*
7 |
8 | ## Introduction
9 |
10 | A plugin for the debug tool [Flipper](https://fbflipper.com) that inspect the [MMKV](https://github.com/Tencent/MMKV) file of your native app.
11 |
12 | It can view or edit the key-value inside the MMKV file.
13 |
14 | 
15 |
16 | Currently only Android is supported.
17 |
18 | Note:
19 |
20 | MMKV did not implement OnSharedPreferenceChangeListener on Android, so you should update the data manually by press "Refresh" Button.
21 |
22 | ## Setup
23 |
24 | ### Flipper Desktop
25 |
26 | 1. Installed [Flipper Desktop](https://fbflipper.com)
27 | 2. Go to **Manage Plugins** by pressing the button in the lower left corner of the Flipper app, or in the **View** menu
28 | 3. Select **Install Plugins** and search for `mmkv-viewer`
29 | 4. Press the **Install** button
30 |
31 | 
32 |
33 | ### Android
34 |
35 | 1. Add [Flipper Android SDK](https://github.com/facebook/flipper) to `build.gradle` on your app module:
36 | ```gradle
37 | dependencies {
38 | // please use Latest Version
39 | debugImplementation 'com.facebook.flipper:flipper:0.30.1'
40 | debugImplementation 'com.facebook.soloader:soloader:0.8.0'
41 | releaseImplementation 'com.facebook.flipper:flipper-noop:0.30.1'
42 | }
43 | ```
44 | 2. Add JitPack in your root build.gradle at the end of repositories:
45 | ```gradle
46 | allprojects {
47 | repositories {
48 | ...
49 | maven { url 'https://jitpack.io' }
50 | }
51 | }
52 | ```
53 | 3. Add this plugin library as a dependency in your app's build.gradle file:
54 | ```gradle
55 | dependencies {
56 | // please use Latest Version
57 | debugImplementation 'com.github.ddyos:flipper-plugin-mmkv-viewer:1.0.0'
58 | }
59 | ```
60 | 4. Init the plugin:
61 | ```Kotlin
62 | val client = AndroidFlipperClient.getInstance(this)
63 | client.addPlugin(MMKVFlipperPlugin("other_mmkv"))
64 | client.start()
65 | ```
66 |
67 | ## Android Demo
68 |
69 | See the projects in the [`sample`](/android/sample) folder.
70 |
71 | ## License
72 |
73 | MIT License, as found in the [LICENSE](/LICENSE) file.
74 |
--------------------------------------------------------------------------------
/android/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/android/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn () {
37 | echo "$*"
38 | }
39 |
40 | die () {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save () {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/android/sample/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/android/plugin/src/main/java/com/ddyos/flipper/mmkv/plugin/MMKVFlipperPlugin.kt:
--------------------------------------------------------------------------------
1 | package com.ddyos.flipper.mmkv.plugin
2 |
3 | import android.text.TextUtils
4 | import com.facebook.flipper.core.FlipperConnection
5 | import com.facebook.flipper.core.FlipperObject
6 | import com.facebook.flipper.core.FlipperPlugin
7 | import com.tencent.mmkv.MMKV
8 | import java.util.*
9 |
10 | /**
11 | * Flipper plugin for MMKV, modify from SharedPreferencesFlipperPlugin
12 | */
13 | class MMKVFlipperPlugin : FlipperPlugin {
14 |
15 | companion object {
16 | private const val PLUGIN_ID = "flipper-plugin-mmkv-viewer"
17 |
18 | private fun buildDescriptorForDefault(): List {
19 | val descriptors: MutableList = ArrayList()
20 | descriptors.add(MMKVDescriptor(MMKV.defaultMMKV().mmapID()))
21 | return descriptors
22 | }
23 |
24 | }
25 |
26 | private var mConnection: FlipperConnection? = null
27 | private var mMMKVMap: MutableMap? = null
28 |
29 | constructor (): this(buildDescriptorForDefault())
30 |
31 | @JvmOverloads
32 | constructor(
33 | name: String,
34 | mode: Int = MMKV.SINGLE_PROCESS_MODE,
35 | cryptKey: String? = null
36 | ) : this(
37 | listOf(
38 | MMKVDescriptor(
39 | name,
40 | mode,
41 | cryptKey
42 | )
43 | ))
44 |
45 | /**
46 | * Creates a MMKV plugin for Flipper
47 | *
48 | * @param descriptors A list of [MMKVDescriptor]s that describe the list of
49 | * preferences to retrieve.
50 | */
51 | constructor(descriptors: List) {
52 | mMMKVMap = HashMap(descriptors.size)
53 | for (descriptor in descriptors) {
54 | val preferences = MMKV.mmkvWithID(descriptor.name, descriptor.mode, descriptor.cryptKey)
55 | mMMKVMap!![preferences] = descriptor
56 | }
57 | }
58 |
59 | override fun getId(): String? {
60 | return PLUGIN_ID
61 | }
62 |
63 | private fun getMMKVFor(name: String): MMKV {
64 | for ((key, value) in mMMKVMap!!) {
65 | if (value.name == name) {
66 | return key
67 | }
68 | }
69 | throw IllegalStateException("Unknown shared preferences $name")
70 | }
71 |
72 | private fun getFlipperObjectFor(name: String): FlipperObject? {
73 | return getFlipperObjectFor(getMMKVFor(name))
74 | }
75 |
76 | private fun getFlipperObjectFor(mmkv: MMKV): FlipperObject? {
77 | val builder = FlipperObject.Builder()
78 | val keys = mmkv.allKeys()
79 | keys?.let {
80 | for (key in keys) {
81 | val `val` = getObjectValue(mmkv, key)
82 | builder.put(key, `val`)
83 | }
84 | }
85 | return builder.build()
86 | }
87 |
88 | /**
89 | * get value with object type, because type-erasure inside mmkv
90 | */
91 | private fun getObjectValue(mmkv: MMKV, key: String): Any? {
92 | // string or string-set
93 | val value = mmkv.decodeString(key)
94 | if (!TextUtils.isEmpty(value)) {
95 | return if (value[0].toInt() == 0x01) {
96 | mmkv.decodeStringSet(key)
97 | } else {
98 | value
99 | }
100 | }
101 | // float double
102 | val set = mmkv.decodeStringSet(key)
103 | if (set != null && set.size == 0) {
104 | val valueFloat = mmkv.decodeFloat(key)
105 | val valueDouble = mmkv.decodeDouble(key)
106 | return if (valueFloat.compareTo(0f) == 0 || valueFloat.compareTo(Float.NaN) == 0) {
107 | valueDouble
108 | } else {
109 | valueFloat
110 | }
111 | }
112 | // int long bool
113 | // for bool, true = 1(int), false = 0(int)
114 | val valueInt = mmkv.decodeInt(key)
115 | val valueLong = mmkv.decodeLong(key)
116 | return if (valueInt.toLong() != valueLong) {
117 | valueLong
118 | } else {
119 | valueInt
120 | }
121 | }
122 |
123 | override fun onConnect(connection: FlipperConnection) {
124 | mConnection = connection
125 | connection.receive("getAllSharedPreferences") { params, responder ->
126 | val builder = FlipperObject.Builder()
127 | for ((key, value) in mMMKVMap!!) {
128 | builder.put(value.name, getFlipperObjectFor(key))
129 | }
130 | responder.success(builder.build())
131 | }
132 | connection.receive("getSharedPreferences") { params, responder ->
133 | val name = params.getString("name")
134 | if (name != null) {
135 | responder.success(getFlipperObjectFor(name))
136 | }
137 | }
138 | connection.receive("setSharedPreference") { params, responder ->
139 | val sharedPreferencesName = params.getString(
140 | "sharedPreferencesName")
141 | val preferenceName = params.getString("preferenceName")
142 | val sharedPrefs = getMMKVFor(
143 | sharedPreferencesName)
144 | val originalValue = getObjectValue(sharedPrefs, preferenceName)
145 | val editor = sharedPrefs.edit()
146 | if (originalValue is Boolean) {
147 | editor.putBoolean(preferenceName, params.getBoolean("preferenceValue"))
148 | } else if (originalValue is Long) {
149 | editor.putLong(preferenceName, params.getLong("preferenceValue"))
150 | } else if (originalValue is Int) {
151 | editor.putInt(preferenceName, params.getInt("preferenceValue"))
152 | } else if (originalValue is Float) {
153 | editor.putFloat(preferenceName, params.getFloat("preferenceValue"))
154 | } else if (originalValue is String) {
155 | editor.putString(preferenceName, params.getString("preferenceValue"))
156 | } else {
157 | throw IllegalArgumentException(
158 | "Type not supported: $preferenceName")
159 | }
160 | editor.apply()
161 | responder.success(getFlipperObjectFor(sharedPreferencesName))
162 | }
163 | }
164 |
165 | override fun onDisconnect() {
166 | mConnection = null
167 | }
168 |
169 | override fun runInBackground(): Boolean {
170 | return false
171 | }
172 |
173 | }
--------------------------------------------------------------------------------
/index.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright 2018-present Facebook.
3 | * This source code is licensed under the MIT license found in the
4 | * LICENSE file in the root directory of this source tree.
5 | * @format
6 | */
7 |
8 | import {
9 | Heading,
10 | FlexColumn,
11 | colors,
12 | FlexRow,
13 | ManagedDataInspector,
14 | styled,
15 | Select,
16 | Button,
17 | } from 'flipper';
18 | import {FlipperPlugin} from 'flipper';
19 |
20 | const {clone} = require('lodash');
21 |
22 | type SharedPreferencesChangeEvent = {|
23 | preferences: string,
24 | name: string,
25 | time: number,
26 | deleted: boolean,
27 | value: string,
28 | |};
29 |
30 | export type SharedPreferences = {|
31 | [name: string]: any,
32 | |};
33 |
34 | type SharedPreferencesEntry = {
35 | preferences: SharedPreferences,
36 | changesList: Array,
37 | };
38 |
39 | type SharedPreferencesMap = {
40 | [name: string]: SharedPreferencesEntry,
41 | };
42 |
43 | type SharedPreferencesState = {|
44 | selectedPreferences: ?string,
45 | sharedPreferences: SharedPreferencesMap,
46 | |};
47 |
48 | const InspectorColumn = styled(FlexColumn)({
49 | flexGrow: 0.2,
50 | });
51 |
52 | const RootColumn = styled(FlexColumn)({
53 | paddingLeft: '16px',
54 | paddingRight: '16px',
55 | paddingTop: '16px',
56 | });
57 |
58 | const ButtonGroupContainer = styled(FlexRow)({
59 | paddingLeft: '16px',
60 | paddingRight: '16px',
61 | paddingBottom: '16px',
62 | });
63 |
64 | export default class extends FlipperPlugin {
65 | state = {
66 | selectedPreferences: null,
67 | sharedPreferences: {},
68 | };
69 |
70 | reducers = {
71 | UpdateSharedPreferences(state: SharedPreferencesState, results: Object) {
72 | const update = results.update;
73 | const entry = state.sharedPreferences[update.name] || {changesList: []};
74 | entry.preferences = update.preferences;
75 | state.sharedPreferences[update.name] = entry;
76 | return {
77 | selectedPreferences: state.selectedPreferences || update.name,
78 | sharedPreferences: state.sharedPreferences,
79 | };
80 | },
81 |
82 | ChangeSharedPreferences(state: SharedPreferencesState, event: Object) {
83 | const change = event.change;
84 | const entry = state.sharedPreferences[change.preferences];
85 | if (entry == null) {
86 | return state;
87 | }
88 | if (change.deleted) {
89 | delete entry.preferences[change.name];
90 | } else {
91 | entry.preferences[change.name] = change.value;
92 | }
93 | entry.changesList = [change, ...entry.changesList];
94 | return {
95 | selectedPreferences: state.selectedPreferences,
96 | sharedPreferences: state.sharedPreferences,
97 | };
98 | },
99 |
100 | UpdateSelectedSharedPreferences(
101 | state: SharedPreferencesState,
102 | event: Object,
103 | ) {
104 | return {
105 | selectedPreferences: event.selected,
106 | sharedPreferences: state.sharedPreferences,
107 | };
108 | },
109 | };
110 |
111 | init() {
112 | this.refresh()
113 | }
114 |
115 | onSharedPreferencesChanged = (path: Array, value: any) => {
116 | const selectedPreferences = this.state.selectedPreferences;
117 | if (selectedPreferences == null) {
118 | return;
119 | }
120 | const entry = this.state.sharedPreferences[selectedPreferences];
121 | if (entry == null) {
122 | return;
123 | }
124 |
125 | const values = entry.preferences;
126 | let newValue = value;
127 | if (path.length === 2 && values) {
128 | newValue = clone(values[path[0]]);
129 | newValue[path[1]] = value;
130 | }
131 | this.client
132 | .call('setSharedPreference', {
133 | sharedPreferencesName: this.state.selectedPreferences,
134 | preferenceName: path[0],
135 | preferenceValue: newValue,
136 | })
137 | .then((results: SharedPreferences) => {
138 | const update = {
139 | name: this.state.selectedPreferences,
140 | preferences: results,
141 | };
142 | this.dispatchAction({update, type: 'UpdateSharedPreferences'});
143 | });
144 | };
145 |
146 | onSharedPreferencesSelected = (selected: string) => {
147 | this.dispatchAction({
148 | selected: selected,
149 | type: 'UpdateSelectedSharedPreferences',
150 | });
151 | };
152 |
153 | refresh = () => {
154 | this.client
155 | .call('getAllSharedPreferences')
156 | .then((results: {[name: string]: SharedPreferences}) => {
157 | Object.entries(results).forEach(([name, prefs]) => {
158 | const update = {name: name, preferences: prefs};
159 | this.dispatchAction({update, type: 'UpdateSharedPreferences'});
160 | });
161 | });
162 |
163 | this.client.subscribe(
164 | 'sharedPreferencesChange',
165 | (change: SharedPreferencesChangeEvent) => {
166 | this.dispatchAction({change, type: 'ChangeSharedPreferences'});
167 | },
168 | );
169 | };
170 |
171 | render() {
172 | const selectedPreferences = this.state.selectedPreferences;
173 | if (selectedPreferences == null) {
174 | return null;
175 | }
176 |
177 | const entry = this.state.sharedPreferences[selectedPreferences];
178 | if (entry == null) {
179 | return null;
180 | }
181 |
182 | return (
183 |
184 |
185 | MMKV File
186 |
197 |
198 |
203 |
204 |
205 |
206 |
207 | Inspector
208 |
209 |
213 |
214 |
215 |
216 | );
217 | }
218 | }
219 |
--------------------------------------------------------------------------------