Skip to content

Commit

Permalink
Refactor check update telmi sync
Browse files Browse the repository at this point in the history
  • Loading branch information
Franck ALARY committed Feb 12, 2024
1 parent 95f2f9d commit 911a3f7
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 31 deletions.
1 change: 1 addition & 0 deletions public/MainEvents/Update.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ function mainEventUpdate (mainWindow) {
'check-update',
async () => {
const json = await requestJson('https://api.github.com/repos/DantSu/Telmi-Sync/releases', {})
mainWindow.webContents.send('check-update-data', 'https://github.com/DantSu/Telmi-Sync/releases')
if (!json.length || !isNewerVersion(app.getVersion(), json[0].tab_name)) {
return
}
Expand Down
7 changes: 7 additions & 0 deletions src/App/Components/Buttons/IconsTexts/ButtonIconTextCloud.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import ButtonIconTextGeneric from './ButtonIconTextGeneric.js'

function ButtonIconTextCloud(props) {
return <ButtonIconTextGeneric {...props} icon={'\uf0ed'}/>
}

export default ButtonIconTextCloud
26 changes: 26 additions & 0 deletions src/App/Components/Link/ButtonExternalLink.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import React, { useCallback, useMemo } from 'react'

const {ipcRenderer} = window.require('electron')

function ButtonExternalLink ({href, children}) {
const
onClick = useCallback(
(e) => {
e.preventDefault()
ipcRenderer.send('new-window', href)
},
[href]
),
childHref = useMemo(
() => React.Children.map(
children,
(child) => React.cloneElement(child, {onClick})
),
[children, onClick]
)

return <>{childHref}</>

}

export default ButtonExternalLink
14 changes: 0 additions & 14 deletions src/App/Components/Link/ExternalLink.js

This file was deleted.

12 changes: 5 additions & 7 deletions src/App/Layout/TopBar/ButtonUpdate.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { useElectronEmitter, useElectronListener } from '../../Components/Electron/Hooks/UseElectronEvent.js'
import { useState } from 'react'
import { useLocale } from '../../Components/Locale/LocaleHooks.js'

import styles from './TopBar.module.scss'
import ExternalLink from '../../Components/Link/ExternalLink.js'
import ButtonExternalLink from '../../Components/Link/ButtonExternalLink.js'
import ButtonIconTextCloud from '../../Components/Buttons/IconsTexts/ButtonIconTextCloud.js'

function ButtonUpdate () {
const
Expand All @@ -17,10 +16,9 @@ function ButtonUpdate () {
)
useElectronEmitter('check-update', [])

return urlUpdate === null ? null : <ExternalLink href={urlUpdate}
className={styles.buttonUpdate}>{
getLocale('update-available')
}</ExternalLink>
return urlUpdate === null ? null : <ButtonExternalLink href={urlUpdate}>
<ButtonIconTextCloud text={getLocale('update-available')} rounded={true}/>
</ButtonExternalLink>
}

export default ButtonUpdate
10 changes: 0 additions & 10 deletions src/App/Layout/TopBar/TopBar.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,3 @@
.buttonSelected {
color: $orange;
}

.buttonUpdate {
-webkit-app-region: no-drag;
display: block;
font-weight: bold;
color: $purple1;
background: $orange;
padding: 5px 10px;
border-radius: 15px;
}

0 comments on commit 911a3f7

Please sign in to comment.