Skip to content

Commit

Permalink
display update status
Browse files Browse the repository at this point in the history
  • Loading branch information
Armaldio committed Jan 24, 2025
1 parent a72a4c3 commit b9fc1e2
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 4 deletions.
1 change: 0 additions & 1 deletion components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ declare module 'vue' {
Password: typeof import('primevue/password')['default']
RouterLink: typeof import('vue-router')['RouterLink']
RouterView: typeof import('vue-router')['RouterView']
ScrollPanel: typeof import('primevue/scrollpanel')['default']
Select: typeof import('primevue/select')['default']
SelectButton: typeof import('primevue/selectbutton')['default']
Skeleton: typeof import('primevue/skeleton')['default']
Expand Down
1 change: 1 addition & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 34 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { handleActionExecute } from '@main/handler-func'
import { useLogger } from '@@/logger'
import * as Sentry from '@sentry/electron/main'
import { assetsPath } from '@main/paths'
import { usePluginAPI } from '@main/api'

const isLinux = platform() === 'linux'
// let tray
Expand All @@ -39,8 +40,16 @@ if (app.isPackaged && process.env.TEST !== 'true' && !isWine) {
const imagePath = join('./assets', 'discord_white.png')
// let isQuiting = false

if (!isLinux && process.env.TEST !== 'true' && require('electron-squirrel-startup')) app.quit()
if (
!isLinux &&
process.env.TEST !== 'true' &&
app.isPackaged &&
require('electron-squirrel-startup')
) {
app.quit()
}

let api
let mainWindow: BrowserWindow | undefined

function createWindow(): void {
Expand All @@ -61,6 +70,8 @@ function createWindow(): void {

setMainWindow(mainWindow)

api = usePluginAPI(mainWindow)

if (is.dev) {
mainWindow.webContents.openDevTools()
}
Expand Down Expand Up @@ -106,6 +117,9 @@ app.whenReady().then(async () => {
})

autoUpdater.on('update-downloaded', (event, releaseNotes, releaseName) => {
api?.execute('update:set-status', {
status: 'update-downloaded'
})
logger().info('releaseNotes', releaseNotes)
logger().info('releaseName', releaseName)
logger().info('event', event)
Expand All @@ -123,24 +137,35 @@ app.whenReady().then(async () => {
})

autoUpdater.on('error', (message) => {
api?.execute('update:set-status', {
status: 'error'
})
logger().info('There was a problem updating the application')
logger().info(message)
})

autoUpdater.on('update-available', () => {
api?.execute('update:set-status', {
status: 'update-available'
})
logger().info('Found update')
})

autoUpdater.on('update-not-available', () => {
api?.execute('update:set-status', {
status: 'update-not-available'
})
logger().info('No update available')
})

autoUpdater.on('checking-for-update', (info: any) => {
api?.execute('update:set-status', {
status: 'checking-for-update'
})
logger().info('checking-for-update', info)
})

logger().info('app ready')
autoUpdater.checkForUpdates()
logger().info('autoUpdater.getFeedURL()', autoUpdater.getFeedURL())

// Set app user model id for windows
Expand Down Expand Up @@ -270,7 +295,8 @@ exec "${process.execPath}" "$@"
mainWindow,
(data) => {
logger().info('send', data)
}
},
new AbortController().signal
)
} else {
throw new Error('Unhandled type ' + node.type)
Expand Down Expand Up @@ -317,6 +343,11 @@ exec "${process.execPath}" "$@"
mainWindow.on('ready-to-show', () => {
mainWindow.show()
mainWindow.maximize()

setTimeout(() => {
autoUpdater.checkForUpdates()
console.log('checkForUpdates')
}, 10000)
})
if (isReadyToShow) {
mainWindow.show()
Expand Down
14 changes: 14 additions & 0 deletions src/main/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ import type { Tagged } from 'type-fest'
import { ILogObjMeta } from 'tslog'
import { useLogger } from '@@/logger'

export type UpdateStatus =
| 'update-available'
| 'update-downloaded'
| 'checking-for-update'
| 'update-not-available'
| 'error'

// eslint-disable-next-line @typescript-eslint/no-unused-vars
type Event<TYPE extends string, DATA> = { type: TYPE; data: DATA }
type EndEvent<DATA> = {
Expand Down Expand Up @@ -37,6 +44,13 @@ export type IpcDefinition = {
ILogObjMeta,
EndEvent<void>
]
'update:set-status': [
// input
{
status: UpdateStatus
},
EndEvent<void>
]
}

export type RendererChannels = keyof IpcDefinition
Expand Down
44 changes: 44 additions & 0 deletions src/renderer/pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@
</div>
</div> -->
</div>
<div class="footer">
<div class="update-status">{{ updateStatusText }}</div>
<div class="version-text">{{ appVersion }}</div>
</div>

<Dialog
v-model:visible="isNewProjectModalVisible"
Expand Down Expand Up @@ -329,6 +333,8 @@ import { Presets } from '@@/apis'
import FileInput from '@renderer/components/FileInput.vue'
import { PROJECT_EXTENSION } from '@renderer/models/constants'
import { kebabCase } from 'change-case'
import { handle } from '@renderer/composables/handlers'
import { UpdateStatus } from '@main/api'
const router = useRouter()
Expand All @@ -346,6 +352,25 @@ const { update: updateFileStore, remove } = fileStore
const filesEnhanced = ref<EnhancedFile[]>([])
const updateStatus = ref<UpdateStatus>('update-not-available')
const updateStatusText = computed(() => {
switch (updateStatus.value) {
case 'update-not-available':
return ''
case 'update-available':
return 'Update available, downloading...'
case 'update-downloaded':
return 'Update downloaded'
case 'checking-for-update':
return 'Checking for update...'
case 'error':
return 'Error'
default:
return ''
}
})
const canCreateproject = computed(() => {
return (
newProjectType.value !== undefined &&
Expand Down Expand Up @@ -702,6 +727,13 @@ const accountMenuItems = computed(() => {
const toggleAccountMenu = (event: MouseEvent) => {
$menu.value.toggle(event)
}
handle('update:set-status', async (event, { value, send }) => {
console.log('event', event)
console.log('value', value)
updateStatus.value = value.status
})
</script>

<style scoped>
Expand Down Expand Up @@ -868,4 +900,16 @@ const toggleAccountMenu = (event: MouseEvent) => {
grid-template-columns: 1fr;
}
}
.footer {
height: 24px;
background-color: #eee;
border-top: 1px solid #ddd;
display: flex;
flex-direction: row;
justify-content: end;
align-items: center;
font-size: 12px;
padding: 0 8px;
}
</style>

0 comments on commit b9fc1e2

Please sign in to comment.