Skip to content

Commit 75ca1b8

Browse files
committed
Merge branch 'main' into refactor/primer-design-system
Signed-off-by: Adam Setch <[email protected]>
2 parents 3a3572d + 4d1a241 commit 75ca1b8

27 files changed

+345
-143
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Gitify
22

3-
[![Build Workflow][build-workflow-badge]][github-actions] [![Release Workflow][release-workflow-badge]][github-actions] [![Coveralls][coveralls-badge]][coveralls] [![Renovate enabled][renovate-badge]][renovate] [![Libraries.io dependency status][librariesio-badge]][librariesio] [![Contributors][contributors-badge]][github] [![Downloads - Total][downloads-total-badge]][website] [![Downloads - Latest Release][downloads-latest-badge]][website] [![OSS License][license-badge]][license] [![Latest Release][github-release-badge]][github-releases] [![Homebrew Cask][homebrew-cask-badge]][homebrew-cask]
3+
[![CI Workflow][ci-workflow-badge]][github-actions] [![Release Workflow][release-workflow-badge]][github-actions] [![Coveralls][coveralls-badge]][coveralls] [![Renovate enabled][renovate-badge]][renovate] [![Contributors][contributors-badge]][github] [![Downloads - Total][downloads-total-badge]][website] [![Downloads - Latest Release][downloads-latest-badge]][website] [![OSS License][license-badge]][license] [![Latest Release][github-release-badge]][github-releases] [![Homebrew Cask][homebrew-cask-badge]][homebrew-cask]
44

