Skip to content

Commit de67f7e

Browse files
authored
Merge pull request #914 from Moltemort/fix/preview-not-show-bug
🐛fix: preview not show bug due to incorrect hosts file
2 parents 9a9141d + f22478e commit de67f7e

File tree

4 files changed

+43
-12
lines changed

4 files changed

+43
-12
lines changed

src/assets/locales.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const message = {
1010
remote: '远 程',
1111
system: '系 统',
1212
renderSuccess: '渲染完毕,快去预览吧!',
13+
renderError: '渲染失败,请检查 hosts 文件中 127.0.0.1 是否指向 localhost。确认配置正确后,尝试重启应用。',
1314
syncWarning: '必须完成配置才能同步哦!',
1415
syncSuccess: '同步成功啦!',
1516
syncError1: '同步遇到了错误,请查阅',
@@ -135,6 +136,7 @@ const message = {
135136
remote: '遠 程',
136137
system: '系 統',
137138
renderSuccess: '渲染完毕,快去预览吧!',
139+
renderError: '渲染失敗,請檢查 hosts 文件中 127.0.0.1 是否指向 localhost。確認配置正確後,嘗試重啟應用。',
138140
syncWarning: '必須完成配置才能同步哦!',
139141
syncSuccess: '同步成功啦!',
140142
syncError1: '同步遇到了错误,请查閱',
@@ -259,6 +261,7 @@ const message = {
259261
remote: 'Server',
260262
system: 'System',
261263
renderSuccess: 'Congratulations, the rendering is complete, go ahead and preview.',
264+
renderError: 'Rendering failed, please check whether 127.0.0.1 in the hosts file points to localhost. After confirming that the configuration is correct, try to restart the application.',
262265
syncWarning: 'You must complete the configuration to synchronize!',
263266
syncSuccess: 'Synchronization succeeded!',
264267
syncError1: 'Sorry, synchronization encountered an error, please refer to',
@@ -383,6 +386,7 @@ const message = {
383386
remote: 'Serveur',
384387
system: 'Système',
385388
renderSuccess: 'Félicitations, le rendu est terminé et regardez en avant-première.',
389+
renderError: 'Le rendu a échoué, veuillez vérifier si 127.0.0.1 dans le fichier hosts pointe vers localhost. Après avoir vérifié que la configuration est correcte, essayez de redémarrer l\'application.',
386390
syncWarning: 'Vous devez compléter la configuration pour synchroniser !',
387391
syncSuccess: 'La synchronisation a réussi !',
388392
syncError1: 'Désolé, la synchronisation a rencontré une erreur, veuillez vous référer à',
@@ -507,6 +511,7 @@ const message = {
507511
remote: 'リモート',
508512
system: 'システム',
509513
renderSuccess: 'レンダリングは完成しました、プレビューしてください。',
514+
renderError: 'レンダリングに失敗しました。hostsファイルの127.0.0.1がlocalhostを指しているかどうかを確認してください。構成が正しいことを確認した後、アプリケーションを再起動してみてください。',
510515
syncWarning: 'サイトを同期化する前に、システムの配置を完成してください!',
511516
syncSuccess: 'サイトの同期化は完成しました!',
512517
syncError1: '同期化の途中でエラーが発生しました、ご確認ください。',

src/background.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ function createWindow() {
3232
webPreferences: {
3333
webSecurity: false, // FIXED: Not allowed to load local resource
3434
nodeIntegration: true,
35+
enableRemoteModule: true, // FIXED: 兼容 [email protected]
3536
},
3637
// frame: false, // 去除默认窗口栏
3738
titleBarStyle: 'hiddenInset' as ('hidden' | 'default' | 'hiddenInset' | 'customButtonsOnHover' | undefined),
@@ -40,7 +41,7 @@ function createWindow() {
4041
if (process.platform !== 'darwin') {
4142
winOption.icon = `${__dirname}/app-icons/gridea.png`
4243
}
43-
44+
4445
win = new BrowserWindow(winOption)
4546
win.setTitle('Gridea')
4647

src/components/Main.vue

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@
8989
</template>
9090

9191
<script lang="ts">
92+
import { VNodeChildren } from 'vue'
9293
import { ipcRenderer, IpcRendererEvent, shell } from 'electron'
9394
import { Vue, Component } from 'vue-property-decorator'
9495
import axios from 'axios'
@@ -121,11 +122,11 @@ export default class App extends Vue {
121122
hasUpdate = false
122123
123124
newVersion = ''
124-
125+
125126
syncErrorModalVisible = false
126127
127128
updateModalVisible = false
128-
129+
129130
systemModalVisible = false
130131
131132
updateContent = ''
@@ -137,7 +138,7 @@ export default class App extends Vue {
137138
get currentRouter() {
138139
return this.$route.path
139140
}
140-
141+
141142
get sideMenus() {
142143
return [
143144
{
@@ -226,15 +227,34 @@ export default class App extends Vue {
226227
ga.event('Preview', 'Preview - start', { evLabel: this.site.setting.domain })
227228
228229
ipcRenderer.once('html-rendered', (event: IpcRendererEvent, result: any) => {
229-
this.$message.success(`🎉 ${this.$t('renderSuccess')}`)
230+
// this.$message.success(`🎉 ${this.$t('renderSuccess')}`)
230231
231232
ga.event('Preview', 'Preview - success', { evLabel: this.site.setting.domain })
232233
233234
ipcRenderer.send('app-preview-server-port-get')
234235
ipcRenderer.once(
235236
'app-preview-server-port-got',
236-
(portGotEvent: IpcRendererEvent, port: any) => {
237-
this.openInBrowser(`http://localhost:${port}`)
237+
(portGotEvent: IpcRendererEvent, port: number | string | null) => {
238+
if (!port && typeof port !== 'number') {
239+
this.$message.config({
240+
top: '36px',
241+
})
242+
this.$message.open({
243+
content: (h: Vue.CreateElement) => {
244+
const errStyle = {
245+
display: 'inline-block',
246+
maxWidth: '800px',
247+
}
248+
return h('span', {
249+
style: errStyle,
250+
}, `❌ ${this.$t('renderError')}` as any as VNodeChildren)
251+
},
252+
icon: '',
253+
})
254+
} else {
255+
this.$message.success(`🎉 ${this.$t('renderSuccess')}`)
256+
this.openInBrowser(`http://localhost:${port}`)
257+
}
238258
},
239259
)
240260
})
@@ -480,7 +500,7 @@ export default class App extends Vue {
480500
list-style-type: none;
481501
font-size: 14px;
482502
margin: 30px 20px;
483-
503+
484504
ul,
485505
ol {
486506
margin: 20px 20px 10px;
@@ -493,14 +513,14 @@ export default class App extends Vue {
493513
494514
/deep/ ul > li {
495515
display: table-row;
496-
516+
497517
&:before {
498518
content:'\25CF';
499519
color: #fad849;
500520
padding-right: 10px;
501521
display: table-cell;
502522
}
503-
523+
504524
+ li:before {
505525
padding-top: 10px;
506526
}

src/server.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,13 @@ export default function initServer() {
77
function listen(port: number) {
88
server = app.listen(port, 'localhost').on('error', (err: NodeJS.ErrnoException) => {
99
if (err) {
10-
console.log(`Preview server port ${port} is busy, trying with port ${port + 1}`)
11-
listen(port + 1)
10+
if (err.message === 'getaddrinfo ENOTFOUND localhost') {
11+
// Fixed: 修复渲染服务在找不到 localhost 时崩溃问题
12+
console.log('\x1B[31m%s\x1B[0m', 'Localhost is not found so that the preview server is not working. Please check your hosts file and then restart the application.')
13+
} else {
14+
console.log(`Preview server port ${port} is busy, trying with port ${port + 1}`)
15+
listen(port + 1)
16+
}
1217
}
1318
}).on('listening', () => {
1419
app.set('port', port)

0 commit comments

Comments
 (0)