From 0d3c04b82204ae94668ad4ab90c1c7975c19234f Mon Sep 17 00:00:00 2001 From: crschnick Date: Fri, 11 Apr 2025 09:44:19 +0000 Subject: [PATCH] Rework [stage] --- .../comp/store/StoreEntryBatchSelectComp.java | 33 +++++++++++------ .../xpipe/app/comp/store/StoreViewState.java | 36 ++++++++++++------- .../base/script/PredefinedScriptGroup.java | 4 +-- .../base/script/PredefinedScriptStore.java | 6 ++++ .../base/resources/scripts/system_health.sh | 26 ++++++++++++++ version | 2 +- 6 files changed, 81 insertions(+), 26 deletions(-) create mode 100644 ext/base/src/main/resources/io/xpipe/ext/base/resources/scripts/system_health.sh diff --git a/app/src/main/java/io/xpipe/app/comp/store/StoreEntryBatchSelectComp.java b/app/src/main/java/io/xpipe/app/comp/store/StoreEntryBatchSelectComp.java index f6c00c673..3de8a79c7 100644 --- a/app/src/main/java/io/xpipe/app/comp/store/StoreEntryBatchSelectComp.java +++ b/app/src/main/java/io/xpipe/app/comp/store/StoreEntryBatchSelectComp.java @@ -2,7 +2,9 @@ package io.xpipe.app.comp.store; import io.xpipe.app.comp.SimpleComp; +import io.xpipe.app.util.BooleanScope; import javafx.application.Platform; +import javafx.beans.property.SimpleBooleanProperty; import javafx.collections.ListChangeListener; import javafx.scene.control.CheckBox; import javafx.scene.input.MouseButton; @@ -19,27 +21,36 @@ public class StoreEntryBatchSelectComp extends SimpleComp { @Override protected Region createSimple() { + var selfUpdate = new SimpleBooleanProperty(false); var cb = new CheckBox(); cb.setAllowIndeterminate(true); cb.selectedProperty().addListener((observable, oldValue, newValue) -> { - if (newValue) { - StoreViewState.get().selectBatchMode(section); - } else { - StoreViewState.get().unselectBatchMode(section); - } + BooleanScope.executeExclusive(selfUpdate, () -> { + if (newValue) { + StoreViewState.get().selectBatchMode(section); + } else { + StoreViewState.get().unselectBatchMode(section); + } + }); }); StoreViewState.get().getBatchModeSelection().getList().addListener((ListChangeListener< ? super StoreEntryWrapper>) c -> { + if (selfUpdate.get()) { + return; + } + Platform.runLater(() -> { - update(cb); + externalUpdate(cb); }); }); section.getShownChildren().getList().addListener((ListChangeListener) c -> { - if (cb.isSelected()) { - StoreViewState.get().selectBatchMode(section); - } + BooleanScope.executeExclusive(selfUpdate, () -> { + if (cb.isSelected()) { + StoreViewState.get().selectBatchMode(section); + } + }); }); cb.getStyleClass().add("batch-mode-selector"); @@ -52,7 +63,7 @@ public class StoreEntryBatchSelectComp extends SimpleComp { return cb; } - private void update(CheckBox checkBox) { + private void externalUpdate(CheckBox checkBox) { var isSelected = StoreViewState.get().isSectionSelected(section); checkBox.setSelected(isSelected); if (section.getShownChildren().getList().size() == 0) { @@ -62,7 +73,7 @@ public class StoreEntryBatchSelectComp extends SimpleComp { var count = section.getShownChildren().getList().stream() .filter(c -> - StoreViewState.get().getBatchModeSelection().getList().contains(c.getWrapper())) + StoreViewState.get().isBatchModeSelected(c.getWrapper())) .count(); checkBox.setIndeterminate( count > 0 && count != section.getShownChildren().getList().size()); diff --git a/app/src/main/java/io/xpipe/app/comp/store/StoreViewState.java b/app/src/main/java/io/xpipe/app/comp/store/StoreViewState.java index 8317a7606..13efc38ee 100644 --- a/app/src/main/java/io/xpipe/app/comp/store/StoreViewState.java +++ b/app/src/main/java/io/xpipe/app/comp/store/StoreViewState.java @@ -50,6 +50,8 @@ public class StoreViewState { @Getter private final DerivedObservableList batchModeSelection = DerivedObservableList.synchronizedArrayList(true); + private final Set batchModeSelectionSet = new HashSet<>(); + @Getter private boolean initialized = false; @@ -107,10 +109,13 @@ public class StoreViewState { return INSTANCE; } + public boolean isBatchModeSelected(StoreEntryWrapper entry) { + return batchModeSelectionSet.contains(entry); + } + public void selectBatchMode(StoreSection section) { - System.out.println("Select " + section.getWrapper()); var wrapper = section.getWrapper(); - if (wrapper != null && !batchModeSelection.getList().contains(wrapper)) { + if (wrapper != null && !batchModeSelectionSet.contains(wrapper)) { batchModeSelection.getList().add(wrapper); } if (wrapper == null @@ -134,11 +139,10 @@ public class StoreViewState { public boolean isSectionSelected(StoreSection section) { if (section.getWrapper() == null) { - var batchSet = new HashSet<>(batchModeSelection.getList()); var childSet = section.getShownChildren().getList().stream() .map(s -> s.getWrapper()) .toList(); - return batchSet.containsAll(childSet); + return batchModeSelectionSet.containsAll(childSet); } return getBatchModeSelection().getList().contains(section.getWrapper()); @@ -150,17 +154,10 @@ public class StoreViewState { } private void initSections() { - // Faster selection check with a hash set - var set = new HashSet<>(batchModeSelection.getList()); - batchModeSelection.getList().addListener((ListChangeListener) c -> { - set.clear(); - set.addAll(c.getList()); - }); - try { currentTopLevelSection = StoreSection.createTopLevel( allEntries, - set, + batchModeSelectionSet, storeEntryWrapper -> true, filter, activeCategory, @@ -193,6 +190,21 @@ public class StoreViewState { } private void initBatchListeners() { + batchModeSelection.getList().addListener((ListChangeListener) c -> { + if (c.getList().isEmpty()) { + batchModeSelectionSet.clear(); + return; + } + + while (c.next()) { + if (c.wasAdded()) { + batchModeSelectionSet.addAll(c.getAddedSubList()); + } else if (c.wasRemoved()) { + c.getRemoved().forEach(batchModeSelectionSet::remove); + } + } + }); + allEntries.getList().addListener((ListChangeListener) c -> { batchModeSelection.getList().retainAll(c.getList()); }); diff --git a/ext/base/src/main/java/io/xpipe/ext/base/script/PredefinedScriptGroup.java b/ext/base/src/main/java/io/xpipe/ext/base/script/PredefinedScriptGroup.java index 2285a87f6..4c8aa2070 100644 --- a/ext/base/src/main/java/io/xpipe/ext/base/script/PredefinedScriptGroup.java +++ b/ext/base/src/main/java/io/xpipe/ext/base/script/PredefinedScriptGroup.java @@ -7,8 +7,8 @@ import lombok.Setter; @Getter public enum PredefinedScriptGroup { - MANAGEMENT("Management", "Some commonly used management scripts", true), - FILES("Files", "Scripts for files", true); + MANAGEMENT("Management", "Sample management scripts", true), + FILES("Files", "Sample scripts for files", true); private final String name; private final String description; diff --git a/ext/base/src/main/java/io/xpipe/ext/base/script/PredefinedScriptStore.java b/ext/base/src/main/java/io/xpipe/ext/base/script/PredefinedScriptStore.java index cf21b0e02..51ae013b9 100644 --- a/ext/base/src/main/java/io/xpipe/ext/base/script/PredefinedScriptStore.java +++ b/ext/base/src/main/java/io/xpipe/ext/base/script/PredefinedScriptStore.java @@ -40,6 +40,12 @@ public enum PredefinedScriptStore { .minimumDialect(null) .commands(file(("git_config.sh"))) .runnableScript(true) + .build()), + SYSTEM_HEALTH_STATUS("System health status", () -> SimpleScriptStore.builder() + .group(PredefinedScriptGroup.MANAGEMENT.getEntry()) + .minimumDialect(ShellDialects.SH) + .commands(file(("system_health.sh"))) + .initScript(true) .build()); private final String name; diff --git a/ext/base/src/main/resources/io/xpipe/ext/base/resources/scripts/system_health.sh b/ext/base/src/main/resources/io/xpipe/ext/base/resources/scripts/system_health.sh new file mode 100644 index 000000000..80d7cdc12 --- /dev/null +++ b/ext/base/src/main/resources/io/xpipe/ext/base/resources/scripts/system_health.sh @@ -0,0 +1,26 @@ +DELIMITER="-------------------------------------" + +hostname -f &> /dev/null && printf "Hostname : $(hostname -f)" || printf "Hostname : $(hostname -s)" + +[ -f /etc/os-release ] && echo $(egrep -w "NAME|VERSION" /etc/os-release|awk -F= '{ print $2 }'|sed 's/"//g') || cat /etc/system-release + +echo -e "Kernel Version :" $(uname -r) +printf "OS Architecture :"$(arch | grep x86_64 &> /dev/null) && printf " 64 Bit OS\n" || printf " 32 Bit OS\n" + +echo -en "System Uptime : " $(uptime -p) +echo -e "\nCurrent System Date & Time : "$(date +%c) + +echo -e "Total Swap Memory in MiB : "$(grep -w SwapTotal /proc/meminfo|awk '{print $2/1024}')", in GiB : "\ +$(grep -w SwapTotal /proc/meminfo|awk '{print $2/1024/1024}') +echo -e "Swap Free Memory in MiB : "$(grep -w SwapFree /proc/meminfo|awk '{print $2/1024}')", in GiB : "\ +$(grep -w SwapFree /proc/meminfo|awk '{print $2/1024/1024}') + +echo -e "\n\nMost Recent 3 Reboots" +echo -e "$DELIMITER$DELIMITER" +last -x 2> /dev/null|grep reboot 1> /dev/null && /usr/bin/last -x 2> /dev/null|grep reboot|head -3 || \ +echo -e "No reboot events are recorded." + +echo -e "\n\nMost Recent 3 Shutdowns" +echo -e "$DELIMITER$DELIMITER" +last -x 2> /dev/null|grep shutdown 1> /dev/null && /usr/bin/last -x 2> /dev/null|grep shutdown|head -3 || \ +echo -e "No shutdown events are recorded." diff --git a/version b/version index 4acbde0ad..837fd6a6f 100644 --- a/version +++ b/version @@ -1 +1 @@ -16.0-24 +16.0-25