55
> GitHub Notifications on your menu bar. Available on macOS, Windows and Linux.
66
@@ -33,22 +33,22 @@ For more information, see [LICENSE](LICENSE).
3333
<!-- LINK LABELS -->
3434
[website]: https://www.gitify.io
3535
[faqs]: https://www.gitify.io/faq/
36+
3637
[github]: https://github.com/gitify-app/gitify
3738
[github-actions]: https://github.com/gitify-app/gitify/actions
3839
[github-releases]: https://github.com/gitify-app/gitify/releases/latest
3940
[github-website]: https://github.com/gitify-app/website
4041
[github-website-pulls]: https://github.com/gitify-app/website/pulls
4142
[brew]: https://brew.sh/
4243
[homebrew-cask]: https://formulae.brew.sh/cask/gitify
44+
4345
[coveralls]: https://coveralls.io/github/gitify-app/gitify
4446
[coveralls-badge]: https://img.shields.io/coverallsCoverage/github/gitify-app/gitify?logo=coveralls
45-
[build-workflow-badge]: https://github.com/gitify-app/gitify/actions/workflows/build.yml/badge.svg
47+
[ci-workflow-badge]: https://github.com/gitify-app/gitify/actions/workflows/ci.yml/badge.svg
4648
[release-workflow-badge]: https://github.com/gitify-app/gitify/actions/workflows/release.yml/badge.svg
4749
[downloads-total-badge]: https://img.shields.io/github/downloads/gitify-app/gitify/total?label=downloads@all&logo=github
4850
[downloads-latest-badge]: https://img.shields.io/github/downloads/gitify-app/gitify/latest/total?logo=github
4951
[contributors-badge]: https://img.shields.io/github/contributors/gitify-app/gitify?logo=github
50-
[librariesio]: https://libraries.io/
51-
[librariesio-badge]: https://img.shields.io/librariesio/github/gitify-app/gitify?logo=librariesdotio
5252
[license]: LICENSE
5353
[license-badge]: https://img.shields.io/github/license/gitify-app/gitify?logo=github
5454
[github-release-badge]: https://img.shields.io/github/v/release/gitify-app/gitify?logo=github

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
"bugs": {
6666
"url": "https://github.com/gitify-app/gitify/issues"
6767
},
68-
"homepage": "https://www.gitify.io/",
68+
"homepage": "https://gitify.io/",
6969
"build": {
7070
"productName": "Gitify",
7171
"appId": "com.electron.gitify",
@@ -132,7 +132,7 @@
132132
"menubar": "9.5.1",
133133
"react": "19.0.0",
134134
"react-dom": "19.0.0",
135-
"react-router-dom": "7.1.1",
135+
"react-router-dom": "7.1.3",
136136
"update-electron-app": "3.1.0"
137137
},
138138
"devDependencies": {

pnpm-lock.yaml

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main/first-run.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ import fs from 'node:fs';
22
import path from 'node:path';
33
import { app, dialog } from 'electron';
44

5+
import { APPLICATION } from '../shared/constants';
56
import { logError } from '../shared/logger';
7+
import { isMacOS } from '../shared/platform';
68

79
export async function onFirstRunMaybe() {
810
if (isFirstRun()) {
@@ -12,7 +14,7 @@ export async function onFirstRunMaybe() {
1214

1315
// Ask user if the app should be moved to the applications folder.
1416
async function promptMoveToApplicationsFolder() {
15-
if (process.platform !== 'darwin') return;
17+
if (!isMacOS()) return;
1618

1719
const isDevMode = !!process.defaultApp;
1820
if (isDevMode || app.isInApplicationsFolder()) return;
@@ -31,7 +33,7 @@ async function promptMoveToApplicationsFolder() {
3133

3234
const getConfigPath = () => {
3335
const userDataPath = app.getPath('userData');
34-
return path.join(userDataPath, 'FirstRun', 'gitify-first-run');
36+
return path.join(userDataPath, 'FirstRun', APPLICATION.FIRST_RUN_FOLDER);
3537
};
3638

3739
// Whether or not the app is being run for the first time.

src/main/main.ts

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ import { app, globalShortcut, ipcMain as ipc, nativeTheme } from 'electron';
22
import log from 'electron-log';
33
import { menubar } from 'menubar';
44

5+
import { APPLICATION } from '../shared/constants';
6+
import { namespacedEvent } from '../shared/events';
7+
import { isMacOS, isWindows } from '../shared/platform';
58
import { onFirstRunMaybe } from './first-run';
69
import { TrayIcons } from './icons';
710
import MenuBuilder from './menu';
@@ -38,8 +41,9 @@ const contextMenu = menuBuilder.buildMenu();
3841
* Electron Auto Updater only supports macOS and Windows
3942
* https://github.com/electron/update-electron-app
4043
*/
41-
if (process.platform === 'darwin' || process.platform === 'win32') {
42-
new Updater(mb, menuBuilder);
44+
if (isMacOS() || isWindows()) {
45+
const updater = new Updater(mb, menuBuilder);
46+
updater.initialize();
4347
}
4448

4549
let shouldUseAlternateIdleIcon = false;
@@ -48,7 +52,7 @@ app.whenReady().then(async () => {
4852
await onFirstRunMaybe();
4953

5054
mb.on('ready', () => {
51-
mb.app.setAppUserModelId('com.electron.gitify');
55+
mb.app.setAppUserModelId(APPLICATION.ID);
5256

5357
/**
5458
* TODO: Remove @electron/remote use - see #650
@@ -58,7 +62,7 @@ app.whenReady().then(async () => {
5862
require('@electron/remote/main').enable(mb.window.webContents);
5963

6064
// Tray configuration
61-
mb.tray.setToolTip('Gitify');
65+
mb.tray.setToolTip(APPLICATION.NAME);
6266
mb.tray.setIgnoreDoubleClickEvents(true);
6367
mb.tray.on('right-click', (_event, bounds) => {
6468
mb.tray.popUpContextMenu(contextMenu, { x: bounds.x, y: bounds.y });
@@ -90,63 +94,66 @@ app.whenReady().then(async () => {
9094

9195
nativeTheme.on('updated', () => {
9296
if (nativeTheme.shouldUseDarkColors) {
93-
mb.window.webContents.send('gitify:update-theme', 'DARK');
97+
mb.window.webContents.send(namespacedEvent('update-theme'), 'DARK');
9498
} else {
95-
mb.window.webContents.send('gitify:update-theme', 'LIGHT');
99+
mb.window.webContents.send(namespacedEvent('update-theme'), 'LIGHT');
96100
}
97101
});
98102

99103
/**
100104
* Gitify custom IPC events
101105
*/
102-
ipc.handle('gitify:version', () => app.getVersion());
106+
ipc.handle(namespacedEvent('version'), () => app.getVersion());
103107

104-
ipc.on('gitify:window-show', () => mb.showWindow());
108+
ipc.on(namespacedEvent('window-show'), () => mb.showWindow());
105109

106-
ipc.on('gitify:window-hide', () => mb.hideWindow());
110+
ipc.on(namespacedEvent('window-hide'), () => mb.hideWindow());
107111

108-
ipc.on('gitify:quit', () => mb.app.quit());
112+
ipc.on(namespacedEvent('quit'), () => mb.app.quit());
109113

110-
ipc.on('gitify:use-alternate-idle-icon', (_, useAlternateIdleIcon) => {
111-
shouldUseAlternateIdleIcon = useAlternateIdleIcon;
112-
});
114+
ipc.on(
115+
namespacedEvent('use-alternate-idle-icon'),
116+
(_, useAlternateIdleIcon) => {
117+
shouldUseAlternateIdleIcon = useAlternateIdleIcon;
118+
},
119+
);
113120

114-
ipc.on('gitify:icon-active', () => {
121+
ipc.on(namespacedEvent('icon-active'), () => {
115122
if (!mb.tray.isDestroyed()) {
116123
mb.tray.setImage(
117-
menuBuilder.isUpdateAvailableMenuVisible()
124+
menuBuilder.isUpdateAvailable()
118125
? TrayIcons.activeUpdateIcon
119126
: TrayIcons.active,
120127
);
121128
}
122129
});
123130

124-
ipc.on('gitify:icon-idle', () => {
131+
ipc.on(namespacedEvent('icon-idle'), () => {
125132
if (!mb.tray.isDestroyed()) {
126133
if (shouldUseAlternateIdleIcon) {
127134
mb.tray.setImage(
128-
menuBuilder.isUpdateAvailableMenuVisible()
135+
menuBuilder.isUpdateAvailable()
129136
? TrayIcons.idleAlternateUpdateIcon
130137
: TrayIcons.idleAlternate,
131138
);
132139
} else {
133140
mb.tray.setImage(
134-
menuBuilder.isUpdateAvailableMenuVisible()
141+
menuBuilder.isUpdateAvailable()
135142
? TrayIcons.idleUpdateIcon
136143
: TrayIcons.idle,
137144
);
138145
}
139146
}
140147
});
141148

142-
ipc.on('gitify:update-title', (_, title) => {
149+
ipc.on(namespacedEvent('update-title'), (_, title) => {
143150
if (!mb.tray.isDestroyed()) {
144151
mb.tray.setTitle(title);
145152
}
146153
});
147154

148155
ipc.on(
149-
'gitify:update-keyboard-shortcut',
156+
namespacedEvent('update-keyboard-shortcut'),
150157
(_, { enabled, keyboardShortcut }) => {
151158
if (!enabled) {
152159
globalShortcut.unregister(keyboardShortcut);
@@ -163,7 +170,7 @@ app.whenReady().then(async () => {
163170
},
164171
);
165172

166-
ipc.on('gitify:update-auto-launch', (_, settings) => {
173+
ipc.on(namespacedEvent('update-auto-launch'), (_, settings) => {
167174
app.setLoginItemSettings(settings);
168175
});
169176
});

src/main/menu.test.ts

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
import { Menu, MenuItem } from 'electron';
2+
import type { Menubar } from 'menubar';
3+
import MenuBuilder from './menu';
4+
5+
jest.mock('electron', () => ({
6+
Menu: {
7+
buildFromTemplate: jest.fn(),
8+
},
9+
MenuItem: jest.fn(),
10+
}));
11+
12+
describe('main/menu.ts', () => {
13+
let menubar: Menubar;
14+
let menuBuilder: MenuBuilder;
15+
16+
beforeEach(() => {
17+
menuBuilder = new MenuBuilder(menubar);
18+
});
19+
20+
it('should create menu items correctly', () => {
21+
expect(MenuItem).toHaveBeenCalledWith({
22+
label: 'Check for updates',
23+
enabled: true,
24+
click: expect.any(Function),
25+
});
26+
27+
expect(MenuItem).toHaveBeenCalledWith({
28+
label: 'No updates available',
29+
enabled: false,
30+
visible: false,
31+
});
32+
33+
expect(MenuItem).toHaveBeenCalledWith({
34+
label: 'An update is available',
35+
enabled: false,
36+
visible: false,
37+
});
38+
39+
expect(MenuItem).toHaveBeenCalledWith({
40+
label: 'Restart to install update',
41+
enabled: true,
42+
visible: false,
43+
click: expect.any(Function),
44+
});
45+
});
46+
47+
it('should build menu correctly', () => {
48+
menuBuilder.buildMenu();
49+
expect(Menu.buildFromTemplate).toHaveBeenCalledWith(expect.any(Array));
50+
});
51+
52+
it('should enable check for updates menu item', () => {
53+
menuBuilder.setCheckForUpdatesMenuEnabled(true);
54+
// biome-ignore lint/complexity/useLiteralKeys: This is a test
55+
expect(menuBuilder['checkForUpdatesMenuItem'].enabled).toBe(true);
56+
});
57+
58+
it('should disable check for updates menu item', () => {
59+
menuBuilder.setCheckForUpdatesMenuEnabled(false);
60+
// biome-ignore lint/complexity/useLiteralKeys: This is a test
61+
expect(menuBuilder['checkForUpdatesMenuItem'].enabled).toBe(false);
62+
});
63+
64+
it('should show no update available menu item', () => {
65+
menuBuilder.setNoUpdateAvailableMenuVisibility(true);
66+
// biome-ignore lint/complexity/useLiteralKeys: This is a test
67+
expect(menuBuilder['noUpdateAvailableMenuItem'].visible).toBe(true);
68+
});
69+
70+
it('should hide no update available menu item', () => {
71+
menuBuilder.setNoUpdateAvailableMenuVisibility(false);
72+
// biome-ignore lint/complexity/useLiteralKeys: This is a test
73+
expect(menuBuilder['noUpdateAvailableMenuItem'].visible).toBe(false);
74+
});
75+
76+
it('should show update available menu item', () => {
77+
menuBuilder.setUpdateAvailableMenuVisibility(true);
78+
// biome-ignore lint/complexity/useLiteralKeys: This is a test
79+
expect(menuBuilder['updateAvailableMenuItem'].visible).toBe(true);
80+
});
81+
82+
it('should hide update available menu item', () => {
83+
menuBuilder.setUpdateAvailableMenuVisibility(false);
84+
// biome-ignore lint/complexity/useLiteralKeys: This is a test
85+
expect(menuBuilder['updateAvailableMenuItem'].visible).toBe(false);
86+
});
87+
88+
it('should show update ready for install menu item', () => {
89+
menuBuilder.setUpdateReadyForInstallMenuVisibility(true);
90+
// biome-ignore lint/complexity/useLiteralKeys: This is a test
91+
expect(menuBuilder['updateReadyForInstallMenuItem'].visible).toBe(true);
92+
});
93+
94+
it('should show update ready for install menu item', () => {
95+
menuBuilder.setUpdateReadyForInstallMenuVisibility(false);
96+
// biome-ignore lint/complexity/useLiteralKeys: This is a test
97+
expect(menuBuilder['updateReadyForInstallMenuItem'].visible).toBe(false);
98+
});
99+
});

0 commit comments

Comments
 (0)