mirror of https://github.com/termux/termux-app
Added: Add support for ~/.termux/termux.float.properties
This commit is contained in:
parent
9f1203f049
commit
bc779d2ffb
|
@ -9,6 +9,7 @@ import com.termux.shared.terminal.io.extrakeys.ExtraKeysInfo;
|
|||
import com.termux.shared.logger.Logger;
|
||||
import com.termux.shared.settings.properties.TermuxPropertyConstants;
|
||||
import com.termux.shared.settings.properties.TermuxSharedProperties;
|
||||
import com.termux.shared.termux.TermuxConstants;
|
||||
|
||||
import org.json.JSONException;
|
||||
|
||||
|
@ -26,7 +27,8 @@ public class TermuxAppSharedProperties extends TermuxSharedProperties {
|
|||
private static final String LOG_TAG = "TermuxAppSharedProperties";
|
||||
|
||||
public TermuxAppSharedProperties(@Nonnull Context context) {
|
||||
super(context);
|
||||
super(context, TermuxConstants.TERMUX_APP_NAME, TermuxPropertyConstants.getTermuxPropertiesFile(),
|
||||
TermuxPropertyConstants.TERMUX_PROPERTIES_LIST, new SharedPropertiesParserClient());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -110,7 +112,8 @@ public class TermuxAppSharedProperties extends TermuxSharedProperties {
|
|||
* Load the {@link TermuxPropertyConstants#KEY_TERMINAL_TRANSCRIPT_ROWS} value from termux properties file on disk.
|
||||
*/
|
||||
public static int getTerminalTranscriptRows(Context context) {
|
||||
return (int) TermuxSharedProperties.getInternalPropertyValue(context, TermuxPropertyConstants.KEY_TERMINAL_TRANSCRIPT_ROWS);
|
||||
return (int) TermuxSharedProperties.getInternalPropertyValue(context, TermuxPropertyConstants.getTermuxPropertiesFile(),
|
||||
TermuxPropertyConstants.KEY_TERMINAL_TRANSCRIPT_ROWS, new SharedPropertiesParserClient());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ import com.termux.shared.terminal.TermuxTerminalSessionClientBase;
|
|||
import com.termux.shared.termux.TermuxConstants;
|
||||
import com.termux.app.TermuxService;
|
||||
import com.termux.shared.settings.properties.TermuxPropertyConstants;
|
||||
import com.termux.app.terminal.io.BellHandler;
|
||||
import com.termux.shared.terminal.io.BellHandler;
|
||||
import com.termux.shared.logger.Logger;
|
||||
import com.termux.terminal.TerminalColors;
|
||||
import com.termux.terminal.TerminalSession;
|
||||
|
|
|
@ -140,7 +140,7 @@ public class TermuxTerminalViewClient extends TermuxTerminalViewClientBase {
|
|||
}
|
||||
|
||||
/**
|
||||
* Should be called when {@link com.termux.view.TerminalView#mEmulator}
|
||||
* Should be called when {@link com.termux.view.TerminalView#mEmulator} is set
|
||||
*/
|
||||
@Override
|
||||
public void onEmulatorSet() {
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package com.termux.shared.settings.properties;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.google.common.collect.ImmutableBiMap;
|
||||
import com.termux.shared.termux.TermuxConstants;
|
||||
import com.termux.shared.logger.Logger;
|
||||
|
@ -12,7 +14,7 @@ import java.util.HashSet;
|
|||
import java.util.Set;
|
||||
|
||||
/*
|
||||
* Version: v0.13.0
|
||||
* Version: v0.14.0
|
||||
*
|
||||
* Changelog
|
||||
*
|
||||
|
@ -58,6 +60,9 @@ import java.util.Set;
|
|||
*
|
||||
* - 0.13.0 (2021-08-25)
|
||||
* - Add `*KEY_TERMINAL_MARGIN_HORIZONTAL*` and `*KEY_TERMINAL_MARGIN_VERTICAL*`.
|
||||
*
|
||||
* - 0.14.0 (2021-09-02)
|
||||
* - Add `getTermuxFloatPropertiesFile()`.
|
||||
*/
|
||||
|
||||
/**
|
||||
|
@ -390,11 +395,28 @@ public final class TermuxPropertyConstants {
|
|||
* @return Returns the {@link File} object for termux properties.
|
||||
*/
|
||||
public static File getTermuxPropertiesFile() {
|
||||
String[] possiblePropertiesFileLocations = {
|
||||
return getPropertiesFile(new String[]{
|
||||
TermuxConstants.TERMUX_PROPERTIES_PRIMARY_FILE_PATH,
|
||||
TermuxConstants.TERMUX_PROPERTIES_SECONDARY_FILE_PATH
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
/** Returns the first {@link File} found at
|
||||
* {@link TermuxConstants#TERMUX_FLOAT_PROPERTIES_PRIMARY_FILE_PATH} or
|
||||
* {@link TermuxConstants#TERMUX_FLOAT_PROPERTIES_SECONDARY_FILE_PATH}
|
||||
* from which termux properties can be loaded.
|
||||
* If the {@link File} found is not a regular file or is not readable then null is returned.
|
||||
*
|
||||
* @return Returns the {@link File} object for termux properties.
|
||||
*/
|
||||
public static File getTermuxFloatPropertiesFile() {
|
||||
return getPropertiesFile(new String[]{
|
||||
TermuxConstants.TERMUX_FLOAT_PROPERTIES_PRIMARY_FILE_PATH,
|
||||
TermuxConstants.TERMUX_FLOAT_PROPERTIES_SECONDARY_FILE_PATH
|
||||
});
|
||||
}
|
||||
|
||||
public static File getPropertiesFile(@NonNull String[] possiblePropertiesFileLocations) {
|
||||
File propertiesFile = new File(possiblePropertiesFileLocations[0]);
|
||||
int i = 0;
|
||||
while (!propertiesFile.exists() && i < possiblePropertiesFileLocations.length) {
|
||||
|
@ -405,7 +427,7 @@ public final class TermuxPropertyConstants {
|
|||
if (propertiesFile.isFile() && propertiesFile.canRead()) {
|
||||
return propertiesFile;
|
||||
} else {
|
||||
Logger.logDebug("No readable termux.properties file found");
|
||||
Logger.logDebug("No readable properties file found at: " + Arrays.toString(possiblePropertiesFileLocations));
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,8 @@ package com.termux.shared.settings.properties;
|
|||
import android.content.Context;
|
||||
import android.content.res.Configuration;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.termux.shared.logger.Logger;
|
||||
import com.termux.shared.data.DataUtils;
|
||||
|
||||
|
@ -10,21 +12,25 @@ import java.io.File;
|
|||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
public class TermuxSharedProperties {
|
||||
public abstract class TermuxSharedProperties {
|
||||
|
||||
protected final Context mContext;
|
||||
protected final SharedProperties mSharedProperties;
|
||||
protected final String mLabel;
|
||||
protected final File mPropertiesFile;
|
||||
protected final SharedProperties mSharedProperties;
|
||||
|
||||
public static final String LOG_TAG = "TermuxSharedProperties";
|
||||
|
||||
public TermuxSharedProperties(@Nonnull Context context) {
|
||||
public TermuxSharedProperties(@Nonnull Context context, @NonNull String label, File propertiesFile,
|
||||
@NonNull Set<String> propertiesList, @NonNull SharedPropertiesParser sharedPropertiesParser) {
|
||||
mContext = context;
|
||||
mPropertiesFile = TermuxPropertyConstants.getTermuxPropertiesFile();
|
||||
mSharedProperties = new SharedProperties(context, mPropertiesFile, TermuxPropertyConstants.TERMUX_PROPERTIES_LIST, new SharedPropertiesParserClient());
|
||||
mLabel = label;
|
||||
mPropertiesFile = propertiesFile;
|
||||
mSharedProperties = new SharedProperties(context, mPropertiesFile, propertiesList, sharedPropertiesParser);
|
||||
loadTermuxPropertiesFromDisk();
|
||||
}
|
||||
|
||||
|
@ -162,7 +168,7 @@ public class TermuxSharedProperties {
|
|||
|
||||
/**
|
||||
* Get the internal {@link Object} value for the key passed from the file returned by
|
||||
* {@link TermuxPropertyConstants#getTermuxPropertiesFile()}. The {@link Properties} object is
|
||||
* {@code propertiesFile}. The {@link Properties} object is
|
||||
* read directly from the file and internal value is returned for the property value against the key.
|
||||
*
|
||||
* @param context The context for operations.
|
||||
|
@ -170,8 +176,9 @@ public class TermuxSharedProperties {
|
|||
* @return Returns the {@link Object} object. This will be {@code null} if key is not found or
|
||||
* the object stored against the key is {@code null}.
|
||||
*/
|
||||
public static Object getInternalPropertyValue(Context context, String key) {
|
||||
return SharedProperties.getInternalProperty(context, TermuxPropertyConstants.getTermuxPropertiesFile(), key, new SharedPropertiesParserClient());
|
||||
public static Object getInternalPropertyValue(Context context, File propertiesFile, String key,
|
||||
@NonNull SharedPropertiesParser sharedPropertiesParser) {
|
||||
return SharedProperties.getInternalProperty(context, propertiesFile, key, sharedPropertiesParser);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -588,7 +595,7 @@ public class TermuxSharedProperties {
|
|||
Properties properties = getProperties(true);
|
||||
StringBuilder propertiesDump = new StringBuilder();
|
||||
|
||||
propertiesDump.append("Termux Properties:");
|
||||
propertiesDump.append(mLabel).append(" Termux Properties:");
|
||||
if (properties != null) {
|
||||
for (String key : properties.stringPropertyNames()) {
|
||||
propertiesDump.append("\n").append(key).append(": `").append(properties.get(key)).append("`");
|
||||
|
@ -604,7 +611,7 @@ public class TermuxSharedProperties {
|
|||
HashMap<String, Object> internalProperties = (HashMap<String, Object>) getInternalProperties();
|
||||
StringBuilder internalPropertiesDump = new StringBuilder();
|
||||
|
||||
internalPropertiesDump.append("Termux Internal Properties:");
|
||||
internalPropertiesDump.append(mLabel).append(" Internal Properties:");
|
||||
if (internalProperties != null) {
|
||||
for (String key : internalProperties.keySet()) {
|
||||
internalPropertiesDump.append("\n").append(key).append(": `").append(internalProperties.get(key)).append("`");
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package com.termux.app.terminal.io;
|
||||
package com.termux.shared.terminal.io;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
|
@ -12,7 +12,7 @@ import java.util.IllegalFormatException;
|
|||
import java.util.List;
|
||||
|
||||
/*
|
||||
* Version: v0.27.0
|
||||
* Version: v0.28.0
|
||||
*
|
||||
* Changelog
|
||||
*
|
||||
|
@ -187,6 +187,9 @@ import java.util.List;
|
|||
* `TERMUX_FLOAT_APP.TERMUX_FLOAT_SERVICE_NAME`.
|
||||
* - Added following to `TERMUX_FLOAT_APP.TERMUX_FLOAT_SERVICE`:
|
||||
* `ACTION_STOP_SERVICE`, `ACTION_SHOW`, `ACTION_HIDE`.
|
||||
*
|
||||
* - 0.28.0 (2021-09-02)
|
||||
* - Added `TERMUX_FLOAT_PROPERTIES_PRIMARY_FILE*` and `TERMUX_FLOAT_PROPERTIES_SECONDARY_FILE*`.
|
||||
*/
|
||||
|
||||
/**
|
||||
|
@ -640,6 +643,17 @@ public final class TermuxConstants {
|
|||
public static final File TERMUX_PROPERTIES_SECONDARY_FILE = new File(TERMUX_PROPERTIES_SECONDARY_FILE_PATH);
|
||||
|
||||
|
||||
/** Termux Float app termux.properties primary file path */
|
||||
public static final String TERMUX_FLOAT_PROPERTIES_PRIMARY_FILE_PATH = TERMUX_DATA_HOME_DIR_PATH + "/termux.float.properties"; // Default: "/data/data/com.termux/files/home/.termux/termux.float.properties"
|
||||
/** Termux Float app termux.properties primary file */
|
||||
public static final File TERMUX_FLOAT_PROPERTIES_PRIMARY_FILE = new File(TERMUX_FLOAT_PROPERTIES_PRIMARY_FILE_PATH);
|
||||
|
||||
/** Termux Float app termux.properties secondary file path */
|
||||
public static final String TERMUX_FLOAT_PROPERTIES_SECONDARY_FILE_PATH = TERMUX_CONFIG_HOME_DIR_PATH + "/termux.float.properties"; // Default: "/data/data/com.termux/files/home/.config/termux/termux.float.properties"
|
||||
/** Termux Float app termux.properties secondary file */
|
||||
public static final File TERMUX_FLOAT_PROPERTIES_SECONDARY_FILE = new File(TERMUX_FLOAT_PROPERTIES_SECONDARY_FILE_PATH);
|
||||
|
||||
|
||||
/** Termux app and Termux:Styling colors.properties file path */
|
||||
public static final String TERMUX_COLOR_PROPERTIES_FILE_PATH = TERMUX_DATA_HOME_DIR_PATH + "/colors.properties"; // Default: "/data/data/com.termux/files/home/.termux/colors.properties"
|
||||
/** Termux app and Termux:Styling colors.properties file */
|
||||
|
|
Loading…
Reference in New Issue