Skip to content

Commit

Permalink
[feats] dns for doh (return)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hiram committed Jul 30, 2024
1 parent 3498bd6 commit f456fae
Show file tree
Hide file tree
Showing 11 changed files with 81 additions and 36 deletions.
4 changes: 4 additions & 0 deletions src/main/core/db/init/tbl_setting.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@
"key": "ua",
"value": "Mozilla/5.0 (Linux; Android 11; M2007J3SC Build/RKQ1.200826.002; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/77.0.3865.120 MQQBrowser/6.2 TBS/045714 Mobile Safari/537.36"
},
{
"key": "dns",
"value": ""
},
{
"key": "playerMode",
"value": {
Expand Down
9 changes: 9 additions & 0 deletions src/main/core/db/magrite/data/update3_3_6_to3_3_7.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,17 @@ const update3_3_6_to3_3_7 = () => {
db.get(TABLE_NAME).remove({ key: 'defaultFilterType' }).write();
};
db.get(TABLE_NAME).insert({ key: 'defaultFilterType', value: 'off' }).write();

if (db.get(TABLE_NAME).find({ key: 'debug' }).value()?.value) {
db.get(TABLE_NAME).remove({ key: 'debug' }).write();
};
db.get(TABLE_NAME).insert({ key: 'debug', value: false }).write();

if (db.get(TABLE_NAME).find({ key: 'dns' }).value()?.value) {
db.get(TABLE_NAME).remove({ key: 'dns' }).write();
};
db.get(TABLE_NAME).insert({ key: 'dns', value: false }).write();

db.get(TABLE_NAME).find({ key: 'version' }).assign({ key: 'version', value: '3.3.7' }).write();
logger.info('[db][magrite][update3_3_6_to3_3_7]completed');
};
Expand Down
14 changes: 14 additions & 0 deletions src/main/core/ipc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,20 @@ const ipcListen = () => {
}
});

ipcMain.on('updateDns', (_, item) => {
logger.info(`[ipcMain] new dns: ${item}`);
if (item) {
app.configureHostResolver({
secureDnsMode: 'secure',
secureDnsServers: [item],
});
} else {
app.configureHostResolver({
secureDnsMode: 'off',
});
}
});

