Skip to content

Commit

Permalink
rename to readyToUpdate
Browse files Browse the repository at this point in the history
  • Loading branch information
juliangruber committed Feb 21, 2024
1 parent 2e31b97 commit bf910b3
Show file tree
Hide file tree
Showing 11 changed files with 33 additions and 33 deletions.
2 changes: 1 addition & 1 deletion main/ipc.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const ipcMainEvents = Object.freeze({

UPDATE_CHECK_STARTED: 'station:update-check:started',
UPDATE_CHECK_FINISHED: 'station:update-check:finished',
UPDATE_AVAILABLE: 'station:update-available',
READY_TO_UPDATE: 'station:ready-to-update',

TRANSACTION_UPDATE: 'station:transaction-update',
BALANCE_UPDATE: 'station:wallet-balance-update',
Expand Down
6 changes: 3 additions & 3 deletions main/preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@ contextBridge.exposeInMainWorld('electron', {
return () =>
ipcRenderer.removeListener('station:earnings-counter', listener)
},
onUpdateAvailable: (/** @type {() => void} */ callback) => {
onReadyToUpdate: (/** @type {() => void} */ callback) => {
const listener = () => callback()
ipcRenderer.on('station:update-available', listener)
ipcRenderer.on('station:ready-to-update', listener)
return () =>
ipcRenderer.removeListener('station:update-available', listener)
ipcRenderer.removeListener('station:ready-to-update', listener)
},
onBalanceUpdate: (/** @type {(value: string) => void} */ callback) => {
/** @type {(event: IpcRendererEvent, ...args: any[]) => void} */
Expand Down
10 changes: 5 additions & 5 deletions main/tray.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ function icon (/** @type {'on' | 'off' | 'update' | 'update-off'} */ state) {
}

/**
* @param {boolean} isUpdateAvailable
* @param {boolean} readyToUpdate
* @param {boolean} isOnline
*/
function getTrayIcon (isUpdateAvailable, isOnline) {
return isUpdateAvailable
function getTrayIcon (readyToUpdate, isOnline) {
return readyToUpdate
? isOnline
? icons.updateOn
: icons.updateOff
Expand Down Expand Up @@ -140,7 +140,7 @@ function setupIpcEventListeners (contextMenu, ctx) {
})

ipcMain.on(ipcMainEvents.ACTIVITY_LOGGED, updateTray)
ipcMain.on(ipcMainEvents.UPDATE_AVAILABLE, updateTray)
ipcMain.on(ipcMainEvents.READY_TO_UPDATE, updateTray)
ipcMain.on(ipcMainEvents.JOB_STATS_UPDATED, updateTray)
ipcMain.on(ipcMainEvents.BALANCE_UPDATE, updateTray)
ipcMain.on(ipcMainEvents.SCHEDULED_REWARDS_UPDATE, updateTray)
Expand All @@ -159,7 +159,7 @@ function setupIpcEventListeners (contextMenu, ctx) {
function updateTray () {
assert(tray)
tray.setImage(
getTrayIcon(ctx.getUpdaterStatus().updateAvailable, core.isOnline())
getTrayIcon(ctx.getUpdaterStatus().readyToUpdate, core.isOnline())
)
const contextMenu = createContextMenu(ctx)
tray.setContextMenu(contextMenu)
Expand Down
2 changes: 1 addition & 1 deletion main/typings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export interface Context {

openReleaseNotes: () => void;
restartToUpdate: () => void;
getUpdaterStatus: () => {updateAvailable: boolean};
getUpdaterStatus: () => {readyToUpdate: boolean};
browseTransactionTracker: (transactionHash: string) => void;
showTermsOfService: () => void;

Expand Down
8 changes: 4 additions & 4 deletions main/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,10 @@ function setupIpcEventForwarding (ui) {
}
ipcMain.on(ipcMainEvents.JOB_STATS_UPDATED, onJobStatsUpdated)

const onUpdateAvailable = (/** @type {unknown[]} */ ...args) => {
ui.webContents.send(ipcMainEvents.UPDATE_AVAILABLE, ...args)
const onReadyToUpdate = (/** @type {unknown[]} */ ...args) => {
ui.webContents.send(ipcMainEvents.READY_TO_UPDATE, ...args)
}
ipcMain.on(ipcMainEvents.UPDATE_AVAILABLE, onUpdateAvailable)
ipcMain.on(ipcMainEvents.READY_TO_UPDATE, onReadyToUpdate)

const onTransactionUpdate = (/** @type {unknown[]} */ ...args) => {
ui.webContents.send(ipcMainEvents.TRANSACTION_UPDATE, ...args)
Expand All @@ -150,7 +150,7 @@ function setupIpcEventForwarding (ui) {
return function stopIpcEventForwarding () {
ipcMain.removeListener(ipcMainEvents.ACTIVITY_LOGGED, onNewActivity)
ipcMain.removeListener(ipcMainEvents.JOB_STATS_UPDATED, onJobStatsUpdated)
ipcMain.removeListener(ipcMainEvents.UPDATE_AVAILABLE, onUpdateAvailable)
ipcMain.removeListener(ipcMainEvents.READY_TO_UPDATE, onReadyToUpdate)
ipcMain.removeListener(
ipcMainEvents.TRANSACTION_UPDATE,
onTransactionUpdate
Expand Down
8 changes: 4 additions & 4 deletions main/updater.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ let updateNotification = null

let checkingManually = false

let updateDownloaded = false
let readyToUpdate = false

/** @type {string | undefined} */
let nextVersion
Expand Down Expand Up @@ -54,7 +54,7 @@ module.exports = async function setupUpdater (
/** @type {import('./typings').Context} */ ctx
) {
ctx.getUpdaterStatus = function getUpdaterStatus () {
return { updateAvailable: updateDownloaded }
return { readyToUpdate }
}

ctx.openReleaseNotes = openReleaseNotes
Expand Down Expand Up @@ -167,7 +167,7 @@ function onUpdateNotAvailable ({ version }) {
* @param {import('electron-updater').UpdateDownloadedEvent} event
*/
function onUpdateDownloaded (ctx, { version /*, releaseNotes */ }) {
updateDownloaded = true
readyToUpdate = true
log.info(`update to ${version} downloaded`)

const showUpdateDialog = () => {
Expand All @@ -192,7 +192,7 @@ function onUpdateDownloaded (ctx, { version /*, releaseNotes */ }) {
// showUpdateDialog() offers the user to restart
} else if (ctx.isShowingUI) {
// show unobtrusive notification + dialog on click
ipcMain.emit(ipcMainEvents.UPDATE_AVAILABLE)
ipcMain.emit(ipcMainEvents.READY_TO_UPDATE)
updateNotification = new Notification({
title: 'Filecoin Station Update',
body: `An update to Filecoin Station ${version} is available.`
Expand Down
10 changes: 5 additions & 5 deletions renderer/src/components/UpdateBanner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@ import Warning from '../assets/img/icons/error.svg?react'
import { openReleaseNotes, restartToUpdate } from '../lib/station-config'

const UpdateBanner = () => {
const [isUpdateAvailable, setIsUpdateAvailable] = useState<boolean>(false)
const [isReadyToUpdate, setIsReadyToUpdate] = useState<boolean>(false)

useEffect(() => {
const reload = async () => {
const updateStatus = await window.electron.getUpdaterStatus()
setIsUpdateAvailable(updateStatus.updateAvailable)
setIsReadyToUpdate(updateStatus.readyToUpdate)
}

reload()
const unsubscribeUpdateNotification = window.electron.stationEvents.onUpdateAvailable(() => {
setIsUpdateAvailable(true)
const unsubscribeUpdateNotification = window.electron.stationEvents.onReadyToUpdate(() => {
setIsReadyToUpdate(true)
})

return unsubscribeUpdateNotification
}, [])

if (!isUpdateAvailable) return null
if (!isReadyToUpdate) return null
return (
<div className="h-14 bg-black top-0 left-0 w-full">
<div className="h-full max-w-[844px] mx-auto flex flex-row items-center justify-between">
Expand Down
8 changes: 4 additions & 4 deletions renderer/src/test/dashboard.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ describe('Dashboard page', () => {
describe('Unpopulated', () => {
const onActivityLogged = vi.fn((callback) => () => ({}))
const onJobProcessed = vi.fn((callback) => () => ({}))
const onUpdateAvailable = vi.fn((callback) => () => ({}))
const onReadyToUpdate = vi.fn((callback) => () => ({}))
const onTransactionUpdate = vi.fn((callback) => () => ({}))
const onBalanceUpdate = vi.fn((callback) => () => ({}))
const onScheduledRewardsUpdate = vi.fn((callback) => () => ({}))
Expand Down Expand Up @@ -94,7 +94,7 @@ describe('Dashboard page', () => {
stationEvents: {
onActivityLogged,
onJobProcessed,
onUpdateAvailable,
onReadyToUpdate,
onTransactionUpdate,
onScheduledRewardsUpdate,
onBalanceUpdate
Expand Down Expand Up @@ -153,7 +153,7 @@ describe('Dashboard page', () => {
return () => ({})
})

const onUpdateAvailable = vi.fn((callback) => () => ({}))
const onReadyToUpdate = vi.fn((callback) => () => ({}))
const onTransactionUpdate = vi.fn((callback) => () => ({}))
const onBalanceUpdate = vi.fn((callback) => () => ({}))
const getUpdaterStatus = vi.fn(() => new Promise((resolve, reject) => ({})))
Expand Down Expand Up @@ -192,7 +192,7 @@ describe('Dashboard page', () => {
stationEvents: {
onActivityLogged,
onJobProcessed,
onUpdateAvailable,
onReadyToUpdate,
onTransactionUpdate,
onScheduledRewardsUpdate,
onBalanceUpdate
Expand Down
4 changes: 2 additions & 2 deletions renderer/src/test/wallet-interaction.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe('Dashboard wallet interactions', () => {
const onActivityLogged = vi.fn((callback) => () => ({}))
const onEarningsChanged = vi.fn((callback) => () => ({}))
const onJobProcessed = vi.fn((callback) => () => ({}))
const onUpdateAvailable = vi.fn((callback) => () => ({}))
const onReadyToUpdate = vi.fn((callback) => () => ({}))
const onTransactionUpdate = vi.fn((callback) => () => ({}))
const onBalanceUpdate = vi.fn((callback) => () => ({}))
const onScheduledRewardsUpdate = vi.fn((callback) => () => ({}))
Expand Down Expand Up @@ -71,7 +71,7 @@ describe('Dashboard wallet interactions', () => {
onActivityLogged,
onEarningsChanged,
onJobProcessed,
onUpdateAvailable,
onReadyToUpdate,
onTransactionUpdate,
onScheduledRewardsUpdate,
onBalanceUpdate
Expand Down
4 changes: 2 additions & 2 deletions renderer/src/test/wallet.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe('Dashboard wallet display', () => {
const onActivityLogged = vi.fn((callback) => () => ({}))
const onEarningsChanged = vi.fn((callback) => () => ({}))
const onJobProcessed = vi.fn((callback) => () => ({}))
const onUpdateAvailable = vi.fn((callback) => () => ({}))
const onReadyToUpdate = vi.fn((callback) => () => ({}))
const onTransactionUpdate = vi.fn((callback) => () => ({}))
const onBalanceUpdate = vi.fn((callback) => () => ({}))
const onScheduledRewardsUpdate = vi.fn((callback) => () => ({}))
Expand Down Expand Up @@ -64,7 +64,7 @@ describe('Dashboard wallet display', () => {
onActivityLogged,
onEarningsChanged,
onJobProcessed,
onUpdateAvailable,
onReadyToUpdate,
onTransactionUpdate,
onBalanceUpdate,
onScheduledRewardsUpdate
Expand Down
4 changes: 2 additions & 2 deletions renderer/src/typings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ declare global {
getActivities(): Promise<Activity[]>;
getTotalJobsCompleted(): Promise<number>;
onJobStatsUpdated (callback: (totalJobCount: number) => void): () => void;
getUpdaterStatus(): Promise<{updateAvailable: boolean}>;
getUpdaterStatus(): Promise<{readyToUpdate: boolean}>;
openReleaseNotes(): void;
restartToUpdate(): void;

Expand All @@ -32,7 +32,7 @@ declare global {
onActivityLogged: (callback: (activity: Activity) => void) => () => void;
onJobProcessed: (callback: (value: number) => void) => () => void;
onEarningsChanged: (callback: (value: number) => void) => () => void;
onUpdateAvailable: (callback: () => void) => () => void;
onReadyToUpdate: (callback: () => void) => () => void;
onTransactionUpdate:
(callback: (allTransactions: (FILTransaction|FILTransactionProcessing)[]) => void) => () => void;
onBalanceUpdate: (callback: (balance: string) => void) => () => void;
Expand Down

0 comments on commit bf910b3

Please sign in to comment.