Skip to content

Commit

Permalink
Build and App setting to select bytecode or not for Gutenberg
Browse files Browse the repository at this point in the history
To use:
0. Use a `debug` build variant, the setting is only avail there
1. Put wp.OFFER_GUTENBERG_TEXT_JS_BUNDLE=true in gradle.settings to
reveal the App setting
2. Use the App setting to select bytecode or not for Gutenberg's JS
bundle
  • Loading branch information
hypest committed Apr 8, 2020
1 parent fd2305f commit cf7de98
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 3 deletions.
1 change: 1 addition & 0 deletions WordPress/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ android {
debug {
minifyEnabled false
buildConfigField "String", "APP_PN_KEY", "\"org.wordpress.android.debug.build\""
buildConfigField "boolean", "OFFER_GUTENBERG_TEXT_JS_BUNDLE_SETTING", (rootProject.ext.has("offerGutenbergTextJsBundle") ? rootProject.ext.offerGutenbergTextJsBundle : false).toString()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1958,6 +1958,7 @@ public Fragment getItem(int position) {
boolean supportsStockPhotos = mSite.isUsingWpComRestApi();
return GutenbergEditorFragment.newInstance("",
"",
AppPrefs.isGutenbergUseBytecode(),
postType,
mIsNewPost,
wpcomLocaleSlug,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import androidx.annotation.NonNull;

import org.wordpress.android.BuildConfig;
import org.wordpress.android.WordPress;
import org.wordpress.android.analytics.AnalyticsTracker;
import org.wordpress.android.analytics.AnalyticsTracker.Stat;
Expand Down Expand Up @@ -124,6 +125,9 @@ public enum DeletablePrefKey implements PrefKey {
SHOULD_AUTO_ENABLE_GUTENBERG_FOR_THE_NEW_POSTS_PHASE_2,
GUTENBERG_OPT_IN_DIALOG_SHOWN,

// Debugging facility
GUTENBERG_USE_BYTECODE,

IS_QUICK_START_NOTICE_REQUIRED,

POST_LIST_AUTHOR_FILTER,
Expand Down Expand Up @@ -800,6 +804,14 @@ public static void setGutenbergInfoPopupDisplayed(String siteURL, boolean isDisp
editor.apply();
}

public static boolean isGutenbergUseBytecode() {
return BuildConfig.OFFER_GUTENBERG_TEXT_JS_BUNDLE_SETTING && getBoolean(DeletablePrefKey.GUTENBERG_USE_BYTECODE, false);
}

public static void setGutenbergUseBytecode(boolean useBytecode) {
setBoolean(DeletablePrefKey.GUTENBERG_USE_BYTECODE, useBytecode);
}

public static void setVideoOptimizeWidth(int width) {
setInt(DeletablePrefKey.VIDEO_OPTIMIZE_WIDTH, width);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public class AppSettingsFragment extends PreferenceFragment
private DetailListPreference mVideoEncorderBitratePref;
private PreferenceScreen mPrivacySettings;
private WPSwitchPreference mStripImageLocation;
private WPSwitchPreference mGutenbergBytecode;

@Inject SiteStore mSiteStore;
@Inject AccountStore mAccountStore;
Expand Down Expand Up @@ -165,6 +166,14 @@ public boolean onPreferenceChange(Preference preference, Object newValue) {
if (!BuildConfig.OFFER_GUTENBERG) {
removeExperimentalCategory();
}

if (BuildConfig.OFFER_GUTENBERG_TEXT_JS_BUNDLE_SETTING) {
mGutenbergBytecode = new WPSwitchPreference(getPreferenceScreen().getContext(), null);
mGutenbergBytecode.setTitle("Use bytecode JS Gutenberg bundle");
mGutenbergBytecode.setOnPreferenceChangeListener(this);
mGutenbergBytecode.setChecked(AppPrefs.isGutenbergUseBytecode());
getPreferenceScreen().addPreference(mGutenbergBytecode);
}
}

private void removeExperimentalCategory() {
Expand Down Expand Up @@ -306,6 +315,8 @@ public boolean onPreferenceChange(Preference preference, Object newValue) {
AppThemeUtils.Companion.setAppTheme(getActivity(), (String) newValue);
// restart activity to make sure changes are applied to PreferenceScreen
getActivity().recreate();
} else if (preference == mGutenbergBytecode) {
AppPrefs.setGutenbergUseBytecode((Boolean) newValue);
}
return true;
}
Expand Down
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ plugins {
apply plugin: 'com.automattic.android.fetchstyle'

project.ext.buildGutenbergFromSource = project.properties.getOrDefault('wp.BUILD_GUTENBERG_FROM_SOURCE', false).toBoolean()
project.ext.offerGutenbergTextJsBundle = project.properties.getOrDefault('wp.OFFER_GUTENBERG_TEXT_JS_BUNDLE', false).toBoolean()

allprojects {
apply plugin: 'checkstyle'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,28 @@
public class GutenbergContainerFragment extends Fragment {
public static final String TAG = "gutenberg_container_fragment_tag";

private static final String ARG_USE_BYTECODE = "param_use_bytecode";
private static final String ARG_POST_TYPE = "param_post_type";
private static final String ARG_IS_NEW_POST = "param_is_new_post";
private static final String ARG_LOCALE = "param_locale";
private static final String ARG_TRANSLATIONS = "param_translations";
private static final String ARG_PREFERRED_COLOR_SCHEME = "param_preferred_color_scheme";

private boolean mUseBytecode;
private boolean mHtmlModeEnabled;
private boolean mHasReceivedAnyContent;

private WPAndroidGlueCode mWPAndroidGlueCode;

public static GutenbergContainerFragment newInstance(String postType,
public static GutenbergContainerFragment newInstance(boolean userBytecode,
String postType,
boolean isNewPost,
String localeString,
Bundle translations,
boolean isDarkMode) {
GutenbergContainerFragment fragment = new GutenbergContainerFragment();
Bundle args = new Bundle();
args.putBoolean(ARG_USE_BYTECODE, userBytecode);
args.putString(ARG_POST_TYPE, postType);
args.putBoolean(ARG_IS_NEW_POST, isNewPost);
args.putString(ARG_LOCALE, localeString);
Expand Down Expand Up @@ -82,6 +86,7 @@ public void attachToContainer(ViewGroup viewGroup, OnMediaLibraryButtonListener
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

boolean userBytecode = getArguments() != null && getArguments().getBoolean(ARG_USE_BYTECODE);
String postType = getArguments().getString(ARG_POST_TYPE);
boolean isNewPost = getArguments() != null && getArguments().getBoolean(ARG_IS_NEW_POST);
String localeString = getArguments().getString(ARG_LOCALE);
Expand All @@ -92,6 +97,7 @@ public void onCreate(Bundle savedInstanceState) {
mWPAndroidGlueCode.onCreate(getContext());
mWPAndroidGlueCode.onCreateView(
getContext(),
userBytecode,
mHtmlModeEnabled,
getActivity().getApplication(),
BuildConfig.DEBUG,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public class GutenbergEditorFragment extends EditorFragmentAbstract implements
private static final String GUTENBERG_EDITOR_NAME = "gutenberg";
private static final String KEY_HTML_MODE_ENABLED = "KEY_HTML_MODE_ENABLED";
private static final String KEY_EDITOR_DID_MOUNT = "KEY_EDITOR_DID_MOUNT";
private static final String ARG_USE_BYTECODE = "param_use_bytecode";
private static final String ARG_POST_TYPE = "param_post_type";
private static final String ARG_IS_NEW_POST = "param_is_new_post";
private static final String ARG_LOCALE_SLUG = "param_locale_slug";
Expand Down Expand Up @@ -107,6 +108,7 @@ public class GutenbergEditorFragment extends EditorFragmentAbstract implements

public static GutenbergEditorFragment newInstance(String title,
String content,
boolean useBytecode,
String postType,
boolean isNewPost,
String localeSlug,
Expand All @@ -115,6 +117,7 @@ public static GutenbergEditorFragment newInstance(String title,
Bundle args = new Bundle();
args.putString(ARG_PARAM_TITLE, title);
args.putString(ARG_PARAM_CONTENT, content);
args.putBoolean(ARG_USE_BYTECODE, useBytecode);
args.putString(ARG_POST_TYPE, postType);
args.putBoolean(ARG_IS_NEW_POST, isNewPost);
args.putString(ARG_LOCALE_SLUG, localeSlug);
Expand Down Expand Up @@ -215,14 +218,16 @@ public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

if (getGutenbergContainerFragment() == null) {
boolean useBytecode = getArguments().getBoolean(ARG_USE_BYTECODE);
String postType = getArguments().getString(ARG_POST_TYPE);
boolean isNewPost = getArguments().getBoolean(ARG_IS_NEW_POST);
String localeSlug = getArguments().getString(ARG_LOCALE_SLUG);

FragmentManager fragmentManager = getChildFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
GutenbergContainerFragment gutenbergContainerFragment =
GutenbergContainerFragment.newInstance(postType,
GutenbergContainerFragment.newInstance(useBytecode,
postType,
isNewPost,
localeSlug,
getTranslations(),
Expand Down

0 comments on commit cf7de98

Please sign in to comment.