// 事件广播通知
ipcMain.handle('event-broadcast', (event, eventInfo) => {
// 遍历window执行
Expand Down
9 changes: 9 additions & 0 deletions src/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,15 @@ let reqIdRedirect = {};
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.whenReady().then(async () => {
if (setting.find({ key: 'dns' }).value) {
const doh = setting.find({ key: 'dns' }).value;
logger.info(`[dns] doh: ${doh}`)
app.configureHostResolver({
secureDnsMode: 'secure',
secureDnsServers: [doh],
});
};

registerTitleBarListener();

const defaultSession = session.defaultSession;
Expand Down
14 changes: 5 additions & 9 deletions src/renderer/src/config/doh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,15 @@ export default {
dns: 'https://dns.alidns.com/dns-query',
},
{
name: 'cloudflare',
dns: 'https://cloudflare-dns.com/dns-query',
},
{
name: 'Google',
dns: 'https://dns.google/dns-query',
name: '360',
dns: 'https://doh.360.cn/dns-query',
},
{
name: 'IBM',
dns: 'https://dns.quad9.net/dns-query',
name: 'Cloudflare',
dns: 'https://cloudflare-dns.com/dns-query',
},
{
name: 'Cisco',
name: 'OpenDNS',
dns: 'https://doh.opendns.com/dns-query',
},
],
Expand Down
8 changes: 7 additions & 1 deletion src/renderer/src/locales/lang/en_US/pages/setting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ export default {
security: 'Security',
proxy: 'Proxy',
ua: 'UA',
dns: 'DNS',
jurisdiction: 'Jurisdiction',
selefBoot: 'SelefBoot',
hardwareAcceleration: 'HardwareAcceleration',
Expand Down Expand Up @@ -192,7 +193,12 @@ export default {
ua: {
title: 'User-Agent',
topTip: 'Emulate User Agent',
bottomTip: 'recommend chrome, empty use system default',
bottomTip: 'Recommend chrome, empty use system default',
},
dns: {
title: 'DNS-over-HTTP',
topTip: 'Using Secure DNS',
bottomTip: 'Recommend Tencent, empty use system default',
},
barrage: {
title: 'Barrage',
Expand Down
6 changes: 6 additions & 0 deletions src/renderer/src/locales/lang/zh_CN/pages/setting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ export default {
security: '安全',
proxy: '网络代理',
ua: '用户代理',
dns: 'DNS',
jurisdiction: '权限',
selefBoot: '自启动',
hardwareAcceleration: '硬件加速',
Expand Down Expand Up @@ -195,6 +196,11 @@ export default {
topTip: '模拟用户代理',
bottomTip: '推荐chrome, 空使用系统默认',
},
dns: {
title: 'DNS-over-HTTP',
topTip: '使用安全DNS',
bottomTip: '推荐腾讯, 空使用系统默认',
},
barrage: {
title: '弹幕',
header: '启用该参数需预处理数据, 将增加起播时间',
Expand Down
22 changes: 12 additions & 10 deletions src/renderer/src/pages/setting/base/BaseSetting.vue
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,12 @@
<t-space>
<span v-if="platform !== 'linux'" class="title" @click="openProxySetting">{{ $t('pages.setting.base.proxy')
}}</span>
<span class="title" @click="uaEvnet">{{ $t('pages.setting.base.ua') }}</span>
<span class="title" @click="safeEvnet('ua')">{{ $t('pages.setting.base.ua') }}</span>
<span class="title" @click="safeEvnet('dns')">{{ $t('pages.setting.base.dns') }}</span>
</t-space>

<dialog-ua-view v-model:visible="isVisible.ua" :data="uaDialogData" @receive-dns-data="flushDialogData" />
<dialog-ua-view v-model:visible="isVisible.ua" :data="safeDialogData" @receive-data="flushDialogData" />
<dialog-dns-view v-model:visible="isVisible.dns" :data="safeDialogData" @receive-data="flushDialogData" />
</t-form-item>
<t-form-item :label="$t('pages.setting.base.jurisdiction')" name="jurisdiction">
<t-space>
Expand Down Expand Up @@ -179,6 +181,7 @@ import SettingDarkIcon from '@/assets/assets-setting-dark.svg';
import SettingLightIcon from '@/assets/assets-setting-light.svg';
import DialogDataView from './components/DialogData.vue';
import DialogUaView from './components/DialogUA.vue';
import DialogDnsView from './components/DialogDns.vue';
import DialogUpdateView from './components/DialogUpdate.vue';
import DialogThumbnailView from './components/DialogThumbnail.vue';
import DialogCustomPlayer from './components/DialogCustomPlayer.vue';
Expand All @@ -203,7 +206,7 @@ const isVisible = reactive({
disclaimer: false,
});
const uaDialogData = ref({ data: '', type: 'ua' });
const safeDialogData = ref({ data: '', type: 'dns' });
const webdevDialogData = ref({ webdev: { sync: false, data: { url: "https://dav.jianguoyun.com/dav/", username: "", password: "" } } });
const snifferDialogData = ref({ data: { type: '', url: '' }, type: 'snifferMode' });
const barrageDialogData = ref({ url: '', key: '', support: [], start: '', mode: '', color: '', content: '' });
Expand Down Expand Up @@ -643,15 +646,14 @@ const debugEvnet = () => {
window?.location.reload();
};
// ua:打开dialog并设置数据
const uaEvnet = () => {
const { ua } = formData.value;
uaDialogData.value = {
data: ua,
type: 'ua',
const safeEvnet = (type) => {
safeDialogData.value = {
data: formData.value[type],
type: type,
};
isVisible.ua = true;
isVisible[type] = true;
};
const snifferEvent = () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,7 @@ const formatSet = (data) => {
},
{ key: "defaultFilterType", value: "off" },
{ key: "debug", value: false },
{ key: "dns", value: "" },
{ key: "version", value: pkgVersion },
// ... 其他新键值对
];
Expand Down
24 changes: 11 additions & 13 deletions src/renderer/src/pages/setting/base/components/DialogDns.vue
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
<template>
<t-dialog v-model:visible="formVisible" header="DNS-over-HTTP" placement="center" :footer="false">
<t-dialog v-model:visible="formVisible" :header="$t('pages.setting.dns.title')" placement="center" :footer="false">
<template #body>
<div class="doh-dialog-container dialog-container-padding">
<div class="header">
<p class="tip">确定如何通过安全连接来连接到网站</p>
<p class="tip">{{ $t('pages.setting.dns.topTip') }}</p>
</div>

<!-- 表单内容 -->
<t-form ref="form" :data="formData" @submit="onSubmit">
<t-textarea v-model="formData.data" class="dns-input" placeholder="请输入dns" autofocus
:autosize="{ minRows: 2, maxRows: 4 }" @change="changeDnstextarea" />
<t-textarea v-model="formData.data" class="text-input" :placeholder="$t('pages.setting.placeholder.general')"
autofocus :autosize="{ minRows: 2, maxRows: 4 }" @change="changeDnstextarea" />
<t-radio-group v-model="dnsSelect" variant="default-filled" size="small" @change="changeDnsSelect">
<t-radio-button v-for="item in DNS_LIST" :key="item.name" :value="item.dns">{{ item.name }}</t-radio-button>
</t-radio-group>
<p class="tip bottom-tip">推荐使用腾讯国密级,为空使用普通dns查询</p>
<p class="tip bottom-tip">{{ $t('pages.setting.dns.bottomTip') }}</p>
<div class="optios">
<t-form-item style="float: right">
<t-button variant="outline" @click="onClickCloseBtn">取消</t-button>
<t-button theme="primary" type="submit">确定</t-button>
<t-button variant="outline" @click="onClickCloseBtn">{{ $t('pages.setting.dialog.cancel') }}</t-button>
<t-button theme="primary" type="submit">{{ $t('pages.setting.dialog.confirm') }}</t-button>
</t-form-item>
</div>
</t-form>
Expand All @@ -28,7 +28,6 @@

<script setup lang="ts">
import _ from 'lodash';
import { MessagePlugin } from 'tdesign-vue-next';
import { reactive, ref, watch } from 'vue';
import DNS_CONFIG from '@/config/doh';
Expand All @@ -55,7 +54,7 @@ const DNS_LIST = reactive([...DNS_CONFIG.doh]);
const dnsSelect = ref('');
const emit = defineEmits(['update:visible', 'receiveDnsData']);
const emit = defineEmits(['update:visible', 'receiveData']);
watch(
() => formVisible.value,
Expand All @@ -81,7 +80,7 @@ watch(
const changeDnstextarea = (item) => {
const index = _.findIndex(DNS_LIST, ['dns', item]);
if (index === -1) dnsSelect.value = null;
if (index === -1) dnsSelect.value = '';
};
const changeDnsSelect = (item) => {
Expand All @@ -90,13 +89,12 @@ const changeDnsSelect = (item) => {
const onSubmit = async () => {
const { data, type } = formData.value;
emit('receiveDnsData', {
emit('receiveData', {
data,
type,
});
window.electron.ipcRenderer.send('update-dns', !!data, data);
MessagePlugin.info('重启软件生效');
window.electron.ipcRenderer.send('updateDns', data);
formVisible.value = false;
};
Expand Down
6 changes: 3 additions & 3 deletions src/renderer/src/pages/setting/base/components/DialogUA.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<!-- 表单内容 -->
<t-form ref="form" :data="formData" @submit="onSubmit">
<t-textarea v-model="formData.data" class="dns-input" :placeholder="$t('pages.setting.placeholder.general')"
<t-textarea v-model="formData.data" class="text-input" :placeholder="$t('pages.setting.placeholder.general')"
autofocus :autosize="{ minRows: 2, maxRows: 4 }" @change="changeUatextarea" />
<t-radio-group v-model="active.select" variant="default-filled" size="small" @change="changeUaSelect">
<t-radio-button v-for="item in UA_LIST" :key="item.name" :value="item.ua">{{ item.name }}</t-radio-button>
Expand Down Expand Up @@ -55,7 +55,7 @@ const active = reactive({
select: ''
});
const emit = defineEmits(['update:visible', 'receiveDnsData']);
const emit = defineEmits(['update:visible', 'receiveData']);
watch(
() => formVisible.value,
Expand Down Expand Up @@ -90,7 +90,7 @@ const changeUaSelect = (item) => {
const onSubmit = async () => {
const { data, type } = formData.value;
emit('receiveDnsData', {
emit('receiveData', {
data,
type,
});
Expand Down

0 comments on commit f456fae

Please sign in to comment.