Added: Add constants and functions for termux-widget in TermuxConstants and TermuxPreferenceConstants

This commit is contained in:
agnostic-apollo
2021-09-04 08:08:51 +05:00
parent e5c0548942
commit d5ffb116b8
3 changed files with 92 additions and 10 deletions

View File

@@ -1,7 +1,7 @@
package com.termux.shared.settings.preferences;
/*
* Version: v0.13.0
* Version: v0.14.0
*
* Changelog
*
@@ -58,6 +58,9 @@ package com.termux.shared.settings.preferences;
* - Added following to `TERMUX_FLOAT_APP`:
* `KEY_WINDOW_X`, `KEY_WINDOW_Y`, `KEY_WINDOW_WIDTH`, `KEY_WINDOW_HEIGHT`, `KEY_FONTSIZE`,
* `KEY_TERMINAL_VIEW_KEY_LOGGING_ENABLED`.
*
* - 0.14.0 (2021-09-04)
* - Added `TERMUX_WIDGET_APP.KEY_TOKEN`.
*/
/**
@@ -270,6 +273,11 @@ public final class TermuxPreferenceConstants {
*/
public static final String KEY_LOG_LEVEL = "log_level";
/**
* Defines the key for current token for shortcuts.
*/
public static final String KEY_TOKEN = "token";
}
}

View File

@@ -11,6 +11,8 @@ import com.termux.shared.packages.PackageUtils;
import com.termux.shared.settings.preferences.TermuxPreferenceConstants.TERMUX_WIDGET_APP;
import com.termux.shared.termux.TermuxConstants;
import java.util.UUID;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
@@ -74,6 +76,23 @@ public class TermuxWidgetAppSharedPreferences {
public static String getGeneratedToken(@NonNull Context context) {
TermuxWidgetAppSharedPreferences preferences = TermuxWidgetAppSharedPreferences.build(context, true);
if (preferences == null) return null;
return preferences.getGeneratedToken();
}
public String getGeneratedToken() {
String token = SharedPreferenceUtils.getString(mSharedPreferences, TERMUX_WIDGET_APP.KEY_TOKEN, null, true);
if (token == null) {
token = UUID.randomUUID().toString();
SharedPreferenceUtils.setString(mSharedPreferences, TERMUX_WIDGET_APP.KEY_TOKEN, token, false);
}
return token;
}
public int getLogLevel(boolean readFromFile) {
if (readFromFile)
return SharedPreferenceUtils.getInt(mMultiProcessSharedPreferences, TERMUX_WIDGET_APP.KEY_LOG_LEVEL, Logger.DEFAULT_LOG_LEVEL);