Skip to content

Commit

Permalink
Update packages to electron 32 (#182)
Browse files Browse the repository at this point in the history
* Remove minor TS warnings

* Temporarily remove eslint from dependencies

It has some sort of node requirement which prevents upgrading anything
else.

* Upgrade all packages to latest

* Update date-fns calls to new version

* Remove asset loading in main process WebPack config

The main process should have no assets.

* Downgrade webpack-asset-relocator-loader to 1.7.3

See electron/forge#3600

* Fix calls to formatDistanceToNow by fixing definitions of timestamps

updatedAt and gitnewsSeenAt are quite different and their types were
wrong.

* Install octokit

* Update tests to remove chai and sinon

* Remove chai and sinon

* Set node version in GH actions

* Fix TS errors in middleware

* Remove octokit

* Add semver types

* Downgrade electron-store to 8.2

This prevents the issue described here: sindresorhus/electron-store#276

The recommended solution that issue is to convert the entire project to
ESM, which I've attempted in #183, but it doesn't seem to work because
of incompatibilities between Webpack and Electron Forge that I haven't
been able to resolve. So for now I'm just going to downgrade.
(The app works fine with or without the errors.)

* Ignore extras directory
  • Loading branch information
sirbrillig authored Sep 7, 2024
1 parent 9fc1809 commit 7fe279a
Show file tree
Hide file tree
Showing 21 changed files with 3,966 additions and 5,551 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: '20.x'
- run: yarn install
- run: yarn test
- run: yarn typecheck
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.env
extras
node_modules
dist
icon-experiments
Expand Down
1 change: 1 addition & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
yarn lint-staged
203 changes: 89 additions & 114 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,116 +1,91 @@
{
"name": "gitnews-menubar",
"version": "1.9.0",
"description": "GitHub notifications in your menu bar",
"productName": "Gitnews",
"main": ".webpack/main",
"scripts": {
"start": "electron-forge start",
"dist-clean": "rm -rf dist && rm -rf node_modules",
"prepare-release": "npm run dist-clean && npm run build",
"build": "yarn && yarn make",
"test": "jest",
"typecheck": "yarn tsc --noEmit",
"package": "electron-forge package",
"make": "electron-forge make"
},
"keywords": [
"menu",
"github",
"notifications"
],
"author": "Payton Swick <[email protected]>",
"license": "MIT",
"dependencies": {
"@typescript-eslint/eslint-plugin": "^5.47.0",
"@typescript-eslint/parser": "^5.47.0",
"date-fns": "^1.30.1",
"debug": "^4.3.1",
"dotenv": "^16.0.3",
"easy-auto-launch": "^6.0.2",
"electron-debug": "^3.1.0",
"electron-is-dev": "^1.2.0",
"electron-log": "^4.4.8",
"electron-squirrel-startup": "^1.0.0",
"electron-store": "^8.1.0",
"electron-unhandled": "^4.0.1",
"eslint-config-react-typescript": "^1.0.10",
"eslint-plugin-import": "^2.26.0",
"gitnews": "^3.1.3",
"gridicons": "^3.3.1",
"jest": "^29.3.1",
"jest-environment-jsdom": "^29.3.1",
"menubar": "^9.2.3",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-redux": "^5.1.2",
"redux": "^4.0.5",
"redux-logger": "^3.0.6",
"redux-persist": "^6.0.0",
"semver": "^7.5.2",
"source-map-support": "^0.5.19"
},
"devDependencies": {
"@babel/plugin-proposal-class-properties": "^7.18.6",
"@babel/plugin-transform-runtime": "^7.19.6",
"@babel/preset-react": "^7.18.6",
"@babel/preset-typescript": "^7.18.6",
"@electron-forge/cli": "^6.0.4",
"@electron-forge/maker-deb": "^6.0.4",
"@electron-forge/maker-rpm": "^6.0.4",
"@electron-forge/maker-squirrel": "^6.0.4",
"@electron-forge/maker-zip": "^6.0.4",
"@electron-forge/plugin-webpack": "^6.0.4",
"@types/debug": "^4.1.7",
"@types/react": "^18.0.26",
"@types/react-dom": "^18.0.9",
"@types/react-redux": "^7.1.24",
"@types/redux-logger": "^3.0.9",
"@vercel/webpack-asset-relocator-loader": "1.7.3",
"chai": "^4.0.0",
"chai-sinon": "^2.8.1",
"copy-webpack-plugin": "^11.0.0",
"electron": "^22.3.25",
"electron-react-devtools": "^0.5.3",
"electron-webpack": "^2.8.2",
"eslint": "^8.30.0",
"eslint-config-prettier": "^6.11.0",
"eslint-config-wpcalypso": "^4.0.1",
"eslint-plugin-prettier": "^3.1.4",
"eslint-plugin-react": "^7.20.5",
"eslint-plugin-react-hooks": "^2.5.1",
"eslint-plugin-wpcalypso": "^4.1.0",
"husky": "^4.2.5",
"lint-staged": "^10.2.11",
"node-loader": "^2.0.0",
"prettier": "^2.8.1",
"sinon": "^7.5.0",
"ts-loader": "^9.4.2",
"typescript": "^4.9.4",
"webpack": "^5.94.0"
},
"repository": {
"type": "git",
"url": "git+https://github.com/sirbrillig/gitnews-menubar.git"
},
"bugs": {
"url": "https://github.com/sirbrillig/gitnews-menubar/issues"
},
"homepage": "https://github.com/sirbrillig/gitnews-menubar#readme",
"electronWebpack": {
"renderer": {
"template": "src/renderer/index.html"
}
},
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"lint-staged": {
"*.{js,ts,tsx}": [
"eslint --fix",
"prettier --write"
]
}
"name": "gitnews-menubar",
"version": "1.9.0",
"description": "GitHub notifications in your menu bar",
"productName": "Gitnews",
"main": ".webpack/main",
"scripts": {
"start": "electron-forge start",
"dist-clean": "rm -rf dist && rm -rf node_modules",
"prepare-release": "npm run dist-clean && npm run build",
"build": "yarn && yarn make",
"test": "jest",
"typecheck": "yarn tsc --noEmit",
"package": "electron-forge package",
"make": "electron-forge make"
},
"keywords": ["menu", "github", "notifications"],
"author": "Payton Swick <[email protected]>",
"license": "MIT",
"dependencies": {
"@types/semver": "^7.5.8",
"date-fns": "^3.6.0",
"debug": "^4.3.7",
"dotenv": "^16.4.5",
"easy-auto-launch": "^6.0.2",
"electron-debug": "^4.0.1",
"electron-is-dev": "^3.0.1",
"electron-log": "^5.2.0",
"electron-squirrel-startup": "^1.0.1",
"electron-store": "^8.2.0",
"electron-unhandled": "^5.0.0",
"gitnews": "^3.1.3",
"gridicons": "^3.4.2",
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.7.0",
"menubar": "^9.5.0",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-redux": "^9.1.2",
"redux": "^5.0.1",
"redux-logger": "^3.0.6",
"redux-persist": "^6.0.0",
"semver": "^7.6.3",
"source-map-support": "^0.5.19"
},
"devDependencies": {
"@babel/plugin-proposal-class-properties": "^7.18.6",
"@babel/plugin-transform-runtime": "^7.25.4",
"@babel/preset-react": "^7.24.7",
"@babel/preset-typescript": "^7.24.7",
"@electron-forge/cli": "^7.4.0",
"@electron-forge/maker-deb": "^7.4.0",
"@electron-forge/maker-rpm": "^7.4.0",
"@electron-forge/maker-squirrel": "^7.4.0",
"@electron-forge/maker-zip": "^7.4.0",
"@electron-forge/plugin-webpack": "^7.4.0",
"@types/debug": "^4.1.12",
"@types/react": "^18.3.5",
"@types/react-dom": "^18.3.0",
"@types/react-redux": "^7.1.33",
"@types/redux-logger": "^3.0.13",
"@vercel/webpack-asset-relocator-loader": "1.7.3",
"copy-webpack-plugin": "^12.0.2",
"electron": "^32.0.2",
"electron-react-devtools": "^0.5.3",
"electron-webpack": "^2.8.2",
"husky": "^9.1.5",
"lint-staged": "^15.2.10",
"node-loader": "^2.0.0",
"prettier": "^3.3.3",
"ts-loader": "^9.5.1",
"typescript": "^5.5.4",
"webpack": "^5.94.0"
},
"repository": {
"type": "git",
"url": "git+https://github.com/sirbrillig/gitnews-menubar.git"
},
"bugs": {
"url": "https://github.com/sirbrillig/gitnews-menubar/issues"
},
"homepage": "https://github.com/sirbrillig/gitnews-menubar#readme",
"electronWebpack": {
"renderer": {
"template": "src/renderer/index.html"
}
},
"lint-staged": {
"*.{js,ts,tsx}": ["prettier --write"]
}
}
12 changes: 6 additions & 6 deletions src/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,24 +109,24 @@ systemPreferences.subscribeNotification(

ipcMain.on(
'log-message',
(event, message: string, level: 'info' | 'warn' | 'error') => {
(_event, message: string, level: 'info' | 'warn' | 'error') => {
logMessage(message, level);
}
);

ipcMain.on('toggle-logging', (event, isLogging: boolean) => {
ipcMain.on('toggle-logging', (_event, isLogging: boolean) => {
toggleLogging(isLogging);
});

ipcMain.on('set-icon', (event, arg: unknown) => {
ipcMain.on('set-icon', (_event, arg: unknown) => {
if (typeof arg !== 'string') {
logMessage('Failed to set icon: it is invalid', 'error');
return;
}
setIcon(arg);
});

ipcMain.on('open-url', (event, url: unknown, options) => {
ipcMain.on('open-url', (_event, url: unknown, options) => {
logMessage(`Opening url: ${url}`, 'info');
if (typeof url !== 'string') {
logMessage('Failed to open URL: it is invalid', 'error');
Expand All @@ -139,7 +139,7 @@ ipcMain.on('quit-app', () => {
app.quit();
});

ipcMain.on('save-token', (event, token: unknown) => {
ipcMain.on('save-token', (_event, token: unknown) => {
if (typeof token !== 'string') {
logMessage('Failed to save token: it is invalid', 'error');
return;
Expand All @@ -152,7 +152,7 @@ const autoLauncher = new AutoLaunch({
name: 'Gitnews',
});

ipcMain.on('toggle-auto-launch', (event, isEnabled) => {
ipcMain.on('toggle-auto-launch', (_event, isEnabled) => {
logMessage(`AutoLaunch changed to ${isEnabled}`, 'info');
if (isEnabled) {
autoLauncher.enable();
Expand Down
10 changes: 4 additions & 6 deletions src/renderer/components/last-checked.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import date from 'date-fns';
import { formatDistanceToNow } from 'date-fns';
import { AppReduxState } from '../types';

export default function LastChecked({
Expand All @@ -10,11 +10,9 @@ export default function LastChecked({
if (!lastSuccessfulCheck) {
return null;
}
const lastCheckedString = date.distanceInWords(
Date.now(),
date.parse(lastSuccessfulCheck),
{ addSuffix: true }
);
const lastCheckedString = formatDistanceToNow(new Date(lastSuccessfulCheck), {
addSuffix: true,
});

return (
<div className="last-checked">{'last checked: ' + lastCheckedString}</div>
Expand Down
9 changes: 3 additions & 6 deletions src/renderer/components/notification.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import Gridicon from 'gridicons';
import debugFactory from 'debug';
import date from 'date-fns';
import { formatDistanceToNow } from 'date-fns';
import EnsuredImage from './ensured-image';
import MuteIcon from './mute-icon';
import {
Expand Down Expand Up @@ -58,11 +58,8 @@ export default function Notification({
openUrl(note.commentUrl);
};

const timeString = date.distanceInWords(
Date.now(),
date.parse(note.updatedAt),
{ addSuffix: true }
);
const lastUpdated = new Date(note.updatedAt);
const timeString = formatDistanceToNow(lastUpdated, { addSuffix: true });
const noteClasses = [
'notification',
...(isMultiOpenMode && !isMultiOpenPending
Expand Down
7 changes: 6 additions & 1 deletion src/renderer/gitnews.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@ declare module 'gitnews' {
repositoryFullName: string;
api: NoteApi;
commentUrl: string;
updatedAt: number;

/**
* ISO 8601 formatted date string like `2017-08-23T18:20:00Z`.
*/
updatedAt: string;

repositoryName: string;
type: string;
subjectUrl: string;
Expand Down
10 changes: 7 additions & 3 deletions src/renderer/lib/config-middleware.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import { Middleware } from 'redux';
import { AppReduxState, AppReduxAction } from '../types';
import { AppReduxState } from '../types';
import { isAction } from './helpers';

export const configMiddleware: Middleware<object, AppReduxState> =
(store) => (next) => (action: AppReduxAction) => {
export const configMiddleware: Middleware<{}, AppReduxState> =
(_store) => (next) => (action) => {
if (!isAction(action)) {
throw new Error('Invalid action dispatched');
}
switch (action.type) {
case 'SET_INITIAL_TOKEN':
window.electronApi.saveToken(action.token);
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/lib/demo-mode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function createDemoNotification(initialDate: Date): Note {
return {
updatedAt: new Date(
initialDate.getTime() - hourInMiliseconds * randomNumber(1, 23)
).getTime(),
).toISOString(),
unread: isUnread,
repositoryName,
repositoryFullName: `${owner}/${repositoryName}`,
Expand Down
10 changes: 7 additions & 3 deletions src/renderer/lib/electron-middleware.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Middleware } from 'redux';
import { AppReduxAction, AppReduxState, IconType } from '../types';
import { AppReduxState, IconType } from '../types';
import { isAction } from './helpers';

function openUrl(url: string) {
window.electronApi.openUrl(url);
Expand All @@ -13,8 +14,11 @@ function scrollToTopNotification() {
window.scrollTo(0, 0);
}

export const electronMiddleware: Middleware<object, AppReduxState> =
(store) => (next) => (action: AppReduxAction) => {
export const electronMiddleware: Middleware<{}, AppReduxState> =
(_store) => (next) => (action) => {
if (!isAction(action)) {
throw new Error('Invalid action dispatched');
}
switch (action.type) {
case 'OPEN_URL':
return openUrl(action.url);
Expand Down
Loading

0 comments on commit 7fe279a

Please sign in to comment.