-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
164 additions
and
31 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
owner: onlook-dev | ||
repo: studio | ||
repo: onlook | ||
provider: github |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import pkg from 'electron-updater'; | ||
const { autoUpdater } = pkg; | ||
|
||
import log from 'electron-log'; | ||
import { mainWindow } from '..'; | ||
import { MainChannels } from '/common/constants'; | ||
|
||
class AppUpdater { | ||
static instance: AppUpdater | null = null; | ||
|
||
static getInstance() { | ||
if (!AppUpdater.instance) { | ||
AppUpdater.instance = new AppUpdater(); | ||
} | ||
return AppUpdater.instance; | ||
} | ||
|
||
private constructor() { | ||
if (AppUpdater.instance) { | ||
return AppUpdater.instance; | ||
} | ||
|
||
log.transports.file.level = 'info'; | ||
autoUpdater.logger = log; | ||
autoUpdater.autoDownload = true; | ||
AppUpdater.instance = this; | ||
} | ||
|
||
quitAndInstall() { | ||
autoUpdater.quitAndInstall(); | ||
} | ||
|
||
listen() { | ||
const checkForUpdates = () => { | ||
autoUpdater.checkForUpdates().catch((err) => { | ||
log.error('Error checking for updates:', err); | ||
}); | ||
}; | ||
|
||
checkForUpdates(); | ||
setInterval(checkForUpdates, 60 * 60 * 1000); | ||
|
||
autoUpdater.on('update-available', () => { | ||
log.info('Update available'); | ||
}); | ||
|
||
autoUpdater.on('update-not-available', () => { | ||
log.info('Update not available'); | ||
mainWindow?.webContents.send(MainChannels.UPDATE_NOT_AVAILABLE); | ||
}); | ||
|
||
autoUpdater.on('download-progress', (progress) => { | ||
let log_message = 'Download speed: ' + progress.bytesPerSecond; | ||
log_message = log_message + ' - Downloaded ' + progress.percent + '%'; | ||
log_message = log_message + ' (' + progress.transferred + '/' + progress.total + ')'; | ||
log.info(log_message); | ||
}); | ||
|
||
autoUpdater.on('update-downloaded', () => { | ||
log.info('Update downloaded'); | ||
mainWindow?.webContents.send(MainChannels.UPDATE_DOWNLOADED); | ||
}); | ||
|
||
autoUpdater.on('error', (err) => { | ||
log.error('AutoUpdater error:', err); | ||
}); | ||
} | ||
} | ||
|
||
export const updater = AppUpdater.getInstance(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { UpdateManager } from '@/lib/update'; | ||
import { createContext, useContext } from 'react'; | ||
|
||
const UpdateContext = createContext(new UpdateManager()); | ||
export const useUpdateManager = () => useContext(UpdateContext); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { Button } from '@/components/ui/button'; | ||
import { DownloadIcon } from '@radix-ui/react-icons'; | ||
import { observer } from 'mobx-react-lite'; | ||
import { useUpdateManager } from './UpdateProvider'; | ||
|
||
const UpdateButton = observer(() => { | ||
const updateManager = useUpdateManager(); | ||
|
||
return ( | ||
updateManager.updateAvailable && ( | ||
<Button | ||
variant={'secondary'} | ||
size={'sm'} | ||
className="bg-red-500 hover:bg-red-600 h-6 rounded-sm gap-2 transition" | ||
onClick={() => { | ||
updateManager.quitAndInstall(); | ||
}} | ||
> | ||
<DownloadIcon /> | ||
<p>Install new Update</p> | ||
</Button> | ||
) | ||
); | ||
}); | ||
|
||
export default UpdateButton; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { makeAutoObservable } from 'mobx'; | ||
import { MainChannels } from '/common/constants'; | ||
|
||
export class UpdateManager { | ||
updateAvailable = false; | ||
|
||
constructor() { | ||
makeAutoObservable(this); | ||
this.listen(); | ||
} | ||
|
||
listen() { | ||
window.api.on(MainChannels.UPDATE_DOWNLOADED, async (e, args) => { | ||
this.updateAvailable = true; | ||
}); | ||
|
||
window.api.on(MainChannels.UPDATE_NOT_AVAILABLE, async (e, args) => { | ||
this.updateAvailable = false; | ||
}); | ||
} | ||
|
||
quitAndInstall() { | ||
window.api.invoke(MainChannels.QUIT_AND_INSTALL); | ||
} | ||
} |