Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lint fixes from recent dependency bumps #2156

Merged
merged 1 commit into from
Apr 2, 2024
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
2 changes: 1 addition & 1 deletion css/dark-mode.css
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ html.dark-mode ._9xq0 {
/* Removing top gap */
/* TODO: Remove when fixed by fb */
.__fb-dark-mode {
--header-height: 0px !important;
--header-height: 0 !important;
}

/* Message list: fix for received messages text color in dark mode */
Expand Down
12 changes: 1 addition & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,12 @@
],
"rules": {
"@typescript-eslint/ban-ts-comment": "off",
"@typescript-eslint/consistent-type-definitions": "off",
"@typescript-eslint/consistent-type-imports": "off",
"@typescript-eslint/naming-convention": "off",
"@typescript-eslint/no-floating-promises": "off",
"@typescript-eslint/no-loop-func": "off",
"@typescript-eslint/no-non-null-assertion": "off",
"@typescript-eslint/no-require-imports": "off",
"@typescript-eslint/no-unnecessary-type-assertion": "off",
"@typescript-eslint/no-unsafe-argument": "off",
"@typescript-eslint/no-unsafe-assignment": "off",
"@typescript-eslint/no-unsafe-call": "off",
Expand All @@ -81,23 +79,15 @@
"import/no-anonymous-default-export": "off",
"import/no-cycle": "off",
"n/file-extension-in-import": "off",
"no-warning-comments": "off",
"object-curly-newline": "off",
"unicorn/no-typeof-undefined": "off",
"unicorn/prefer-at": "off",
"unicorn/prefer-module": "off",
"unicorn/prefer-string-replace-all": "off",
"unicorn/prefer-top-level-await": "off",
"unicorn/prevent-abbreviations": "off",
"unicorn/switch-case-braces": "off"
"unicorn/prefer-top-level-await": "off"
}
},
"stylelint": {
"extends": "stylelint-config-xo",
"rules": {
"comment-word-disallowed-list": null,
"declaration-no-important": null,
"length-zero-no-unit": null,
"no-descending-specificity": null,
"no-duplicate-selectors": null,
"rule-empty-line-before": null,
Expand Down
4 changes: 2 additions & 2 deletions source/autoplay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ function disableVideoAutoplay(videos: NodeListOf<HTMLVideoElement>): void {
} = firstParent;

const style = parentWithBackground.style || window.getComputedStyle(parentWithBackground);
const backgroundImageSrc = style.backgroundImage.slice(4, -1).replace(/"/g, '');
const backgroundImageSource = style.backgroundImage.slice(4, -1).replaceAll(/"/, '');

// Create the image to replace the video as a placeholder
const image = document.createElement('img');
image.setAttribute('src', backgroundImageSrc);
image.setAttribute('src', backgroundImageSource);
image.classList.add('disabledAutoPlayImgTopRadius');

// If it's a video without a source title bar at the bottom,
Expand Down
42 changes: 26 additions & 16 deletions source/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ async function isNewSidebar(): Promise<boolean> {

async function withSettingsMenu(callback: () => Promise<void> | void): Promise<void> {
// Wait for navigation pane buttons to show up
const settingsMenu = await elementReady(selectors.userMenuNewSidebar, {stopOnDomReady: false})!;
const settingsMenu = await elementReady(selectors.userMenuNewSidebar, {stopOnDomReady: false});

await withMenu(settingsMenu as HTMLElement, callback);
}
Expand Down Expand Up @@ -260,7 +260,7 @@ async function toggleSounds({checked}: IToggleSounds): Promise<void> {
const shouldClosePreferences = await openHiddenPreferences();

const soundsCheckbox = document.querySelector<HTMLInputElement>(`${selectors.preferencesSelector} ${selectors.messengerSoundsSelector}`)!;
if (typeof checked === 'undefined' || checked !== soundsCheckbox.checked) {
if (checked === undefined || checked !== soundsCheckbox.checked) {
soundsCheckbox.click();
}

Expand Down Expand Up @@ -412,12 +412,16 @@ async function updateVibrancy(): Promise<void> {
const vibrancy = await ipc.callMain<undefined, 'sidebar' | 'none' | 'full'>('get-config-vibrancy');

switch (vibrancy) {
case 'sidebar':
case 'sidebar': {
classList.add('sidebar-vibrancy');
break;
case 'full':
}

case 'full': {
classList.add('full-vibrancy');
break;
}

default:
}

Expand All @@ -432,15 +436,21 @@ async function updateSidebar(): Promise<void> {
const sidebar = await ipc.callMain<undefined, 'default' | 'hidden' | 'narrow' | 'wide'>('get-config-sidebar');

switch (sidebar) {
case 'hidden':
case 'hidden': {
classList.add('sidebar-hidden');
break;
case 'narrow':
}

case 'narrow': {
classList.add('sidebar-force-narrow');
break;
case 'wide':
}

case 'wide': {
classList.add('sidebar-force-wide');
break;
}

default:
}
}
Expand All @@ -460,15 +470,15 @@ function renderOverlayIcon(messageCount: number): HTMLCanvasElement {
canvas.width = 128;
canvas.style.letterSpacing = '-5px';

const ctx = canvas.getContext('2d')!;
ctx.fillStyle = '#f42020';
ctx.beginPath();
ctx.ellipse(64, 64, 64, 64, 0, 0, 2 * Math.PI);
ctx.fill();
ctx.textAlign = 'center';
ctx.fillStyle = 'white';
ctx.font = '90px sans-serif';
ctx.fillText(String(Math.min(99, messageCount)), 64, 96);
const context = canvas.getContext('2d')!;
context.fillStyle = '#f42020';
context.beginPath();
context.ellipse(64, 64, 64, 64, 0, 0, 2 * Math.PI);
context.fill();
context.textAlign = 'center';
context.fillStyle = 'white';
context.font = '90px sans-serif';
context.fillText(String(Math.min(99, messageCount)), 64, 96);

return canvas;
}
Expand Down
44 changes: 22 additions & 22 deletions source/browser/conversation-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ function drawIcon(size: number, img?: HTMLImageElement): HTMLCanvasElement {
canvas.width = size + padding.left + padding.right;
canvas.height = size + padding.top + padding.bottom;

const ctx = canvas.getContext('2d')!;
ctx.beginPath();
ctx.arc((size / 2) + padding.left, (size / 2) + padding.top, (size / 2), 0, Math.PI * 2, true);
ctx.closePath();
ctx.clip();
const context = canvas.getContext('2d')!;
context.beginPath();
context.arc((size / 2) + padding.left, (size / 2) + padding.top, (size / 2), 0, Math.PI * 2, true);
context.closePath();
context.clip();

ctx.drawImage(img, padding.left, padding.top, size, size);
context.drawImage(img, padding.left, padding.top, size, size);
} else {
canvas.width = 0;
canvas.height = 0;
Expand Down Expand Up @@ -63,13 +63,13 @@ async function createIcons(element: HTMLElement, url: string): Promise<void> {
element.setAttribute(icon.read, canvas.toDataURL());

const markerSize = 8;
const ctx = canvas.getContext('2d')!;
const context = canvas.getContext('2d')!;

ctx.fillStyle = '#f42020';
ctx.beginPath();
ctx.ellipse(canvas.width - markerSize, markerSize, markerSize, markerSize, 0, 0, 2 * Math.PI);
ctx.closePath();
ctx.fill();
context.fillStyle = '#f42020';
context.beginPath();
context.ellipse(canvas.width - markerSize, markerSize, markerSize, markerSize, 0, 0, 2 * Math.PI);
context.closePath();
context.fill();

element.setAttribute(icon.unread, canvas.toDataURL());
}
Expand Down Expand Up @@ -111,8 +111,8 @@ async function getLabel(element: HTMLElement): Promise<string> {

const emojis: HTMLElement[] = [];
if (element !== null) {
for (const element_curr of element.children) {
emojis.push(element_curr as HTMLElement);
for (const elementCurrent of element.children) {
emojis.push(elementCurrent as HTMLElement);
}
}

Expand Down Expand Up @@ -169,7 +169,7 @@ export async function sendConversationList(): Promise<void> {
ipc.callMain('conversations', conversationsToRender);
}

function genStringFromNode(element: Element): string | undefined {
function generateStringFromNode(element: Element): string | undefined {
const cloneElement = element.cloneNode(true) as Element;
let emojiString;

Expand Down Expand Up @@ -217,9 +217,9 @@ function countUnread(mutationsList: MutationRecord[]): void {

// Check latest mutation first
for (const mutation of unreadMutations.reverse()) {
const curr = (mutation.target.parentElement as Element).closest(selectors.conversationSidebarSelector)!;
const current = (mutation.target.parentElement as Element).closest(selectors.conversationSidebarSelector)!;

const href = curr.closest('[role="link"]')?.getAttribute('href');
const href = current.closest('[role="link"]')?.getAttribute('href');

if (!href) {
continue;
Expand All @@ -228,21 +228,21 @@ function countUnread(mutationsList: MutationRecord[]): void {
// It is possible to have multiple mutations for the same conversation, but we only want one notification.
// So if the current conversation has already been checked, continue.
// Additionally if the conversation is not unread, then also continue.
if (alreadyChecked.includes(href) || !curr.querySelector('.' + selectors.conversationSidebarUnreadDot.replace(/ /g, '.'))) {
if (alreadyChecked.includes(href) || !current.querySelector('.' + selectors.conversationSidebarUnreadDot.replaceAll(/ /, '.'))) {
continue;
}

alreadyChecked.push(href);

// Get the image data URI from the parent of the author/text
const imgUrl = curr.querySelector('img')?.dataset.caprineIcon;
const textOptions = curr.querySelectorAll(selectors.conversationSidebarTextSelector);
const imgUrl = current.querySelector('img')?.dataset.caprineIcon;
const textOptions = current.querySelectorAll(selectors.conversationSidebarTextSelector);
// Get the author and text of the new message
const titleTextNode = textOptions[0];
const bodyTextNode = textOptions[1];

const titleText = genStringFromNode(titleTextNode);
const bodyText = genStringFromNode(bodyTextNode);
const titleText = generateStringFromNode(titleTextNode);
const bodyText = generateStringFromNode(bodyTextNode);

if (!bodyText || !titleText || !imgUrl) {
continue;
Expand Down
6 changes: 3 additions & 3 deletions source/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,18 +250,18 @@ function updateThemeSetting(store: Store<StoreType>): void {

if (is.macos && followSystemAppearance) {
store.set('theme', 'system');
} else if (typeof darkMode !== 'undefined') {
} else if (darkMode !== undefined) {
store.set('theme', darkMode ? 'dark' : 'light');
} else if (!store.has('theme')) {
store.set('theme', 'system');
}

if (typeof darkMode !== 'undefined') {
if (darkMode !== undefined) {
// @ts-expect-error
store.delete('darkMode');
}

if (typeof followSystemAppearance !== 'undefined') {
if (followSystemAppearance !== undefined) {
// @ts-expect-error
store.delete('followSystemAppearance');
}
Expand Down
4 changes: 2 additions & 2 deletions source/conversation.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
interface Conversation {
type Conversation = {
label: string;
selected: boolean;
unread: boolean;
icon: string;
}
};
11 changes: 8 additions & 3 deletions source/emoji.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,12 +219,17 @@ enum EmojiStyleCode {

function codeForEmojiStyle(style: EmojiStyle): EmojiStyleCode {
switch (style) {
case 'facebook-2-2':
case 'facebook-2-2': {
return EmojiStyleCode.Facebook22;
case 'messenger-1-0':
}

case 'messenger-1-0': {
return EmojiStyleCode.Messenger10;
default:
}

default: {
return EmojiStyleCode.Facebook30;
}
}
}

Expand Down
32 changes: 20 additions & 12 deletions source/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,12 @@ import doNotDisturb from '@sindresorhus/do-not-disturb';
import updateAppMenu from './menu';
import config, {StoreType} from './config';
import tray from './tray';
import {sendAction, sendBackgroundAction, messengerDomain, stripTrackingFromUrl} from './util';
import {
sendAction,
sendBackgroundAction,
messengerDomain,
stripTrackingFromUrl,
} from './util';
import {process as processEmojiUrl} from './emoji';
import ensureOnline from './ensure-online';
import {setUpMenuBarMode} from './menu-bar-mode';
Expand Down Expand Up @@ -143,12 +148,12 @@ function updateOverlayIcon({data, text}: {data: string; text: string}): void {
mainWindow.setOverlayIcon(img, text);
}

interface BeforeSendHeadersResponse {
type BeforeSendHeadersResponse = {
cancel?: boolean;
requestHeaders?: Record<string, string>;
}
};

interface OnSendHeadersDetails {
type OnSendHeadersDetails = {
id: number;
url: string;
method: string;
Expand All @@ -157,7 +162,7 @@ interface OnSendHeadersDetails {
referrer: string;
timestamp: number;
requestHeaders: Record<string, string>;
}
};

function enableHiresResources(): void {
const scaleFactor = Math.max(
Expand Down Expand Up @@ -500,14 +505,17 @@ function createMainWindow(): BrowserWindow {
if (details.url === 'about:blank' || details.url === 'about:blank#blocked') {
if (details.frameName !== 'about:blank') {
// Voice/video call popup
return {action: 'allow', overrideBrowserWindowOptions: {
show: true,
titleBarStyle: 'default',
webPreferences: {
nodeIntegration: false,
preload: path.join(__dirname, 'browser-call.js'),
return {
action: 'allow',
overrideBrowserWindowOptions: {
show: true,
titleBarStyle: 'default',
webPreferences: {
nodeIntegration: false,
preload: path.join(__dirname, 'browser-call.js'),
},
},
}};
};
}
} else {
const url = stripTrackingFromUrl(details.url);
Expand Down
7 changes: 6 additions & 1 deletion source/menu-bar-mode.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import {app, globalShortcut, BrowserWindow, Menu} from 'electron';
import {
app,
globalShortcut,
BrowserWindow,
Menu,
} from 'electron';
import {is} from 'electron-util';
import config from './config';
import tray from './tray';
Expand Down
Loading