Search in sources :

Example 1 with ConfigInfo

use of lee.study.down.model.ConfigInfo in project proxyee-down by monkeyWie.

the class ConfigContent method init.

public void init() {
    if (FileUtil.exists(HttpDownConstant.CONFIG_PATH)) {
        try (InputStream inputStream = new FileInputStream(HttpDownConstant.CONFIG_PATH)) {
            set(JSON.parseObject(inputStream, ConfigInfo.class));
        } catch (Exception e) {
            if (!(e instanceof FileNotFoundException)) {
                try {
                    FileUtil.deleteIfExists(HttpDownConstant.CONFIG_PATH);
                } catch (IOException e1) {
                    e1.printStackTrace();
                }
            }
            LOGGER.error("加载配置文件失败:", e);
        }
    }
    if (configContent == null || configContent.getProxyPort() == 0) {
        set(new ConfigInfo());
        save();
    }
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) ConfigInfo(lee.study.down.model.ConfigInfo) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Example 2 with ConfigInfo

use of lee.study.down.model.ConfigInfo in project proxyee-down by monkeyWie.

the class HttpDownApplication method start.

@Override
public void start(Stage stage) throws Exception {
    initHandle();
    this.stage = stage;
    Platform.setImplicitExit(false);
    isSupportBrowser = isSupportBrowser();
    SwingUtilities.invokeLater(this::addTray);
    // webview加载
    if (ContentManager.CONFIG.get().getUiModel() == 1 && isSupportBrowser) {
        initBrowser();
    }
    stage.setTitle("proxyee-down-" + version);
    Rectangle2D bounds = Screen.getPrimary().getVisualBounds();
    ConfigInfo cf = ContentManager.CONFIG.get();
    stage.setX(cf.getGuiX() >= 0 ? cf.getGuiX() : bounds.getMinX());
    stage.setY(cf.getGuiY() >= 0 ? cf.getGuiY() : bounds.getMinY());
    stage.setWidth(cf.getGuiWidth() >= 0 ? cf.getGuiWidth() : bounds.getWidth());
    stage.setHeight(cf.getGuiHeight() >= 0 ? cf.getGuiHeight() : bounds.getHeight());
    stage.getIcons().add(new Image(Thread.currentThread().getContextClassLoader().getResourceAsStream("favicon.png")));
    // 关闭窗口监听
    stage.setOnCloseRequest(event -> {
        event.consume();
        close();
    });
}
Also used : Rectangle2D(javafx.geometry.Rectangle2D) ConfigInfo(lee.study.down.model.ConfigInfo) Image(javafx.scene.image.Image)

Example 3 with ConfigInfo

use of lee.study.down.model.ConfigInfo in project proxyee-down by monkeyWie.

the class HttpDownController method setConfigInfo.

@RequestMapping("/setConfigInfo")
public ResultInfo setConfigInfo(@RequestBody ConfigForm configForm) {
    ResultInfo resultInfo = new ResultInfo();
    int beforePort = ContentManager.CONFIG.get().getProxyPort();
    boolean beforeSecProxyEnable = ContentManager.CONFIG.get().isSecProxyEnable();
    ProxyConfig beforeSecProxyConfig = ContentManager.CONFIG.get().getSecProxyConfig();
    if (!configForm.isSecProxyEnable()) {
        configForm.setSecProxyConfig(null);
    }
    ConfigInfo configInfo = configForm.convert();
    ContentManager.CONFIG.set(configInfo);
    ContentManager.CONFIG.save();
    // 代理服务器需要重新启动
    if (beforePort != configInfo.getProxyPort() || beforeSecProxyEnable != configInfo.isSecProxyEnable() || (configInfo.isSecProxyEnable() && !configInfo.getSecProxyConfig().equals(beforeSecProxyConfig))) {
        new Thread(() -> {
            HttpDownApplication.getProxyServer().close();
            HttpDownApplication.getProxyServer().setProxyConfig(configInfo.getSecProxyConfig());
            HttpDownApplication.getProxyServer().start(configInfo.getProxyPort());
        }).start();
    }
    return resultInfo;
}
Also used : ProxyConfig(lee.study.proxyee.proxy.ProxyConfig) ResultInfo(lee.study.down.model.ResultInfo) ConfigInfo(lee.study.down.model.ConfigInfo) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 4 with ConfigInfo

use of lee.study.down.model.ConfigInfo in project proxyee-down by monkeyWie.

the class ConfigForm method convert.

public ConfigInfo convert() {
    ConfigInfo configInfo = new ConfigInfo();
    BeanUtils.copyProperties(this, configInfo, new String[] { "secProxyConfig" });
    if (secProxyConfig != null) {
        configInfo.setSecProxyConfig(secProxyConfig.convert());
    }
    return configInfo;
}
Also used : ConfigInfo(lee.study.down.model.ConfigInfo)

Aggregations

ConfigInfo (lee.study.down.model.ConfigInfo)4 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 Rectangle2D (javafx.geometry.Rectangle2D)1 Image (javafx.scene.image.Image)1 ResultInfo (lee.study.down.model.ResultInfo)1 ProxyConfig (lee.study.proxyee.proxy.ProxyConfig)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1