-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1241 from responsively-org/about-window-revamp
Revamped the about window and added info about app update status
- Loading branch information
Showing
11 changed files
with
369 additions
and
133 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { autoUpdater } from 'electron-updater'; | ||
|
||
export interface AppUpdaterStatus { | ||
status: string; | ||
version?: string; | ||
lastChecked?: number; | ||
progress?: number; | ||
size?: number; | ||
error?: Error; | ||
} | ||
|
||
export class AppUpdater { | ||
status: string = 'IDLE'; | ||
|
||
version?: string; | ||
|
||
lastChecked?: number; | ||
|
||
progress?: number; | ||
|
||
size?: number; | ||
|
||
error?: Error; | ||
|
||
constructor() { | ||
autoUpdater.logger = console; | ||
autoUpdater.checkForUpdatesAndNotify(); | ||
autoUpdater.on('checking-for-update', () => { | ||
this.status = 'CHECKING'; | ||
this.lastChecked = Date.now(); | ||
}); | ||
autoUpdater.on('update-available', (info) => { | ||
this.status = 'AVAILABLE'; | ||
this.version = info.version; | ||
this.lastChecked = Date.now(); | ||
}); | ||
autoUpdater.on('update-not-available', (info) => { | ||
this.status = 'UP_TO_DATE'; | ||
this.lastChecked = Date.now(); | ||
}); | ||
autoUpdater.on('error', (err) => { | ||
this.status = 'ERROR'; | ||
this.error = err; | ||
this.lastChecked = Date.now(); | ||
}); | ||
autoUpdater.on('download-progress', (progressObj) => { | ||
const logMessage = `Download speed: ${progressObj.bytesPerSecond} - Downloaded ${progressObj.percent}% (${progressObj.transferred}/${progressObj.total})`; | ||
// eslint-disable-next-line no-console | ||
console.log(logMessage); | ||
this.status = `DOWNLOADING - ${progressObj.percent}%`; | ||
this.progress = progressObj.percent; | ||
this.size = progressObj.total; | ||
this.lastChecked = Date.now(); | ||
}); | ||
autoUpdater.on('update-downloaded', (info) => { | ||
this.status = 'DOWNLOADED (Restart to apply update)'; | ||
this.lastChecked = Date.now(); | ||
}); | ||
} | ||
|
||
getStatus(): AppUpdaterStatus { | ||
return { | ||
status: this.status, | ||
version: this.version, | ||
lastChecked: this.lastChecked, | ||
progress: this.progress, | ||
size: this.size, | ||
error: this.error, | ||
}; | ||
} | ||
} |
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,106 +1,83 @@ | ||
import { | ||
BrowserWindow, | ||
clipboard, | ||
dialog, | ||
MenuItemConstructorOptions, | ||
ipcMain, | ||
shell, | ||
} from 'electron'; | ||
import path from 'path'; | ||
|
||
import { getEnvironmentInfo, getPackageJson } from '../util'; | ||
import { EnvironmentInfo, getEnvironmentInfo } from '../util'; | ||
import { IPC_MAIN_CHANNELS } from '../../common/constants'; | ||
import { AppUpdater, AppUpdaterStatus } from '../app-updater'; | ||
|
||
const aboutOnClick = () => { | ||
const iconPath = path.join(__dirname, '../resources/icons/64x64.png'); | ||
const title = 'Responsively'; | ||
const { description } = getPackageJson(); | ||
const { | ||
appVersion, | ||
electronVersion, | ||
chromeVersion, | ||
nodeVersion, | ||
v8Version, | ||
osInfo, | ||
} = getEnvironmentInfo(); | ||
export interface AboutDialogArgs { | ||
environmentInfo: EnvironmentInfo; | ||
updaterStatus: AppUpdaterStatus; | ||
} | ||
|
||
const usefulInfo = `Version: ${appVersion}\nElectron: ${electronVersion}\nChrome: ${chromeVersion}\nNode.js: ${nodeVersion}\nV8: ${v8Version}\nOS: ${osInfo}`; | ||
const detail = description ? `${description}\n\n${usefulInfo}` : usefulInfo; | ||
let buttons = ['OK', 'Copy']; | ||
let cancelId = 0; | ||
let defaultId = 1; | ||
if (process.platform === 'linux') { | ||
buttons = ['Copy', 'OK']; | ||
cancelId = 1; | ||
defaultId = 0; | ||
} | ||
dialog | ||
.showMessageBox(BrowserWindow.getAllWindows()[0], { | ||
type: 'none', | ||
buttons, | ||
title, | ||
message: title, | ||
detail, | ||
noLink: true, | ||
icon: iconPath, | ||
cancelId, | ||
defaultId, | ||
}) | ||
.then(({ response }) => { | ||
if (response === defaultId) { | ||
clipboard.writeText(usefulInfo, 'clipboard'); | ||
} | ||
return null; | ||
}) | ||
.catch((err) => { | ||
console.error('Error opening about', err); | ||
}); | ||
}; | ||
export const subMenuHelp = ( | ||
mainWindow: BrowserWindow, | ||
appUpdater: AppUpdater | ||
): MenuItemConstructorOptions => { | ||
const environmentInfo = getEnvironmentInfo(); | ||
ipcMain.handle('get-about-info', async (_): Promise<AboutDialogArgs> => { | ||
return { | ||
environmentInfo, | ||
updaterStatus: appUpdater.getStatus(), | ||
}; | ||
}); | ||
|
||
export const subMenuHelp: MenuItemConstructorOptions = { | ||
label: 'Help', | ||
submenu: [ | ||
{ | ||
label: 'Learn More', | ||
click() { | ||
shell.openExternal('https://responsively.app'); | ||
return { | ||
label: 'Help', | ||
submenu: [ | ||
{ | ||
label: 'Learn More', | ||
click() { | ||
shell.openExternal('https://responsively.app'); | ||
}, | ||
}, | ||
{ | ||
label: 'Open Source', | ||
click() { | ||
shell.openExternal( | ||
'https://github.com/responsively-org/responsively-app' | ||
); | ||
}, | ||
}, | ||
{ | ||
label: 'Join Discord', | ||
click() { | ||
shell.openExternal('https://responsively.app/join-discord/'); | ||
}, | ||
}, | ||
}, | ||
{ | ||
label: 'Open Source', | ||
click() { | ||
shell.openExternal( | ||
'https://github.com/responsively-org/responsively-app' | ||
); | ||
{ | ||
label: 'Search Issues', | ||
click() { | ||
shell.openExternal( | ||
'https://github.com/responsively-org/responsively-app/issues' | ||
); | ||
}, | ||
}, | ||
}, | ||
{ | ||
label: 'Join Discord', | ||
click() { | ||
shell.openExternal('https://responsively.app/join-discord/'); | ||
{ | ||
label: 'Sponsor Responsively', | ||
click() { | ||
shell.openExternal( | ||
'https://responsively.app/sponsor?utm_source=app&utm_medium=menu&utm_campaign=sponsor' | ||
); | ||
}, | ||
}, | ||
}, | ||
{ | ||
label: 'Search Issues', | ||
click() { | ||
shell.openExternal( | ||
'https://github.com/responsively-org/responsively-app/issues' | ||
); | ||
{ | ||
type: 'separator', | ||
}, | ||
}, | ||
{ | ||
label: 'Sponsor Responsively', | ||
click() { | ||
shell.openExternal( | ||
'https://responsively.app/sponsor?utm_source=app&utm_medium=menu&utm_campaign=sponsor' | ||
); | ||
{ | ||
label: 'About', | ||
accelerator: 'F1', | ||
click: () => { | ||
mainWindow.webContents.send(IPC_MAIN_CHANNELS.OPEN_ABOUT_DIALOG, { | ||
environmentInfo, | ||
updaterStatus: appUpdater.getStatus(), | ||
}); | ||
}, | ||
}, | ||
}, | ||
{ | ||
type: 'separator', | ||
}, | ||
{ | ||
label: 'About', | ||
accelerator: 'F1', | ||
click: aboutOnClick, | ||
}, | ||
], | ||
], | ||
}; | ||
}; |
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
Oops, something went wrong.