mirror of
https://github.com/octopusYan/alist-gui.git
synced 2025-01-31 10:06:43 +08:00
pref: 开机自启改为执行cmd命令
This commit is contained in:
parent
12d9a07320
commit
442940cf05
11
pom.xml
11
pom.xml
@ -94,17 +94,6 @@
|
|||||||
<version>${common-exec.version}</version>
|
<version>${common-exec.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>net.java.dev.jna</groupId>
|
|
||||||
<artifactId>jna</artifactId>
|
|
||||||
<version>${jna.version}</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>net.java.dev.jna</groupId>
|
|
||||||
<artifactId>jna-platform</artifactId>
|
|
||||||
<version>${jna.version}</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- hutool -->
|
<!-- hutool -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>cn.hutool</groupId>
|
<groupId>cn.hutool</groupId>
|
||||||
|
@ -2,13 +2,10 @@ package cn.octopusyan.alistgui.controller;
|
|||||||
|
|
||||||
import atlantafx.base.theme.Theme;
|
import atlantafx.base.theme.Theme;
|
||||||
import cn.octopusyan.alistgui.base.BaseController;
|
import cn.octopusyan.alistgui.base.BaseController;
|
||||||
import cn.octopusyan.alistgui.config.Constants;
|
|
||||||
import cn.octopusyan.alistgui.config.Context;
|
import cn.octopusyan.alistgui.config.Context;
|
||||||
import cn.octopusyan.alistgui.enums.ProxySetup;
|
import cn.octopusyan.alistgui.enums.ProxySetup;
|
||||||
import cn.octopusyan.alistgui.manager.ConfigManager;
|
import cn.octopusyan.alistgui.manager.ConfigManager;
|
||||||
import cn.octopusyan.alistgui.viewModel.SetupViewModel;
|
import cn.octopusyan.alistgui.viewModel.SetupViewModel;
|
||||||
import com.sun.jna.platform.win32.Advapi32Util;
|
|
||||||
import com.sun.jna.platform.win32.WinReg;
|
|
||||||
import javafx.collections.FXCollections;
|
import javafx.collections.FXCollections;
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
import javafx.fxml.Initializable;
|
import javafx.fxml.Initializable;
|
||||||
@ -101,18 +98,6 @@ public class SetupController extends BaseController<SetupViewModel> implements I
|
|||||||
viewModel.languageProperty().bind(languageComboBox.getSelectionModel().selectedItemProperty());
|
viewModel.languageProperty().bind(languageComboBox.getSelectionModel().selectedItemProperty());
|
||||||
viewModel.themeProperty().bind(themeComboBox.getSelectionModel().selectedItemProperty());
|
viewModel.themeProperty().bind(themeComboBox.getSelectionModel().selectedItemProperty());
|
||||||
viewModel.proxySetupProperty().bind(proxySetupComboBox.getSelectionModel().selectedItemProperty());
|
viewModel.proxySetupProperty().bind(proxySetupComboBox.getSelectionModel().selectedItemProperty());
|
||||||
|
|
||||||
autoStartCheckBox.selectedProperty().addListener((_, _, checked) -> {
|
|
||||||
try {
|
|
||||||
if (checked) {
|
|
||||||
Advapi32Util.registrySetStringValue(WinReg.HKEY_CURRENT_USER, Constants.REG_AUTO_RUN, Constants.APP_TITLE, Constants.APP_EXE);
|
|
||||||
} else {
|
|
||||||
Advapi32Util.registryDeleteValue(WinReg.HKEY_CURRENT_USER, Constants.REG_AUTO_RUN, Constants.APP_TITLE);
|
|
||||||
}
|
|
||||||
} catch (Throwable e) {
|
|
||||||
logger.error("", e);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
|
80
src/main/java/cn/octopusyan/alistgui/util/Registry.java
Normal file
80
src/main/java/cn/octopusyan/alistgui/util/Registry.java
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
package cn.octopusyan.alistgui.util;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 注册表编辑
|
||||||
|
*
|
||||||
|
* @author octopus_yan
|
||||||
|
*/
|
||||||
|
public class Registry {
|
||||||
|
private static final ProcessesUtil util = ProcessesUtil.init(".");
|
||||||
|
|
||||||
|
public static void setStringValue(Root root, String keyPath, String name, String value) {
|
||||||
|
setValue(root, keyPath, name, DataType.REG_SZ, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void deleteValue(Root root, String keyPath, String name) {
|
||||||
|
name = handleSpaces(name);
|
||||||
|
util.exec(STR."reg \{Operation.DELETE} \{root.path}\\\{keyPath} /v \{name} /f");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setValue(Root root, String keyPath, String name, DataType type, String value) {
|
||||||
|
name = handleSpaces(name);
|
||||||
|
value = handleSpaces(value);
|
||||||
|
util.exec(STR."""
|
||||||
|
reg \{Operation.ADD} \{root.path}\\\{keyPath} /v \{name} /t \{type} /d \{value}
|
||||||
|
""");
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String handleSpaces(String str) {
|
||||||
|
if (str.contains(" "))
|
||||||
|
str = STR."\"\{str}\"";
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum Operation {
|
||||||
|
ADD,
|
||||||
|
COMPARE,
|
||||||
|
COPY,
|
||||||
|
DELETE,
|
||||||
|
EXPORT,
|
||||||
|
IMPORT,
|
||||||
|
LOAD,
|
||||||
|
QUERY,
|
||||||
|
RESTORE,
|
||||||
|
SAVE,
|
||||||
|
UNLOAD,
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum Root {
|
||||||
|
HKCR("HKEY_CLASSES_ROOT"),
|
||||||
|
HKCU("HKEY_CURRENT_USER"),
|
||||||
|
HKLM("HKEY_LOCAL_MACHINE"),
|
||||||
|
HKU("HKEY_USERS"),
|
||||||
|
HKCC("HKEY_CURRENT_CONFIG"),
|
||||||
|
;
|
||||||
|
|
||||||
|
private final String path;
|
||||||
|
|
||||||
|
Root(String path) {
|
||||||
|
this.path = path;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPath() {
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum DataType {
|
||||||
|
REG_SZ,
|
||||||
|
REG_MULTI_SZ,
|
||||||
|
REG_DWORD_BIG_ENDIAN,
|
||||||
|
REG_DWORD,
|
||||||
|
REG_BINARY,
|
||||||
|
REG_DWORD_LITTLE_ENDIAN,
|
||||||
|
REG_LINK,
|
||||||
|
REG_FULL_RESOURCE_DESCRIPTOR,
|
||||||
|
REG_EXPAND_SZ,
|
||||||
|
;
|
||||||
|
}
|
||||||
|
}
|
@ -2,12 +2,14 @@ package cn.octopusyan.alistgui.viewModel;
|
|||||||
|
|
||||||
import atlantafx.base.theme.Theme;
|
import atlantafx.base.theme.Theme;
|
||||||
import cn.octopusyan.alistgui.base.BaseViewModel;
|
import cn.octopusyan.alistgui.base.BaseViewModel;
|
||||||
|
import cn.octopusyan.alistgui.config.Constants;
|
||||||
import cn.octopusyan.alistgui.config.Context;
|
import cn.octopusyan.alistgui.config.Context;
|
||||||
import cn.octopusyan.alistgui.enums.ProxySetup;
|
import cn.octopusyan.alistgui.enums.ProxySetup;
|
||||||
import cn.octopusyan.alistgui.manager.ConfigManager;
|
import cn.octopusyan.alistgui.manager.ConfigManager;
|
||||||
import cn.octopusyan.alistgui.manager.http.HttpUtil;
|
import cn.octopusyan.alistgui.manager.http.HttpUtil;
|
||||||
import cn.octopusyan.alistgui.task.ProxyCheckTask;
|
import cn.octopusyan.alistgui.task.ProxyCheckTask;
|
||||||
import cn.octopusyan.alistgui.task.listener.TaskListener;
|
import cn.octopusyan.alistgui.task.listener.TaskListener;
|
||||||
|
import cn.octopusyan.alistgui.util.Registry;
|
||||||
import cn.octopusyan.alistgui.view.alert.AlertUtil;
|
import cn.octopusyan.alistgui.view.alert.AlertUtil;
|
||||||
import javafx.beans.property.*;
|
import javafx.beans.property.*;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
@ -35,8 +37,19 @@ public class SetupViewModel extends BaseViewModel {
|
|||||||
public SetupViewModel() {
|
public SetupViewModel() {
|
||||||
theme.bindBidirectional(Context.themeProperty());
|
theme.bindBidirectional(Context.themeProperty());
|
||||||
theme.addListener((_, _, newValue) -> ConfigManager.theme(newValue));
|
theme.addListener((_, _, newValue) -> ConfigManager.theme(newValue));
|
||||||
autoStart.addListener((_, _, newValue) -> ConfigManager.autoStart(newValue));
|
|
||||||
silentStartup.addListener((_, _, newValue) -> ConfigManager.silentStartup(newValue));
|
silentStartup.addListener((_, _, newValue) -> ConfigManager.silentStartup(newValue));
|
||||||
|
autoStart.addListener((_, _, newValue) -> {
|
||||||
|
try {
|
||||||
|
if (newValue) {
|
||||||
|
Registry.setStringValue(Registry.Root.HKCU, Constants.REG_AUTO_RUN, Constants.APP_TITLE, Constants.APP_EXE);
|
||||||
|
} else {
|
||||||
|
Registry.deleteValue(Registry.Root.HKCU, Constants.REG_AUTO_RUN, Constants.APP_TITLE);
|
||||||
|
}
|
||||||
|
} catch (Throwable e) {
|
||||||
|
log.error("", e);
|
||||||
|
}
|
||||||
|
ConfigManager.autoStart(newValue);
|
||||||
|
});
|
||||||
proxySetup.addListener((_, _, newValue) -> ConfigManager.proxySetup(newValue));
|
proxySetup.addListener((_, _, newValue) -> ConfigManager.proxySetup(newValue));
|
||||||
proxyTestUrl.addListener((_, _, newValue) -> ConfigManager.proxyTestUrl(newValue));
|
proxyTestUrl.addListener((_, _, newValue) -> ConfigManager.proxyTestUrl(newValue));
|
||||||
proxyHost.addListener((_, _, newValue) -> ConfigManager.proxyHost(newValue));
|
proxyHost.addListener((_, _, newValue) -> ConfigManager.proxyHost(newValue));
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
module cn.octopusyan.alistgui {
|
module cn.octopusyan.alistgui {
|
||||||
requires java.net.http;
|
requires java.net.http;
|
||||||
requires com.sun.jna.platform;
|
|
||||||
requires javafx.controls;
|
requires javafx.controls;
|
||||||
requires javafx.fxml;
|
requires javafx.fxml;
|
||||||
requires javafx.graphics;
|
requires javafx.graphics;
|
||||||
|
Loading…
Reference in New Issue
Block a user