mirror of
https://github.com/fankes/termux-app.git
synced 2025-09-10 12:34:08 +08:00
Added: Add constants and functions for termux-widget in TermuxConstants and TermuxPreferenceConstants
This commit is contained in:
@@ -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";
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -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);
|
||||
|
Reference in New Issue
Block a user