Update av alert

This commit is contained in:
crschnick committed 2023-12-27 04:23:11 +00:00
1 parent 404cd744b2
commit 6e3b044fdc
7 files changed
+126 -142

No files matched your search

@@ -1,61 +0,0 @@
package io.xpipe.app.core.check;
import io.xpipe.app.comp.base.MarkdownComp;
import io.xpipe.app.core.*;
import io.xpipe.app.core.mode.OperationMode;
import io.xpipe.app.util.PlatformState;
import io.xpipe.app.util.WindowsRegistry;
import io.xpipe.core.process.OsType;
import javafx.geometry.Insets;
import javafx.scene.control.Alert;
import javafx.scene.control.ButtonBar;
import javafx.scene.control.ButtonType;
import java.nio.file.Files;
import java.util.Optional;
public class AppAvBlockCheck {
private static Optional<String> detect() {
var bitdefender = WindowsRegistry.readString(WindowsRegistry.HKEY_LOCAL_MACHINE,"SOFTWARE\\Bitdefender", "InstallDir");
if (bitdefender.isPresent()) {
return Optional.of("Bitdefender");
}
return Optional.empty();
}
public static void check() throws Throwable {
// Only show this on first launch on windows
if (OsType.getLocal() != OsType.WINDOWS || !AppState.get().isInitialLaunch()) {
return;
}
var found = detect();
if (found.isEmpty()) {
return;
}
PlatformState.initPlatformOrThrow();
AppStyle.init();
AppImages.init();
var a = AppWindowHelper.showBlockingAlert(alert -> {
alert.setTitle(AppI18n.get("antivirusNoticeTitle"));
alert.setAlertType(Alert.AlertType.NONE);
AppResources.with(
AppResources.XPIPE_MODULE,
"misc/antivirus.md",
file -> {
var markdown = new MarkdownComp(Files.readString(file), s -> s.formatted(found.get(), found.get(), AppProperties.get().getVersion(), AppProperties.get().getVersion(), found.get())).prefWidth(550).prefHeight(600).createRegion();
alert.getDialogPane().setContent(markdown);
alert.getDialogPane().setPadding(new Insets(15));
});
alert.getButtonTypes().add(new ButtonType(AppI18n.get("gotIt"), ButtonBar.ButtonData.OK_DONE));
});
a.filter(b -> b.getButtonData().isDefaultButton())
.ifPresentOrElse(buttonType -> {}, () -> OperationMode.halt(1));
}
}
@@ -0,0 +1,116 @@
package io.xpipe.app.core.check;
import io.xpipe.app.comp.base.MarkdownComp;
import io.xpipe.app.core.*;
import io.xpipe.app.core.mode.OperationMode;
import io.xpipe.app.util.PlatformState;
import io.xpipe.app.util.WindowsRegistry;
import io.xpipe.core.process.OsType;
import javafx.geometry.Insets;
import javafx.scene.control.Alert;
import javafx.scene.control.ButtonBar;
import javafx.scene.control.ButtonType;
import lombok.Getter;
import java.nio.file.Files;
import java.util.Optional;
public class AppAvCheck {
@Getter
public static enum AvType {
BITDEFENDER("Bitdefender") {
@Override
public String getDescription() {
return "Bitdefender sometimes isolates XPipe and some shell programs, effectively making it unusable.";
}
@Override
public boolean isActive() {
var bitdefender = WindowsRegistry.readString(WindowsRegistry.HKEY_LOCAL_MACHINE,"SOFTWARE\\Bitdefender", "InstallDir");
return bitdefender.isPresent();
}
},
MALWAREBYTES("Malwarebytes") {
@Override
public String getDescription() {
return "The free Malwarebytes version performs less invasive scans, so it shouldn't be a problem. If you are running the paid Malwarebytes Pro version, you will have access to the `Exploit Protection` under the `Real-time Protection` mode. When this setting is active, any shell access is slowed down, resulting in XPipe becoming very slow.";
}
@Override
public boolean isActive() {
var reg = WindowsRegistry.readString(WindowsRegistry.HKEY_LOCAL_MACHINE,"SOFTWARE\\Malwarebytes", "id");
return reg.isPresent();
}
},
MCAFEE("McAfee") {
@Override
public String getDescription() {
return "McAfee slows down XPipe considerably. It also sometimes preemptively disables some Win32 commands that XPipe depends on, leading to errors.";
}
@Override
public boolean isActive() {
var mcafee = WindowsRegistry.readString(WindowsRegistry.HKEY_LOCAL_MACHINE,"SOFTWARE\\McAfee", "mi");
return mcafee.isPresent();
}
};
private final String name;
AvType(String name) {
this.name = name;
}
public abstract String getDescription();
public abstract boolean isActive();
}
private static Optional<AvType> detect() {
for (AvType value : AvType.values()) {
if (value.isActive()) {
return Optional.of(value);
}
}
return Optional.empty();
}
public static void check() throws Throwable {
// Only show this on first launch on windows
if (OsType.getLocal() != OsType.WINDOWS || !AppState.get().isInitialLaunch()) {
return;
}
var found = detect();
if (found.isEmpty()) {
return;
}
PlatformState.initPlatformOrThrow();
AppStyle.init();
AppImages.init();
var a = AppWindowHelper.showBlockingAlert(alert -> {
alert.setTitle(AppI18n.get("antivirusNoticeTitle"));
alert.setAlertType(Alert.AlertType.NONE);
AppResources.with(
AppResources.XPIPE_MODULE,
"misc/antivirus.md",
file -> {
var markdown = new MarkdownComp(Files.readString(file), s -> {
var t = found.get();
return s.formatted(t.getName(), t.getName(), t.getDescription(), AppProperties.get().getVersion(), AppProperties.get().getVersion(), t.getName());
}).prefWidth(550).prefHeight(600).createRegion();
alert.getDialogPane().setContent(markdown);
alert.getDialogPane().setPadding(new Insets(15));
});
alert.getButtonTypes().add(new ButtonType(AppI18n.get("gotIt"), ButtonBar.ButtonData.OK_DONE));
});
a.filter(b -> b.getButtonData().isDefaultButton())
.ifPresentOrElse(buttonType -> {}, () -> OperationMode.halt(1));
}
}
@@ -1,58 +0,0 @@
package io.xpipe.app.core.check;
import io.xpipe.app.comp.base.MarkdownComp;
import io.xpipe.app.core.*;
import io.xpipe.app.util.PlatformState;
import io.xpipe.app.util.WindowsRegistry;
import io.xpipe.core.process.OsType;
import javafx.geometry.Insets;
import javafx.scene.control.Alert;
import javafx.scene.control.ButtonBar;
import javafx.scene.control.ButtonType;
import java.nio.file.Files;
public class AppMalwarebytesCheck {
private static boolean detect() {
var reg = WindowsRegistry.readString(WindowsRegistry.HKEY_LOCAL_MACHINE,"SOFTWARE\\Malwarebytes", "id");
if (reg.isPresent()) {
return true;
}
return false;
}
public static void check() throws Throwable {
// Only show this on first launch on windows
if (OsType.getLocal() != OsType.WINDOWS || AppCache.get("malwarebytesSeen", Boolean.class,() -> false)) {
return;
}
var found = detect();
if (!found) {
return;
}
PlatformState.initPlatformOrThrow();
AppStyle.init();
AppImages.init();
var a = AppWindowHelper.showBlockingAlert(alert -> {
alert.setTitle(AppI18n.get("malwarebytesNoticeTitle"));
alert.setAlertType(Alert.AlertType.NONE);
AppResources.with(
AppResources.XPIPE_MODULE,
"misc/malwarebytes.md",
file -> {
var markdown = new MarkdownComp(Files.readString(file), s -> s).prefWidth(550).prefHeight(500).createRegion();
alert.getDialogPane().setContent(markdown);
alert.getDialogPane().setPadding(new Insets(15));
});
alert.getButtonTypes().add(new ButtonType(AppI18n.get("gotIt"), ButtonBar.ButtonData.OK_DONE));
});
a.filter(b -> b.getButtonData().isDefaultButton())
.ifPresentOrElse(buttonType -> {}, () -> AppCache.update("malwarebytesSeen", true));
}
}
@@ -3,8 +3,7 @@ package io.xpipe.app.core.mode;
import io.xpipe.app.browser.BrowserModel;
import io.xpipe.app.comp.store.StoreViewState;
import io.xpipe.app.core.*;
import io.xpipe.app.core.check.AppAvBlockCheck;
import io.xpipe.app.core.check.AppMalwarebytesCheck;
import io.xpipe.app.core.check.AppAvCheck;
import io.xpipe.app.ext.ActionProvider;
import io.xpipe.app.issue.TrackEvent;
import io.xpipe.app.prefs.AppPrefs;
@@ -49,8 +48,7 @@ public class BaseMode extends OperationMode {
// Also loaded before antivirus alert to localize that
AppI18n.init();
LicenseProvider.get().init();
AppAvBlockCheck.check();
AppMalwarebytesCheck.check();
AppAvCheck.check();
LocalShell.init();
XPipeDistributionType.init();
AppPrefs.init();
@@ -99,7 +99,7 @@ public class LauncherCommand implements Callable<Integer> {
} catch (Exception ex) {
var cli = XPipeInstallation.getLocalDefaultCliExecutable();
ErrorEvent.fromThrowable(ex).term().description("Unable to connect to existing running daemon instance as it did not respond." +
" Either try to kill the process xpiped manually or use the command " + cli + " daemon stop --force.").handle();
" Either try to kill the process xpiped manually or use the command \"" + cli + "\" daemon stop --force.").handle();
}
}