Skip to content

Commit

Permalink
refactor: split code into main and renderer modules, adopt TS for mai…
Browse files Browse the repository at this point in the history
…n, and improve webpack process for bundling

Signed-off-by: Adam Setch <adam.setch@outlook.com>
  • Loading branch information
setchy committed Sep 30, 2024
1 parent 964db86 commit 26448b2
Show file tree
Hide file tree
Showing 16 changed files with 27 additions and 62 deletions.
12 changes: 1 addition & 11 deletions config/webpack.config.renderer.base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,19 +61,9 @@ const configuration: webpack.Configuration = {
isBrowser: false,
}),

// Twemoji SVGs for Emoji parsing
new CopyWebpackPlugin({
patterns: [
// Image Assets
{
from: webpackPaths.assetsImagesPath,
to: 'assets/images',
},
// Sound Assets
{
from: webpackPaths.assetsSoundsPath,
to: 'assets/sounds',
},
// Twemoji SVGs for Emojis
{
from: path.join(
webpackPaths.nodeModulesPath,
Expand Down
7 changes: 0 additions & 7 deletions config/webpack.paths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ const rootPath = path.join(__dirname, '..');

const nodeModulesPath = path.join(rootPath, 'node_modules');

const assetsPath = path.join(rootPath, 'assets');
const assetsImagesPath = path.join(assetsPath, 'images');
const assetsSoundsPath = path.join(assetsPath, 'sounds');

const srcPath = path.join(rootPath, 'src');
const srcMainPath = path.join(srcPath, 'main');
const srcRendererPath = path.join(srcPath, 'renderer');
Expand All @@ -19,9 +15,6 @@ const distPath = path.join(rootPath, 'dist');
export default {
rootPath,
nodeModulesPath,
assetsPath,
assetsImagesPath,
assetsSoundsPath,
srcPath,
srcMainPath,
srcRendererPath,
Expand Down
9 changes: 8 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,14 @@
"appId": "com.electron.gitify",
"copyright": "Copyright © 2024 Gitify Team",
"asar": true,
"files": ["build/**/*", "node_modules/**/*", "package.json", "LICENSE"],
"files": [
"assets/images/*",
"assets/sounds/*",
"build/**/*",
"LICENSE",
"node_modules/**/*",
"package.json"
],
"mac": {
"category": "public.app-category.developer-tools",
"icon": "assets/images/app-icon.icns",
Expand Down
2 changes: 1 addition & 1 deletion src/main/icons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ export const activeIcon = getIconPath('tray-active.png');
export const activeUpdateIcon = getIconPath('tray-active-update.png');

function getIconPath(iconName: string) {
return path.resolve(__dirname, '../assets/images', iconName);
return path.resolve(__dirname, '..', 'assets', 'images', iconName);
}
6 changes: 0 additions & 6 deletions src/renderer/__mocks__/utils.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
import * as helpers from '../utils/helpers';

export function mockDirectoryPath() {
jest.spyOn(helpers, 'getDirectoryPath').mockReturnValue('/mocked/dir/name');
}

/**
* Ensure stable snapshots for our randomized emoji use-cases
*/
Expand Down
3 changes: 1 addition & 2 deletions src/renderer/components/AccountNotifications.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { act, fireEvent, render, screen } from '@testing-library/react';
import { mockGitHubCloudAccount, mockSettings } from '../__mocks__/state-mocks';
import { ensureStableEmojis, mockDirectoryPath } from '../__mocks__/utils';
import { ensureStableEmojis } from '../__mocks__/utils';
import { AppContext } from '../context/App';
import { GroupBy } from '../types';
import { mockGitHubNotifications } from '../utils/api/__mocks__/response-mocks';
Expand All @@ -14,7 +14,6 @@ jest.mock('./RepositoryNotifications', () => ({
describe('renderer/components/AccountNotifications.tsx', () => {
beforeEach(() => {
ensureStableEmojis();
mockDirectoryPath();
});

it('should render itself - group notifications by repositories', () => {
Expand Down
3 changes: 1 addition & 2 deletions src/renderer/components/AllRead.test.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { render } from '@testing-library/react';
import { ensureStableEmojis, mockDirectoryPath } from '../__mocks__/utils';
import { ensureStableEmojis } from '../__mocks__/utils';
import { AllRead } from './AllRead';

describe('renderer/components/AllRead.tsx', () => {
beforeEach(() => {
ensureStableEmojis();
mockDirectoryPath();
});

it('should render itself & its children', () => {
Expand Down
5 changes: 0 additions & 5 deletions src/renderer/components/EmojiText.test.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
import { render } from '@testing-library/react';
import { mockDirectoryPath } from '../__mocks__/utils';
import { EmojiText, type IEmojiText } from './EmojiText';

describe('renderer/components/Emoji.tsx', () => {
beforeEach(() => {
mockDirectoryPath();
});

it('should render', () => {
const props: IEmojiText = {
text: '🍺',
Expand Down
8 changes: 1 addition & 7 deletions src/renderer/components/EmojiText.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import path from 'node:path';
import twemoji from '@discordapp/twemoji';
import { type FC, useEffect, useRef } from 'react';
import { getDirectoryPath } from '../utils/helpers';

export interface IEmojiText {
text: string;
Expand All @@ -26,12 +25,7 @@ export const EmojiText: FC<IEmojiText> = ({ text }) => {
_options: TwemojiOptions,
_variant: string,
) => {
return path.join(
getDirectoryPath(),
'assets',
'twemoji',
`${icon}.svg`,
);
return path.join('assets', 'twemoji', `${icon}.svg`);
},
});
}
Expand Down
5 changes: 0 additions & 5 deletions src/renderer/components/Oops.test.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
import { render } from '@testing-library/react';
import { mockDirectoryPath } from '../__mocks__/utils';
import { Oops } from './Oops';

describe('renderer/components/Oops.tsx', () => {
beforeEach(() => {
mockDirectoryPath();
});

it('should render itself & its children', () => {
const mockError = {
title: 'Error title',
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/renderer/components/__snapshots__/AllRead.test.tsx.snap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/renderer/components/__snapshots__/EmojiText.test.tsx.snap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/renderer/components/__snapshots__/Oops.test.tsx.snap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions src/renderer/utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,3 @@ export function getFilterCount(settings: SettingsState): number {

return count;
}

export function getDirectoryPath(): string {
return `${__dirname}`;
}
5 changes: 4 additions & 1 deletion src/renderer/utils/notifications.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import path from 'node:path';
import log from 'electron-log';
import type {
AccountNotifications,
Expand Down Expand Up @@ -103,7 +104,9 @@ export const raiseNativeNotification = (notifications: Notification[]) => {
};

export const raiseSoundNotification = () => {
const audio = new Audio('assets/sounds/clearly.mp3');
const audio = new Audio(
path.resolve(__dirname, '..', 'assets', 'sounds', 'clearly.mp3'),
);
audio.volume = 0.2;
audio.play();
};
Expand Down

0 comments on commit 26448b2

Please sign in to comment.