Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@
"class-variance-authority": "0.7.0",
"clsx": "2.1.1",
"date-fns": "3.6.0",
"electron-log": "5.1.6",
"electron-updater": "6.3.0",
"final-form": "4.20.10",
"menubar": "9.5.0",
Expand Down
9 changes: 9 additions & 0 deletions pnpm-lock.yaml

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

4 changes: 2 additions & 2 deletions src/electron/first-run.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const { app, dialog } = require('electron');

const fs = require('node:fs');
const path = require('node:path');
const log = require('electron-log');

async function onFirstRunMaybe() {
if (isFirstRun()) {
Expand Down Expand Up @@ -49,7 +49,7 @@ function isFirstRun() {

fs.writeFileSync(configPath, '');
} catch (error) {
console.warn('First run: Unable to write firstRun file', error);
log.warn('First run: Unable to write firstRun file', error);
}

return true;
Expand Down
4 changes: 4 additions & 0 deletions src/electron/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ const { menubar } = require('menubar');
const { autoUpdater } = require('electron-updater');
const { onFirstRunMaybe } = require('./first-run');
const path = require('node:path');
const log = require('electron-log');

log.initialize();
autoUpdater.logger = log;

// TODO: Remove @electron/remote use - see #650
require('@electron/remote/main').initialize();
Expand Down
5 changes: 3 additions & 2 deletions src/utils/api/client.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import axios, { type AxiosPromise, type AxiosResponse } from 'axios';
import log from 'electron-log';
import {
mockGitHubCloudAccount,
mockGitHubEnterpriseServerAccount,
Expand Down Expand Up @@ -278,7 +279,7 @@ describe('utils/api/client.ts', () => {
});

it('should handle error', async () => {
const consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation();
const logErrorSpy = jest.spyOn(log, 'error').mockImplementation();

const apiRequestAuthMock = jest.spyOn(apiRequests, 'apiRequestAuth');

Expand All @@ -291,7 +292,7 @@ describe('utils/api/client.ts', () => {
'123' as Token,
);

expect(consoleErrorSpy).toHaveBeenCalledWith('Failed to get html url');
expect(logErrorSpy).toHaveBeenCalledWith('Failed to get html url');
});
});
});
3 changes: 2 additions & 1 deletion src/utils/api/client.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { AxiosPromise } from 'axios';
import log from 'electron-log';
import { print } from 'graphql/language/printer';
import type {
Account,
Expand Down Expand Up @@ -224,7 +225,7 @@ export async function getHtmlUrl(url: Link, token: Token): Promise<string> {
const response = (await apiRequestAuth(url, 'GET', token)).data;
return response.html_url;
} catch (err) {
console.error('Failed to get html url');
log.error('Failed to get html url');
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/utils/auth/migration.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import axios from 'axios';
import log from 'electron-log';
import nock from 'nock';
import { mockGitifyUser, mockToken } from '../../__mocks__/state-mocks';
import type { AuthState, Hostname } from '../../types';
Expand All @@ -20,6 +21,7 @@ describe('utils/auth/migration.ts', () => {

describe('migrateAuthenticatedAccounts', () => {
it('migrate and save legacy accounts', async () => {
const logInfoSpy = jest.spyOn(log, 'info').mockImplementation();
jest.spyOn(localStorage.__proto__, 'getItem').mockReturnValueOnce(
JSON.stringify({
auth: {
Expand All @@ -36,7 +38,7 @@ describe('utils/auth/migration.ts', () => {
await migrateAuthenticatedAccounts();

expect(localStorage.setItem).toHaveBeenCalledTimes(1);
expect(console.log).toHaveBeenCalledTimes(2);
expect(logInfoSpy).toHaveBeenCalledTimes(2);
});
});

Expand Down
27 changes: 13 additions & 14 deletions src/utils/auth/migration.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
import log from 'electron-log';
import type { Account, AuthState } from '../../types';
import Constants from '../constants';
import { loadState, saveState } from '../storage';
import { getUserData } from './utils';

export function logMigrationProgress(msg: string) {
// biome-ignore lint/suspicious/noConsoleLog: log migration progress
console.log(`Account Migration: ${msg}`);
}

/**
* Migrate authenticated accounts from old data structure to new data structure (v5.7.0+).
*
Expand All @@ -16,17 +12,20 @@ export function logMigrationProgress(msg: string) {
export async function migrateAuthenticatedAccounts() {
const existing = loadState();

if (hasAccountsToMigrate(existing.auth)) {
logMigrationProgress('Commencing authenticated accounts migration');
if (!hasAccountsToMigrate(existing.auth)) {
log.info('Account Migration: No accounts need migrating');
return;
}

log.info('Account Migration: Commencing authenticated accounts migration');

const migratedAccounts = await convertAccounts(existing.auth);
const migratedAccounts = await convertAccounts(existing.auth);

saveState({
auth: { ...existing.auth, accounts: migratedAccounts },
settings: existing.settings,
});
logMigrationProgress('Authenticated accounts migration complete');
}
saveState({
auth: { ...existing.auth, accounts: migratedAccounts },
settings: existing.settings,
});
log.info('Account Migration: Authenticated accounts migration complete');
}

export function hasAccountsToMigrate(existingAuthState: AuthState): boolean {
Expand Down
7 changes: 3 additions & 4 deletions src/utils/subject.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const mockDiscussionAuthor: DiscussionAuthor = {
avatar_url: 'https://avatars.githubusercontent.com/u/123456789?v=4' as Link,
type: 'User',
};
import log from 'electron-log';

describe('utils/subject.ts', () => {
beforeEach(() => {
Expand Down Expand Up @@ -1150,9 +1151,7 @@ describe('utils/subject.ts', () => {

describe('Error', () => {
it('catches error and logs message', async () => {
const consoleErrorSpy = jest
.spyOn(console, 'error')
.mockImplementation();
const logErrorSpy = jest.spyOn(log, 'error').mockImplementation();

const mockError = new Error('Test error');
const mockNotification = partialMockNotification({
Expand All @@ -1167,7 +1166,7 @@ describe('utils/subject.ts', () => {

await getGitifySubjectDetails(mockNotification);

expect(consoleErrorSpy).toHaveBeenCalledWith(
expect(logErrorSpy).toHaveBeenCalledWith(
'Error occurred while fetching details for Issue notification: This issue will throw an error',
mockError,
);
Expand Down
3 changes: 2 additions & 1 deletion src/utils/subject.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import log from 'electron-log';
import type { Link } from '../types';
import type {
CheckSuiteAttributes,
Expand Down Expand Up @@ -48,7 +49,7 @@ export async function getGitifySubjectDetails(
return null;
}
} catch (err) {
console.error(
log.error(
`Error occurred while fetching details for ${notification.subject.type} notification: ${notification.subject.title}`,
err,
);
Expand Down