Skip to content

Commit

Permalink
可以设置启动时是否弹窗
Browse files Browse the repository at this point in the history
  • Loading branch information
monkeyWie committed Nov 1, 2018
1 parent 5b882e2 commit 9048c18
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 34 deletions.
6 changes: 5 additions & 1 deletion front/src/i18n/en-US.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@ export default {
fmtErr: 'Incorrect format',
choose: 'Choose',
save: 'Save',
refresh: 'Refresh',
copySucc: 'Copied successfully',
copyFail: 'Copy failed'
copyFail: 'Copy failed',
saveSucc: 'Save successfully',
saveFail: 'Save failed'
},
tasks: {
createTask: 'New Task',
Expand Down Expand Up @@ -97,6 +100,7 @@ export default {
uiMode: 'UI mode',
uiModeWindows: 'Windows',
uiModeBrowser: 'Browser',
autoOpen: 'Popup at startup',
checkUpdate: 'Check for update',
checkUpdateWeek: 'Every week',
checkUpdateStartup: 'Every startup',
Expand Down
9 changes: 7 additions & 2 deletions front/src/i18n/zh-CN.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@ export default {
fmtErr: '格式不正确',
choose: '选择',
save: '保存',
refresh: '刷新',
copySucc: '复制成功',
copyFail: '复制失败'
copyFail: '复制失败',
saveSucc: '保存成功',
saveFail: '保存失败'
},
tasks: {
createTask: '创建任务',
Expand Down Expand Up @@ -80,7 +83,8 @@ export default {
extCenter: '扩展中心',
installLocalExt: '加载本地扩展',
installOk: '加载成功',
installErr: '加载失败,请检查manifest.json文件'
installErr: '加载失败,请检查manifest.json文件',
setting: '设置'
},
setting: {
downSetting: '下载设置',
Expand All @@ -97,6 +101,7 @@ export default {
uiMode: 'UI模式',
uiModeWindows: '窗口',
uiModeBrowser: '浏览器',
autoOpen: '启动弹窗',
checkUpdate: '检查更新',
checkUpdateWeek: '每周',
checkUpdateStartup: '每次启动',
Expand Down
11 changes: 8 additions & 3 deletions front/src/i18n/zh-TW.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@ export default {
fmtErr: '格式不正確',
choose: '選擇',
save: '儲存',
refresh: '刷新',
copySucc: '複製成功',
copyFail: '複製失敗'
copyFail: '複製失敗',
saveSucc: '保存成功',
saveFail: '保存失敗'
},
tasks: {
createTask: '建立任務',
Expand Down Expand Up @@ -53,7 +56,8 @@ export default {
},
extension: {
conditions: '使用須知',
conditionsContent: '首次使用擴充模組時,必須安裝由 Proxyee Down 隨機產生的一個 CA 憑證,點選下方的安裝按鈕並依系統的引導進行確認安裝。(注意:程式會在安裝前偵測作業系統中是否有安裝過憑證,當偵測到有安裝的情況會提示刪除對應的舊 CA 憑證)',
conditionsContent:
'首次使用擴充模組時,必須安裝由 Proxyee Down 隨機產生的一個 CA 憑證,點選下方的安裝按鈕並依系統的引導進行確認安裝。(注意:程式會在安裝前偵測作業系統中是否有安裝過憑證,當偵測到有安裝的情況會提示刪除對應的舊 CA 憑證)',
install: '安裝',
globalProxy: '全域代理',
proxyTip: '點選檢視說明',
Expand Down Expand Up @@ -96,6 +100,7 @@ export default {
uiMode: 'UI 模式',
uiModeWindows: '視窗',
uiModeBrowser: '瀏覽器',
autoOpen: '啟動彈窗',
checkUpdate: '檢查更新',
checkUpdateWeek: '每週',
checkUpdateStartup: '每次啟動',
Expand Down Expand Up @@ -167,4 +172,4 @@ export default {
}
}
}
}
}
55 changes: 34 additions & 21 deletions front/src/views/Setting.vue
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@
:value="option.value">{{ option.text }}</Option>
</Select>
</FormItem>
<FormItem :label="$t('setting.autoOpen')"
prop="appConfig.autoOpen">
<Switch v-model="form.appConfig.autoOpen"></Switch>
</FormItem>
<FormItem :label="$t('setting.secondProxy.secondProxy')">
<Switch v-model="secondProxyEnable"
@on-change="switchSecondProxy"></Switch>
Expand Down Expand Up @@ -130,10 +134,6 @@
</div>
</Panel>
</Collapse>
<div style="padding-top:1.25rem;">
<Button type="primary"
@click="setConfig">{{ $t('tip.save') }}</Button>
</div>
</Form>
</template>
<script>
Expand Down Expand Up @@ -179,19 +179,20 @@ export default {
}
}
},
watch: {
form: {
handler(nowVal, oldVal) {
//不是首次加载触发
if (Object.keys(oldVal.downConfig).length !== 0) {
this.setConfig()
}
},
deep: true
}
},
methods: {
switchSecondProxy(val) {
if (val) {
//设置默认值
if (!this.form.appConfig.proxyConfig) {
this.$set(this.form.appConfig, 'proxyConfig', {
proxyType: 'HTTP',
host: null,
port: null,
user: null,
pwd: null
})
}
this.rules['appConfig.proxyConfig.proxyType'] = [{ required: true, message: this.$t('tip.notNull') }]
this.rules['appConfig.proxyConfig.host'] = [{ required: true, message: this.$t('tip.notNull') }]
this.rules['appConfig.proxyConfig.port'] = [{ required: true, message: this.$t('tip.notNull') }]
Expand All @@ -209,6 +210,16 @@ export default {
appConfig: { ...appConfig }
}
this.secondProxyEnable = !!this.form.appConfig.proxyConfig
//设置默认值
if (!this.form.appConfig.proxyConfig) {
this.$set(this.form.appConfig, 'proxyConfig', {
proxyType: 'HTTP',
host: null,
port: null,
user: null,
pwd: null
})
}
if (this.form.downConfig.speedLimit > 0) {
this.form.downConfig.speedLimit /= 1024
}
Expand All @@ -219,32 +230,34 @@ export default {
async setConfig() {
this.$refs['form'].validate(async valid => {
if (valid) {
let downConfig = { ...this.form.downConfig }
let downConfig = { ...{}, ...this.form.downConfig }
let appConfig = { ...{}, ...this.form.appConfig }
if (downConfig.speedLimit > 0) {
downConfig.speedLimit *= 1024
}
if (downConfig.totalSpeedLimit > 0) {
downConfig.totalSpeedLimit *= 1024
}
if (!this.secondProxyEnable) {
this.$delete(this.form.appConfig, 'proxyConfig')
delete downConfig.proxyConfig
this.$delete(appConfig, 'proxyConfig')
this.$delete(downConfig, 'proxyConfig')
} else {
downConfig.proxyConfig = { ...this.form.appConfig.proxyConfig }
}
await this.$http.put('http://127.0.0.1:26339/config', downConfig)
await setConfig(this.form.appConfig)
await this.$noSpinHttp.put('http://127.0.0.1:26339/config', downConfig)
await setConfig(appConfig)
this.$Message.success(this.$t('tip.saveSucc'))
if (this.$i18n.locale != this.form.appConfig.locale) {
this.$i18n.locale = this.form.appConfig.locale
//强制渲染一遍,避免切换语言后下拉框不渲染的问题
const uiMode = this.form.appConfig.uiMode
/* const uiMode = this.form.appConfig.uiMode
const updateCheckRate = this.form.appConfig.updateCheckRate
this.form.appConfig.uiMode = null
this.form.appConfig.updateCheckRate = null
setTimeout(() => {
this.form.appConfig.uiMode = uiMode
this.form.appConfig.updateCheckRate = updateCheckRate
}, 0)
}, 0) */
}
}
})
Expand Down
24 changes: 17 additions & 7 deletions main/src/main/java/org/pdown/gui/DownApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public void start(Stage primaryStage) throws Exception {
initTray();
initWindow();
initBrowser();
loadUri(null, true);
loadUri(null, true, true);
}


Expand Down Expand Up @@ -316,24 +316,34 @@ public void show(boolean isTray) {
}
}

public void loadUri(String uri, boolean isTray) {
public void loadUri(String uri, boolean isTray, boolean isStartup) {
String url = "http://127.0.0.1:" + FRONT_PORT + (uri == null ? "" : uri);
boolean autoOpen = PDownConfigContent.getInstance().get().isAutoOpen();
if (PDownConfigContent.getInstance().get().getUiMode() == 0) {
try {
Desktop.getDesktop().browse(URI.create(url));
} catch (IOException e) {
LOGGER.error("Open browse error", e);
if (!isStartup || autoOpen) {
try {
Desktop.getDesktop().browse(URI.create(url));
} catch (IOException e) {
LOGGER.error("Open browse error", e);
}
}

} else {
Platform.runLater(() -> {
if (uri != null || !browser.isLoad()) {
browser.load(url);
}
show(isTray);
if (!isStartup || autoOpen) {
show(isTray);
}
});
}
}

public void loadUri(String uri, boolean isTray) {
loadUri(uri, isTray, false);
}

//提示并退出程序
private void alertAndExit(String msg) {
Platform.runLater(() -> {
Expand Down
11 changes: 11 additions & 0 deletions main/src/main/java/org/pdown/gui/entity/PDownConfigInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ public class PDownConfigInfo implements Serializable {
private List<String> extFileServers;
//检测更新频率 0.从不 1.一周检查一次 2.每次打开检查
private int updateCheckRate = 2;
//启动时是否自动打开窗口
private boolean autoOpen = true;
//最后一次检查更新时间
private long lastUpdateCheck;
//前置代理
Expand Down Expand Up @@ -85,6 +87,15 @@ public PDownConfigInfo setProxyConfig(ProxyConfig proxyConfig) {
return this;
}

public boolean isAutoOpen() {
return autoOpen;
}

public PDownConfigInfo setAutoOpen(boolean autoOpen) {
this.autoOpen = autoOpen;
return this;
}

public static com.github.monkeywie.proxyee.proxy.ProxyConfig convert(ProxyConfig proxyConfig) {
if (proxyConfig == null) {
return null;
Expand Down

0 comments on commit 9048c18

Please sign in to comment.