Skip to content

Commit 09ec5ee

Browse files
committed
feat(main): check for update
1 parent d73856c commit 09ec5ee

File tree

6 files changed

+87
-3
lines changed

6 files changed

+87
-3
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
"@types/universal-analytics": "^0.4.5",
3737
"@vueuse/core": "^8.1.2",
3838
"ace-builds": "^1.4.14",
39+
"axios": "^0.26.1",
3940
"electron-store": "^8.0.1",
4041
"fs-extra": "^10.0.1",
4142
"lowdb": "^3.0.0",

src/main/index.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { app, BrowserWindow, ipcMain, Menu } from 'electron'
1+
import { app, BrowserWindow, ipcMain, Menu, shell } from 'electron'
22
import path from 'path'
33
import os from 'os'
44
import { store } from './store'
@@ -8,6 +8,7 @@ import { debounce } from 'lodash'
88
import { subscribeToChannels } from './services/ipc'
99
import { mainMenu } from './menu/main'
1010
import { subscribeToDialog } from './services/ipc/dialog'
11+
import { checkForUpdate } from './services/update-check'
1112

1213
const isDev = process.env.NODE_ENV === 'development'
1314

@@ -43,6 +44,8 @@ function createWindow () {
4344

4445
mainWindow.on('resize', () => storeBounds(mainWindow))
4546
mainWindow.on('move', () => storeBounds(mainWindow))
47+
48+
checkForUpdate()
4649
}
4750

4851
const storeBounds = debounce((mainWindow: BrowserWindow) => {
@@ -69,6 +72,10 @@ ipcMain.handle('main:restart-api', () => {
6972
apiServer.restart()
7073
})
7174

75+
ipcMain.handle('main:open-url', (event, payload) => {
76+
shell.openExternal(payload as string)
77+
})
78+
7279
ipcMain.on('request-info', event => {
7380
event.sender.send('request-info', {
7481
version: app.getVersion(),

src/main/services/update-check.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import axios from 'axios'
2+
import { BrowserWindow } from 'electron'
3+
import { version, repository } from '../../../package.json'
4+
5+
const isDev = process.env.NODE_ENV === 'development'
6+
7+
export const checkForUpdate = async () => {
8+
if (isDev) return
9+
10+
const res = await axios.get(`${repository}/releases/latest`)
11+
12+
if (res) {
13+
const latest = res.request.socket._httpMessage.path
14+
.split('/')
15+
.pop()
16+
.substring(1)
17+
if (latest !== version) {
18+
BrowserWindow.getFocusedWindow()?.webContents.send(
19+
'main:update-available'
20+
)
21+
}
22+
}
23+
}

src/renderer/App.vue

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
11
<template>
22
<div class="app-title-bar" />
33
<RouterView />
4+
<div
5+
v-if="isUpdateAvailable"
6+
class="update"
7+
@click="onClickUpdate"
8+
>
9+
<span> Update available </span>
10+
</div>
411
</template>
512

613
<script setup lang="ts">
714
import router from '@/router'
8-
import { watch } from 'vue'
15+
import { ref, watch } from 'vue'
916
import { ipc } from './electron'
1017
import { useAppStore } from './store/app'
18+
import { repository } from '../../package.json'
1119
1220
// По какой то причине необходимо явно установить роут в '/'
1321
// для корректного поведения в продакшен сборке
@@ -16,10 +24,16 @@ router.push('/')
1624
1725
const appStore = useAppStore()
1826
27+
const isUpdateAvailable = ref(false)
28+
1929
const setTheme = (theme: string) => {
2030
document.body.dataset.theme = theme
2131
}
2232
33+
const onClickUpdate = () => {
34+
ipc.invoke('main:open-url', `${repository}/releases`)
35+
}
36+
2337
watch(
2438
() => appStore.theme,
2539
() => setTheme(appStore.theme),
@@ -29,6 +43,10 @@ watch(
2943
ipc.on('main-menu:preferences', () => {
3044
router.push('/preferences')
3145
})
46+
47+
ipc.on('main:update-available', async () => {
48+
isUpdateAvailable.value = true
49+
})
3250
</script>
3351

3452
<style lang="scss">
@@ -47,4 +65,30 @@ body {
4765
transition: all 0.5s;
4866
}
4967
}
68+
.update {
69+
position: absolute;
70+
top: 5px;
71+
right: var(--spacing-sm);
72+
z-index: 1020;
73+
text-transform: uppercase;
74+
font-size: 11px;
75+
font-weight: bold;
76+
background: -webkit-linear-gradient(60deg, var(--color-primary), limegreen);
77+
-webkit-background-clip: text;
78+
-webkit-text-fill-color: transparent;
79+
background-size: 200% auto;
80+
animation: shine 3s ease infinite;
81+
}
82+
83+
@keyframes shine {
84+
from {
85+
background-position: 200%;
86+
}
87+
}
88+
89+
@keyframes zoom {
90+
from {
91+
background-position: 100%;
92+
}
93+
}
5094
</style>

src/shared/types/main/index.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ type MainAction =
3737
| 'notification'
3838
| 'open-dialog'
3939
| 'open-message-box'
40+
| 'update-available'
41+
| 'open-url'
4042

4143
export type ContextMenuChannel = CombineWith<ChannelSubject, 'context-menu'>
4244

yarn.lock

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3094,6 +3094,13 @@ axios@^0.21.1:
30943094
dependencies:
30953095
follow-redirects "^1.14.0"
30963096

3097+
axios@^0.26.1:
3098+
version "0.26.1"
3099+
resolved "https://registry.yarnpkg.com/axios/-/axios-0.26.1.tgz#1ede41c51fcf51bbbd6fd43669caaa4f0495aaa9"
3100+
integrity sha512-fPwcX4EvnSHuInCMItEhAGnaSEXRBjtzh9fOtsE6E1G6p7vl7edEeZe11QHf18+6+9gR5PbKV/sGKNaD8YaMeA==
3101+
dependencies:
3102+
follow-redirects "^1.14.8"
3103+
30973104
babel-core@^7.0.0-bridge.0:
30983105
version "7.0.0-bridge.0"
30993106
resolved "https://registry.yarnpkg.com/babel-core/-/babel-core-7.0.0-bridge.0.tgz#95a492ddd90f9b4e9a4a1da14eb335b87b634ece"
@@ -6028,7 +6035,7 @@ flow-parser@0.*:
60286035
resolved "https://registry.yarnpkg.com/flow-parser/-/flow-parser-0.168.0.tgz#e9c385499145828b42fd754d3528f4cb7d5c6edf"
60296036
integrity sha512-YMlc+6vvyDPqWKOpzmyifJXBbwlNdqznuy8YBHxX1/90F8d+NnhsxMe1u/ok5LNvNJVJ2TVMkWudu0BUKOSawA==
60306037

6031-
follow-redirects@^1.14.0:
6038+
follow-redirects@^1.14.0, follow-redirects@^1.14.8:
60326039
version "1.14.9"
60336040
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.14.9.tgz#dd4ea157de7bfaf9ea9b3fbd85aa16951f78d8d7"
60346041
integrity sha512-MQDfihBQYMcyy5dhRDJUHcw7lb2Pv/TuE6xP1vyraLukNDHKbDxDNaOE3NbCAdKQApno+GPRyo1YAp89yCjK4w==

0 commit comments

Comments
 (0)