mirror of
https://github.com/fankes/termux-app.git
synced 2025-09-06 18:55:31 +08:00
Changed: Load termux.properties into a single static app wide TermuxAppSharedProperties class
The `TermuxAppSharedProperties.properties` will exist in `termux-shared` library and only the single static instance will be reloaded whenever needed, instead of different activities and services maintaining their own instances. The classes in `termux-shared` library will also get access to the properties for their own needs. The night mode set in `TermuxApplication` and terminal rows set in `TermuxService` will no longer require loading props from disk. Updating `allow-external-apps` value will now require restarting termux or running `termux-reload-settings` since value will no longer be loaded from disk every time.
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
package com.termux.shared.termux.settings.properties;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.termux.shared.termux.TermuxConstants;
|
||||
|
||||
public class TermuxAppSharedProperties extends TermuxSharedProperties {
|
||||
|
||||
private static TermuxAppSharedProperties properties;
|
||||
|
||||
|
||||
private TermuxAppSharedProperties(@NonNull Context context) {
|
||||
super(context, TermuxConstants.TERMUX_APP_NAME,
|
||||
TermuxPropertyConstants.getTermuxPropertiesFile(), TermuxPropertyConstants.TERMUX_APP_PROPERTIES_LIST,
|
||||
new TermuxSharedProperties.SharedPropertiesParserClient());
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the {@link #properties} and load properties from disk.
|
||||
*
|
||||
* @param context The {@link Context} for operations.
|
||||
* @return Returns the {@link TermuxAppSharedProperties}.
|
||||
*/
|
||||
public static TermuxAppSharedProperties init(@NonNull Context context) {
|
||||
if (properties == null)
|
||||
properties = new TermuxAppSharedProperties(context);
|
||||
|
||||
return properties;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the {@link #properties}.
|
||||
*
|
||||
* @return Returns the {@link TermuxAppSharedProperties}.
|
||||
*/
|
||||
public static TermuxAppSharedProperties getProperties() {
|
||||
return properties;
|
||||
}
|
||||
|
||||
}
|
@@ -355,7 +355,7 @@ public final class TermuxPropertyConstants {
|
||||
/** Defines the set for keys loaded by termux
|
||||
* Setting this to {@code null} will make {@link SharedProperties} throw an exception.
|
||||
* */
|
||||
public static final Set<String> TERMUX_PROPERTIES_LIST = new HashSet<>(Arrays.asList(
|
||||
public static final Set<String> TERMUX_APP_PROPERTIES_LIST = new HashSet<>(Arrays.asList(
|
||||
/* boolean */
|
||||
KEY_DISABLE_HARDWARE_KEYBOARD_SHORTCUTS,
|
||||
KEY_DISABLE_TERMINAL_SESSION_CHANGE_TOAST,
|
||||
|
@@ -8,6 +8,7 @@ import com.termux.shared.logger.Logger;
|
||||
import com.termux.shared.data.DataUtils;
|
||||
import com.termux.shared.settings.properties.SharedProperties;
|
||||
import com.termux.shared.settings.properties.SharedPropertiesParser;
|
||||
import com.termux.shared.termux.TermuxConstants;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
@@ -539,6 +540,9 @@ public abstract class TermuxSharedProperties {
|
||||
|
||||
|
||||
|
||||
public boolean shouldAllowExternalApps() {
|
||||
return (boolean) getInternalPropertyValue(TermuxConstants.PROP_ALLOW_EXTERNAL_APPS, true);
|
||||
}
|
||||
public boolean areHardwareKeyboardShortcutsDisabled() {
|
||||
return (boolean) getInternalPropertyValue(TermuxPropertyConstants.KEY_DISABLE_HARDWARE_KEYBOARD_SHORTCUTS, true);
|
||||
}
|
||||
|
Reference in New Issue
Block a user