diff --git a/.eslintrc.json b/.eslintrc.json index ebf859c..c9f8cf4 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -3,81 +3,106 @@ "es2020": true, "node": true }, - - "extends": [ - "airbnb-base", - "prettier", - "prettier/@typescript-eslint" - ], - + "extends": ["airbnb-base", "prettier", "prettier/@typescript-eslint"], "globals": { "__BUILDNUM__": "readonly" }, - "parser": "@typescript-eslint/parser", - "parserOptions": { "ecmaVersion": 12, "sourceType": "module", "project": "tsconfig.json" }, - - "plugins": [ - "@typescript-eslint" - ], - + "plugins": ["@typescript-eslint"], "rules": { "@typescript-eslint/no-floating-promises": ["warn"], "@typescript-eslint/no-shadow": ["error"], + "@typescript-eslint/no-unused-expressions": ["error"], "@typescript-eslint/no-unused-vars": ["error"], - "curly": ["error", "all"], - "import/extensions": "off", + "arrow-parens": ["error", "always"], + "comma-dangle": [ + "error", + { + "arrays": "always-multiline", + "objects": "always-multiline", + "imports": "always-multiline", + "exports": "always-multiline", + "functions": "never" + } + ], + "import/extensions": [ + "error", + "ignorePackages", + { + "ts": "never" + } + ], "import/prefer-default-export": "off", "no-bitwise": "off", - "no-console": "off", "no-empty": "off", "no-fallthrough": "off", "no-multiple-empty-lines": "error", "no-restricted-syntax": "off", "no-shadow": "off", // Prevent conflicts with @typescript-eslint/no-shadow "no-underscore-dangle": "off", - "no-void": ["error", { "allowAsStatement": true }], - "padding-line-between-statements": [ // See docs + "no-unused-expressions": "off", // @typescript-eslint/no-unused-expressions used instead + "no-void": [ + "error", + { + "allowAsStatement": true + } + ], + "padding-line-between-statements": [ + // See docs "warn", - { "blankLine": "always", "prev": "*", "next": "return" }, // return - - { "blankLine": "always", "prev": "*", "next": "class" }, // class - - { "blankLine": "always", "prev": ["const", "let", "var"], "next": "*" }, // Variable declaration - { "blankLine": "any", "prev": ["const", "let", "var"], "next": ["const", "let", "var"] }, - - { "blankLine": "always", "prev": ["case", "default"], "next": "*" }, // case in switch - - { "blankLine": "always", "prev": "*", "next": ["try", "switch", "for", "block-like"] }, // blocks (try, switch, if, while, for, {}) - { "blankLine": "always", "prev": ["try", "switch", "for", "block-like"], "next": "*" }, - - { // Multiline + { + "blankLine": "always", + "prev": "*", + "next": "return" + }, // return + { + "blankLine": "always", + "prev": "*", + "next": "class" + }, // class + { + "blankLine": "always", + "prev": ["const", "let", "var"], + "next": "*" + }, // Variable declaration + { + "blankLine": "any", + "prev": ["const", "let", "var"], + "next": ["const", "let", "var"] + }, + { + "blankLine": "always", + "prev": ["case", "default"], + "next": "*" + }, // case in switch + { + "blankLine": "always", + "prev": "*", + "next": ["try", "switch", "for", "block-like"] + }, // blocks (try, switch, if, while, for, {}) + { + "blankLine": "always", + "prev": ["try", "switch", "for", "block-like"], + "next": "*" + }, + { + // Multiline "blankLine": "always", "prev": ["multiline-const", "multiline-expression", "multiline-let"], "next": "*" } ] }, - "settings": { "import/resolver": { "node": { - "paths": [ - "src", - "worker", - "node_modules" - ], - - "extensions": [ - ".js", - ".json", - ".ts" - ] + "paths": ["src", "worker", "node_modules"], + "extensions": [".js", ".json", ".ts"] } } } diff --git a/.prettierrc.json b/.prettierrc.json index 036c879..e24a3fd 100644 --- a/.prettierrc.json +++ b/.prettierrc.json @@ -1,7 +1,7 @@ { "singleQuote": true, - "trailingComma": "all", + "trailingComma": "es5", "endOfLine": "lf", "printWidth": 100, - "arrowParens": "avoid" + "arrowParens": "always" } diff --git a/.vscode/settings.json b/.vscode/settings.json index 08ca525..d3d130f 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,4 +1,7 @@ { "editor.tabSize": 2, - "editor.defaultFormatter": "esbenp.prettier-vscode" + "editor.defaultFormatter": "esbenp.prettier-vscode", + "[jsonc]": { + "editor.defaultFormatter": "esbenp.prettier-vscode" + } } \ No newline at end of file diff --git a/package.json b/package.json index 30451d5..08453ec 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,8 @@ "start:debug": "qode --max-old-space-size=128 --inspect=0.0.0.0:9229 ./dist/index.js", "start:watch": "nodemon -e js,ts,css,scss --ignore dist/ --ignore node_modules/ --exec npm run start:debug", "lint": "eslint src/**/*.ts worker/**/*.ts", - "lint:fix": "npm run lint -- --fix && npm run prettier", + "lint:ts": "tsc -p .", + "lint:fix": "eslint --fix 'src/**/*.ts' 'worker/**/*.ts' && npm run prettier", "prettier": "prettier --write --loglevel warn src/**/*.ts worker/**/*.ts src/**/*.scss", "postinstall": "node ./downloadNodeGui.js && webpack -p", "package": "nodegui-packer --pack ./dist", diff --git a/src/Tray.ts b/src/Tray.ts index b8f0526..590406c 100644 --- a/src/Tray.ts +++ b/src/Tray.ts @@ -1,6 +1,6 @@ import { QAction, QMenu, QSystemTrayIcon, QSystemTrayIconActivationReason } from '@nodegui/nodegui'; import { Constants } from 'discord.js'; -import { __ } from 'i18n'; +import { __ } from './utilities/StringProvider'; import { app } from '.'; import { Events as AppEvents } from './utilities/Events'; diff --git a/src/components/DLabel/DLabel.ts b/src/components/DLabel/DLabel.ts index ca43a6e..ea446d6 100644 --- a/src/components/DLabel/DLabel.ts +++ b/src/components/DLabel/DLabel.ts @@ -1,9 +1,9 @@ import { CursorShape, QLabel, QPoint, TextInteractionFlag } from '@nodegui/nodegui'; import { DMChannel, Guild, GuildChannel, TextChannel } from 'discord.js'; -import { __ } from 'i18n'; import open from 'open'; import { basename, extname } from 'path'; import { URL } from 'url'; +import { __ } from '../../utilities/StringProvider'; import { app } from '../..'; import { Events } from '../../utilities/Events'; import { MarkdownStyles } from '../../utilities/MarkdownStyles'; @@ -35,7 +35,7 @@ export class DLabel extends QLabel { Events.OPEN_USER_PROFILE, url.hostname, app.currentGuildId, - this.mapToGlobal(this.p0), + this.mapToGlobal(this.p0) ); break; @@ -105,7 +105,7 @@ export class DLabel extends QLabel { ? `${__('EMOJI_POPOUT_JOINED_GUILD_EMOJI_DESCRIPTION')} ${serverName}` : __('EMOJI_POPOUT_PREMIUM_UNJOINED_PRIVATE_GUILD_DESCRIPTION') } - `, + ` ); } } diff --git a/src/components/DMPanel/DMTitleBar.ts b/src/components/DMPanel/DMTitleBar.ts index 5997684..f7ef241 100644 --- a/src/components/DMPanel/DMTitleBar.ts +++ b/src/components/DMPanel/DMTitleBar.ts @@ -1,4 +1,4 @@ -import { __ } from 'i18n'; +import { __ } from '../../utilities/StringProvider'; import { DLineEdit } from '../DLineEdit/DLineEdit'; import { DTitleBar } from '../DTitleBar/DTitleBar'; import { DMUsersList } from './DMUsersList'; diff --git a/src/components/EmojiPicker/EmojiPicker.ts b/src/components/EmojiPicker/EmojiPicker.ts index 6c14116..d45ca8f 100644 --- a/src/components/EmojiPicker/EmojiPicker.ts +++ b/src/components/EmojiPicker/EmojiPicker.ts @@ -29,7 +29,7 @@ import { import { NativeRawPointer } from '@nodegui/nodegui/dist/lib/core/Component'; import { Emoji } from 'discord.js'; import { EventEmitter } from 'events'; -import { __ } from 'i18n'; +import { __ } from '../../utilities/StringProvider'; import { app } from '../..'; import { CancelToken } from '../../utilities/CancelToken'; import { createLogger } from '../../utilities/Console'; @@ -293,8 +293,8 @@ export class EmojiPicker extends QMenu { emojiView.clear(); emojiView.setCurrentRow(0); - if (emojiName === __('SEARCH_FOR_EMOJI') && config.recentEmojis) { - const recents = config.recentEmojis.sort((a, b) => a[1] - b[1]); + if (emojiName === __('SEARCH_FOR_EMOJI') && config.get('recentEmojis')) { + const recents = config.get('recentEmojis').sort((a, b) => a[1] - b[1]); for (const item of recents) { const emoji = client.emojis.resolve(item[0]); @@ -309,7 +309,7 @@ export class EmojiPicker extends QMenu { const result = client.emojis.cache .filter((emoji) => - emoji.name.toLowerCase().includes(emojiName.replace(/ /g, '').toLowerCase()), + emoji.name.toLowerCase().includes(emojiName.replace(/ /g, '').toLowerCase()) ) .partition((v) => v.guild.id === app.currentGuildId); @@ -332,7 +332,7 @@ export class EmojiPicker extends QMenu { this.insertEmoji( i < thisGuild.length ? thisGuild[i] : otherGuilds[i - thisGuild.length], - this.token, + this.token ); } diff --git a/src/components/GuildPanel/ChannelMembers.ts b/src/components/GuildPanel/ChannelMembers.ts index 2bc127c..7c7700e 100644 --- a/src/components/GuildPanel/ChannelMembers.ts +++ b/src/components/GuildPanel/ChannelMembers.ts @@ -57,7 +57,7 @@ export class ChannelMembers extends QListWidget { ubtn.setStyleSheet( speaking.bitfield === 1 ? '#Avatar { border: 2px solid #43b581; padding: 3px; border-radius: 12px; }' - : '', + : '' ); } }); diff --git a/src/components/GuildPanel/ChannelsList.ts b/src/components/GuildPanel/ChannelsList.ts index dcd1a1f..aff8651 100644 --- a/src/components/GuildPanel/ChannelsList.ts +++ b/src/components/GuildPanel/ChannelsList.ts @@ -203,7 +203,7 @@ export class ChannelsList extends QListWidget { .filter((c) => c.can(Permissions.FLAGS.VIEW_CHANNEL)) .partition((a) => a.type === 'category') as [ Collection, - Collection, + Collection ]; debug(`Loading ${categories.size} categories...`); @@ -219,7 +219,7 @@ export class ChannelsList extends QListWidget { label.adjustSize(); label.addEventListener( WidgetEventTypes.MouseButtonPress, - this.toggleCategory.bind(this, guild.id, category.id), + this.toggleCategory.bind(this, guild.id, category.id) ); const item = new QListWidgetItem(); diff --git a/src/components/GuildPanel/GuildActionsMenu.ts b/src/components/GuildPanel/GuildActionsMenu.ts index de99a4e..c302004 100644 --- a/src/components/GuildPanel/GuildActionsMenu.ts +++ b/src/components/GuildPanel/GuildActionsMenu.ts @@ -1,8 +1,9 @@ import { QAction, QMenu, QPoint, WidgetAttribute, WidgetEventTypes } from '@nodegui/nodegui'; import { Guild } from 'discord.js'; -import { __ } from 'i18n'; import { app } from '../..'; import { Events } from '../../utilities/Events'; +import { PhraseID } from '../../utilities/PhraseID'; +import { __ } from '../../utilities/StringProvider'; import { ViewOptions } from '../../views/ViewOptions'; export class GuildActionsMenu extends QMenu { @@ -35,7 +36,7 @@ export class GuildActionsMenu extends QMenu { this.addEventListener(WidgetEventTypes.Hide, () => this.updateComponents()); } - private addComponent(textId: string, callback: () => Promise) { + private addComponent(textId: PhraseID, callback: () => Promise) { const item = new QAction(); item.setText(__(textId)); @@ -115,7 +116,7 @@ export class GuildActionsMenu extends QMenu { .get('CHANGE_NICKNAME') ?.setProperty( 'visible', - member.hasPermission('CHANGE_NICKNAME') || member.hasPermission('MANAGE_NICKNAMES'), + member.hasPermission('CHANGE_NICKNAME') || member.hasPermission('MANAGE_NICKNAMES') ); } diff --git a/src/components/GuildPanel/GuildPanel.ts b/src/components/GuildPanel/GuildPanel.ts index fd92af9..960b29c 100644 --- a/src/components/GuildPanel/GuildPanel.ts +++ b/src/components/GuildPanel/GuildPanel.ts @@ -37,7 +37,7 @@ export class GuildPanel extends QWidget { 24, 24, 1, - 1, + 1 ); private guildow = new QLabel(this); @@ -95,7 +95,7 @@ export class GuildPanel extends QWidget { if (event?.button() === MouseButton.LeftButton) { actionsMenu.popup(this.channelsList.mapToGlobal(new QPoint(0, 0))); } - }, + } ); controls.setSpacing(0); diff --git a/src/components/GuildsList/GuildButton.ts b/src/components/GuildsList/GuildButton.ts index 64658cb..455725f 100644 --- a/src/components/GuildsList/GuildButton.ts +++ b/src/components/GuildsList/GuildButton.ts @@ -7,7 +7,7 @@ import { WidgetEventTypes, } from '@nodegui/nodegui'; import { Guild } from 'discord.js'; -import { __ } from 'i18n'; +import { __ } from '../../utilities/StringProvider'; import { app } from '../..'; import { Events } from '../../utilities/Events'; import { pictureWorker } from '../../utilities/PictureWorker'; diff --git a/src/components/GuildsList/GuildsList.ts b/src/components/GuildsList/GuildsList.ts index 9ae33d1..ba6ec2a 100644 --- a/src/components/GuildsList/GuildsList.ts +++ b/src/components/GuildsList/GuildsList.ts @@ -14,10 +14,10 @@ import { WidgetEventTypes, } from '@nodegui/nodegui'; import { Client, Constants, DQConstants, Guild } from 'discord.js'; -import { __ } from 'i18n'; import path from 'path'; import { app, MAX_QSIZE } from '../..'; import { Events as AppEvents } from '../../utilities/Events'; +import { __ } from '../../utilities/StringProvider'; import { ViewOptions } from '../../views/ViewOptions'; import { GuildButton } from './GuildButton'; diff --git a/src/components/InputPanel/AttachmentsPanel.ts b/src/components/InputPanel/AttachmentsPanel.ts index a474d44..94b19b3 100644 --- a/src/components/InputPanel/AttachmentsPanel.ts +++ b/src/components/InputPanel/AttachmentsPanel.ts @@ -9,12 +9,12 @@ import { QWidget, WidgetEventTypes, } from '@nodegui/nodegui'; -import { __ } from 'i18n'; import { basename, extname, join } from 'path'; import { pathToFileURL } from 'url'; import { PIXMAP_EXTS } from '../..'; import { createLogger } from '../../utilities/Console'; import { pictureWorker } from '../../utilities/PictureWorker'; +import { __ } from '../../utilities/StringProvider'; const { error } = createLogger('AttachmentsPanel'); diff --git a/src/components/InputPanel/InputPanel.ts b/src/components/InputPanel/InputPanel.ts index 7ef99fe..a63c77e 100644 --- a/src/components/InputPanel/InputPanel.ts +++ b/src/components/InputPanel/InputPanel.ts @@ -28,15 +28,16 @@ import { Permissions, TextChannel, } from 'discord.js'; -import { __ } from 'i18n'; import { join } from 'path'; import { fileURLToPath, URL } from 'url'; import { app, MAX_QSIZE } from '../..'; +import { createLogger } from '../../utilities/Console'; import { Events as AppEvents } from '../../utilities/Events'; import { paths } from '../../utilities/Paths'; -import { createLogger } from '../../utilities/Console'; +import { PhraseID } from '../../utilities/PhraseID'; import { pictureWorker } from '../../utilities/PictureWorker'; import { getEmojiURL } from '../../utilities/ResolveEmoji'; +import { __ } from '../../utilities/StringProvider'; import { ViewOptions } from '../../views/ViewOptions'; import { DIconButton } from '../DIconButton/DIconButton'; import { EmojiPicker } from '../EmojiPicker/EmojiPicker'; @@ -129,7 +130,7 @@ export class InputPanel extends QWidget { channel.type === 'dm' ? `@${(channel).recipient.username}` : `#${(channel).name}`, - }), + }) ); input.setFocus(FocusReason.TabFocusReason); @@ -159,7 +160,7 @@ export class InputPanel extends QWidget { } this.prevTypers = typers; - let i18nString; + let i18nString: PhraseID; switch (typers.length) { case 0: @@ -190,7 +191,7 @@ export class InputPanel extends QWidget { const { input } = this; input.insertPlainText( - `> ${message.cleanContent.replace(/\n/g, '\n> ')}\n${message.author.toString()}`, + `> ${message.cleanContent.replace(/\n/g, '\n> ')}\n${message.author.toString()}` ); input.setFocus(FocusReason.TabFocusReason); @@ -245,7 +246,7 @@ export class InputPanel extends QWidget { emoji_id: emoji.id || undefined, emoji_name: emoji.name, }, - emoji.animated ? 'gif' : 'png', + emoji.animated ? 'gif' : 'png' ); url += '?size=128'; diff --git a/src/components/MainTitleBar/MainTitleBar.ts b/src/components/MainTitleBar/MainTitleBar.ts index ebccb41..03109d7 100644 --- a/src/components/MainTitleBar/MainTitleBar.ts +++ b/src/components/MainTitleBar/MainTitleBar.ts @@ -1,12 +1,12 @@ import { QLabel, QPixmap, QSize, QWidget, WidgetEventTypes } from '@nodegui/nodegui'; import { Client, Constants, DMChannel, GuildChannel, NewsChannel, TextChannel } from 'discord.js'; -import { __ } from 'i18n'; import open from 'open'; import path from 'path'; import { app } from '../..'; import { ConfigManager } from '../../utilities/ConfigManager'; import { Events as AppEvents } from '../../utilities/Events'; import { PresenceStatusColor } from '../../utilities/PresenceStatusColor'; +import { __ } from '../../utilities/StringProvider'; import { ViewOptions } from '../../views/ViewOptions'; import { DIconButton } from '../DIconButton/DIconButton'; import { DLineEdit } from '../DLineEdit/DLineEdit'; @@ -34,7 +34,7 @@ export class MainTitleBar extends DTitleBar { iconQSize: new QSize(24, 24), tooltipText: '', isCheckbox: true, - checked: true + checked: true, }); private pinBtn = new DIconButton({ @@ -95,7 +95,7 @@ export class MainTitleBar extends DTitleBar { app.on(AppEvents.TOGGLE_DRAWER, (value) => { this.drawerBtn.setChecked(value); - }) + }); } private handleConfigUpdate(config: ConfigManager) { @@ -123,7 +123,7 @@ export class MainTitleBar extends DTitleBar { this.addEventListener(WidgetEventTypes.MouseButtonPress, () => { app.emit(AppEvents.TOGGLE_DRAWER, false); - }) + }); controls.setSpacing(6); controls.setContentsMargins(16, 12, 16, 12); @@ -170,7 +170,7 @@ export class MainTitleBar extends DTitleBar { if (channel instanceof DMChannel) { statusLabel.setText('●'); statusLabel.setInlineStyle( - `color: ${PresenceStatusColor.get(channel.recipient.presence.status || 'offline')}`, + `color: ${PresenceStatusColor.get(channel.recipient.presence.status || 'offline')}` ); } } diff --git a/src/components/MessagesPanel/MessageItem.ts b/src/components/MessagesPanel/MessageItem.ts index 012907a..18f5783 100644 --- a/src/components/MessagesPanel/MessageItem.ts +++ b/src/components/MessagesPanel/MessageItem.ts @@ -17,7 +17,7 @@ import { WidgetEventTypes, } from '@nodegui/nodegui'; import { Message, Snowflake } from 'discord.js'; -import { __ } from 'i18n'; +import { __ } from '../../utilities/StringProvider'; import { app } from '../..'; import { Events } from '../../utilities/Events'; import { createLogger } from '../../utilities/Console'; @@ -32,6 +32,7 @@ import { processMarkdown, processMentions, } from './MessageUtilities'; +import { PhraseID } from '../../utilities/PhraseID'; const avatarCache = new Map(); const { error } = createLogger('MessageItem'); @@ -147,7 +148,7 @@ export class MessageItem extends QWidget { app.emit( Events.OPEN_USER_MENU, this.message.member || this.message.author, - avatar.mapToGlobal(new QPoint(x, y)), + avatar.mapToGlobal(new QPoint(x, y)) ); }); @@ -220,7 +221,11 @@ export class MessageItem extends QWidget { if (this.contentNoEmojis) { processEmojis(this.contentNoEmojis) - .then((content) => !this.contentLabel.native.destroyed && this.contentLabel.setText(content)) + .then( + (content) => + !this.contentLabel.native.destroyed && + this.contentLabel.setText(content.replace(/\n/g, '
')) + ) .catch(error.bind(error, "Couldn't load emoji.")); } @@ -234,7 +239,7 @@ export class MessageItem extends QWidget { async loadAvatar() { const { message, avatar } = this; - if (!message || avatar.native.destroyed) { + if (!message || this.native.destroyed || avatar.native.destroyed) { return; } @@ -248,10 +253,10 @@ export class MessageItem extends QWidget { try { const image = await pictureWorker.loadImage( - message.author.displayAvatarURL({ format: 'png', size: 256 }), + message.author.displayAvatarURL({ format: 'png', size: 256 }) ); - if (avatar.native.destroyed) { + if (this.native.destroyed || avatar.native.destroyed) { return; } @@ -293,7 +298,7 @@ export class MessageItem extends QWidget { return this; } - contentLabel.setText(content); + contentLabel.setText(content.replace(/\n/g, '
')); } [ @@ -310,7 +315,7 @@ export class MessageItem extends QWidget { * @param message Message to process. */ private loadSystemMessage(message: Message) { - const content = __(`MESSAGE_${message.type}`) || message.type; + const content = __(`MESSAGE_${message.type}` as PhraseID) || message.type; this.dateLabel.hide(); this.contentLabel.setPlainText(` ${content}`); diff --git a/src/components/MessagesPanel/MessageUtilities.ts b/src/components/MessagesPanel/MessageUtilities.ts index c2d7665..faddf74 100644 --- a/src/components/MessagesPanel/MessageUtilities.ts +++ b/src/components/MessagesPanel/MessageUtilities.ts @@ -13,7 +13,6 @@ import { WidgetEventTypes, } from '@nodegui/nodegui'; import { GuildChannel, Message, MessageEmbedImage, MessageMentions } from 'discord.js'; -import { __ } from 'i18n'; import markdownIt from 'markdown-it'; import open from 'open'; import { extname, join } from 'path'; @@ -22,6 +21,7 @@ import { app, MAX_QSIZE, PIXMAP_EXTS } from '../..'; import { createLogger } from '../../utilities/Console'; import { pictureWorker } from '../../utilities/PictureWorker'; import { resolveEmoji } from '../../utilities/ResolveEmoji'; +import { __ } from '../../utilities/StringProvider'; import { DLabel } from '../DLabel/DLabel'; import { MessageItem } from './MessageItem'; @@ -100,13 +100,11 @@ export async function processMentions(content: string, message: Message) { if (message.guild) { const member = message.guild.members.resolve(id); const memberName = - member?.displayName || - app.client.users.resolve(id)?.username || - 'unknown-user'; + member?.displayName || app.client.users.resolve(id)?.username || 'unknown-user'; newContent = newContent.replace( escape(match), - `@${memberName}`, + `@${memberName}` ); } else { let userName: string; @@ -121,7 +119,7 @@ export async function processMentions(content: string, message: Message) { newContent = newContent.replace( escape(match), - `@${userName}`, + `@${userName}` ); } }), @@ -132,7 +130,7 @@ export async function processMentions(content: string, message: Message) { if (role) { newContent = newContent.replace( escape(match), - `@${role.name}`, + `@${role.name}` ); } }), @@ -143,7 +141,7 @@ export async function processMentions(content: string, message: Message) { newContent = newContent.replace( escape(match), - `#${channelName}`, + `#${channelName}` ); }), ]); @@ -187,7 +185,7 @@ export async function processEmojiPlaceholders(content: string): Promise for (const emo of emoIds) { newContent = newContent.replace( escape(emo), - ``, + `` ); } @@ -226,7 +224,7 @@ export async function processEmojis(content: string): Promise { newContent = newContent.replace( escape(emo), - ``, + `` ); }) .catch(() => { @@ -280,7 +278,7 @@ export function processEmbeds(message: Message, item: MessageItem): QWidget[] { pictureWorker .loadImage(embed.author.proxyIconURL) .then( - (path) => !item.native.destroyed && auimage.setPixmap(new QPixmap(path).scaled(24, 24)), + (path) => !item.native.destroyed && auimage.setPixmap(new QPixmap(path).scaled(24, 24)) ) .catch(() => { error(`Couldn't load avatar picture of embed ${embed.title}.`); @@ -295,7 +293,7 @@ export function processEmbeds(message: Message, item: MessageItem): QWidget[] { if (embed.author.url) { auname.setText( - `${embed.author.name}`, + `${embed.author.name}` ); } else { auname.setText(embed.author.name || ''); @@ -491,7 +489,10 @@ export async function processInvites(message: Message, msgItem: MessageItem): Pr } }; }) - .catch(error.bind("Couldn't load the invite.")); + .catch(() => { + helperText.setText(__('INVITE_BUTTON_INVALID')); + avatar.setText(':-('); + }); } return widgets; @@ -519,7 +520,7 @@ export function processAttachments(message: Message, item: MessageItem): QLabel[ `${attach.name || attach.url}
Size: ${attach.size} bytes ${attach.width && attach.height ? `
Resolution: ${attach.width}x${attach.height}` : ''} - `, + ` ); qimage.addEventListener(WidgetEventTypes.MouseButtonPress, () => { diff --git a/src/components/MessagesPanel/MessagesPanel.ts b/src/components/MessagesPanel/MessagesPanel.ts index 08556f5..43bcd15 100644 --- a/src/components/MessagesPanel/MessagesPanel.ts +++ b/src/components/MessagesPanel/MessagesPanel.ts @@ -73,7 +73,7 @@ export class MessagesPanel extends QScrollArea { !lowest?.native.destroyed && this.isBottom(lowest) && this.ensureVisible(0, MAX_QSIZE), - 100, + 100 ); this.initAckTimer(); @@ -87,7 +87,8 @@ export class MessagesPanel extends QScrollArea { } private initRoot() { - this.root = new QWidget(this); + this.takeWidget(); + this.root = new QWidget(); this.root.setObjectName('MessagesContainer'); this.root.addEventListener(WidgetEventTypes.Move, this.handleWheel.bind(this, false)); this.rootControls = new QBoxLayout(Direction.BottomToTop); @@ -154,10 +155,12 @@ export class MessagesPanel extends QScrollArea { return; } - const messages = (await channel.messages.fetch({ - before: before.message?.id, - limit, - })) + const messages = ( + await channel.messages.fetch({ + before: before.message?.id, + limit, + }) + ) .array() .sort((a, b) => a.createdAt.getTime() - b.createdAt.getTime()) .reverse(); diff --git a/src/components/ProfilePopup/NoteSection.ts b/src/components/ProfilePopup/NoteSection.ts index 139efdd..18efd6c 100644 --- a/src/components/ProfilePopup/NoteSection.ts +++ b/src/components/ProfilePopup/NoteSection.ts @@ -8,7 +8,7 @@ import { WidgetEventTypes, } from '@nodegui/nodegui'; import { User } from 'discord.js'; -import { __ } from 'i18n'; +import { __ } from '../../utilities/StringProvider'; import { MAX_QSIZE } from '../..'; export class NoteSection extends QWidget { diff --git a/src/components/ProfilePopup/Profile.ts b/src/components/ProfilePopup/Profile.ts index 0c181e2..b00a693 100644 --- a/src/components/ProfilePopup/Profile.ts +++ b/src/components/ProfilePopup/Profile.ts @@ -93,7 +93,7 @@ export class Profile extends QWidget { username.setText(user.tag); } else { nickname.setText( - `${user.username}#${user.discriminator}`, + `${user.username}#${user.discriminator}` ); username.hide(); diff --git a/src/components/ProfilePopup/ProfilePresence.ts b/src/components/ProfilePopup/ProfilePresence.ts index 787b045..3b6dc01 100644 --- a/src/components/ProfilePopup/ProfilePresence.ts +++ b/src/components/ProfilePopup/ProfilePresence.ts @@ -1,10 +1,11 @@ import { AlignmentFlag, Direction, QBoxLayout, QLabel, QPixmap, QWidget } from '@nodegui/nodegui'; import { ActivityType, Client, Presence } from 'discord.js'; -import { __ } from 'i18n'; +import { __ } from '../../utilities/StringProvider'; import { app, MAX_QSIZE } from '../..'; import { createLogger } from '../../utilities/Console'; import { Events } from '../../utilities/Events'; import { pictureWorker } from '../../utilities/PictureWorker'; +import { PhraseID } from '../../utilities/PhraseID'; const { error } = createLogger('ProfilePresence'); @@ -12,7 +13,7 @@ const { error } = createLogger('ProfilePresence'); * Represents currently playing section in the profile popup. */ export class ProfilePresence extends QWidget { - private static ActivityTypeText: Map = new Map([ + private static ActivityTypeText: Map = new Map([ ['LISTENING', 'USER_ACTIVITY_HEADER_LISTENING'], ['PLAYING', 'USER_ACTIVITY_HEADER_PLAYING'], ['WATCHING', 'USER_ACTIVITY_HEADER_WATCHING'], @@ -107,10 +108,10 @@ export class ProfilePresence extends QWidget { } header.setText( - __(ProfilePresence.ActivityTypeText.get(activity.type) || '', { + __(ProfilePresence.ActivityTypeText.get(activity.type) as PhraseID, { name: activity.name, platform: activity.name, - }), + }) ); switch (activity.type) { diff --git a/src/components/ProfilePopup/RolesSection.ts b/src/components/ProfilePopup/RolesSection.ts index 4e4e2ec..10f9101 100644 --- a/src/components/ProfilePopup/RolesSection.ts +++ b/src/components/ProfilePopup/RolesSection.ts @@ -10,7 +10,7 @@ import { WidgetEventTypes, } from '@nodegui/nodegui'; import { GuildMemberRoleManager } from 'discord.js'; -import { __ } from 'i18n'; +import { __ } from '../../utilities/StringProvider'; import { MAX_QSIZE } from '../..'; export class RolesSection extends QWidget { diff --git a/src/components/UserButton/UserButton.ts b/src/components/UserButton/UserButton.ts index de8f8a1..cf23fcb 100644 --- a/src/components/UserButton/UserButton.ts +++ b/src/components/UserButton/UserButton.ts @@ -9,13 +9,14 @@ import { WidgetEventTypes, } from '@nodegui/nodegui'; import { ActivityType, Client, Constants, GuildMember, Presence, User } from 'discord.js'; -import { __ } from 'i18n'; import { app, MAX_QSIZE } from '../..'; import { createLogger } from '../../utilities/Console'; import { Events as AppEvents } from '../../utilities/Events'; +import { PhraseID } from '../../utilities/PhraseID'; import { pictureWorker } from '../../utilities/PictureWorker'; import { PresenceStatusColor } from '../../utilities/PresenceStatusColor'; import { resolveEmoji } from '../../utilities/ResolveEmoji'; +import { __ } from '../../utilities/StringProvider'; import { DChannelButton } from '../DChannelButton/DChannelButton'; const { error } = createLogger('UserButton'); @@ -26,7 +27,7 @@ const p0 = new QPoint(0, 0); * Represents a button with user's avatar, name and current status. */ export class UserButton extends DChannelButton { - private static ActivityTypeText: Map = new Map([ + private static ActivityTypeText: Map = new Map([ ['LISTENING', 'LISTENING_TO'], ['PLAYING', 'PLAYING_GAME'], ['WATCHING', 'WATCHING'], @@ -206,7 +207,7 @@ export class UserButton extends DChannelButton { try { const path = await pictureWorker.loadImage( - this.user.displayAvatarURL({ format: 'png', size: 256 }), + this.user.displayAvatarURL({ format: 'png', size: 256 }) ); if (this.native.destroyed) { @@ -242,7 +243,7 @@ export class UserButton extends DChannelButton { if (type === 'CUSTOM_STATUS') { status = state || ''; } else { - status = __(UserButton.ActivityTypeText.get(type) || '', { name, game: name }); + status = __(UserButton.ActivityTypeText.get(type) as PhraseID, { name, game: name }); } this.statusLabel.setText(status); diff --git a/src/components/UserMenu/UserMenu.ts b/src/components/UserMenu/UserMenu.ts index 3a31298..d4fe07f 100644 --- a/src/components/UserMenu/UserMenu.ts +++ b/src/components/UserMenu/UserMenu.ts @@ -14,9 +14,10 @@ import { WidgetEventTypes, } from '@nodegui/nodegui'; import { GuildMember, User } from 'discord.js'; -import { __ } from 'i18n'; import { app } from '../..'; import { Events } from '../../utilities/Events'; +import { PhraseID } from '../../utilities/PhraseID'; +import { __ } from '../../utilities/StringProvider'; export class UserMenu extends QMenu { private someone?: GuildMember | User; @@ -48,7 +49,7 @@ export class UserMenu extends QMenu { * @param id Translation ID, also used in this.items * @param callback Callback */ - private addSimpleItem(id: string, callback: () => void) { + private addSimpleItem(id: PhraseID, callback: () => void) { const item = new QAction(); item.setText(__(id)); @@ -92,7 +93,8 @@ export class UserMenu extends QMenu { this.items.set('VOLUME_SEPARATOR', this.addSeparator()); - { // User volume slider + { + // User volume slider const item = new QAction(); item.setText(''); diff --git a/src/components/UserPanel/UserPanel.ts b/src/components/UserPanel/UserPanel.ts index aa453b0..40a2ddc 100644 --- a/src/components/UserPanel/UserPanel.ts +++ b/src/components/UserPanel/UserPanel.ts @@ -13,15 +13,16 @@ import { WidgetEventTypes, } from '@nodegui/nodegui'; import { Client, Constants, DQConstants } from 'discord.js'; -import { __ } from 'i18n'; import { join } from 'path'; import { app, MAX_QSIZE } from '../..'; +import { createLogger } from '../../utilities/Console'; import { CustomStatus } from '../../utilities/CustomStatus'; import { Events as AppEvents } from '../../utilities/Events'; -import { PresenceStatusColor } from '../../utilities/PresenceStatusColor'; -import { createLogger } from '../../utilities/Console'; +import { PhraseID } from '../../utilities/PhraseID'; import { pictureWorker } from '../../utilities/PictureWorker'; +import { PresenceStatusColor } from '../../utilities/PresenceStatusColor'; import { resolveEmoji } from '../../utilities/ResolveEmoji'; +import { __ } from '../../utilities/StringProvider'; import { DIconButton } from '../DIconButton/DIconButton'; import { UserPanelMenu } from './UserPanelMenu'; @@ -117,7 +118,7 @@ export class UserPanel extends QWidget { this.copiedAmount += 1; clipboard.setText(app.client.user?.tag || '', QClipboardMode.Clipboard); [discLabel, statusText].forEach((w) => - w.setText(__(`ACCOUNT_USERNAME_COPY_SUCCESS_${Math.min(this.copiedAmount, 11)}`)), + w.setText(__(`ACCOUNT_USERNAME_COPY_SUCCESS_${Math.min(this.copiedAmount, 11)}` as PhraseID)) ); this.copiedTimer = setTimeout(() => { @@ -249,7 +250,7 @@ export class UserPanel extends QWidget { try { const path = await pictureWorker.loadImage( - client.user.displayAvatarURL({ format: 'png', size: 256 }), + client.user.displayAvatarURL({ format: 'png', size: 256 }) ); avatar.setPixmap(new QPixmap(path).scaled(32, 32, 1, 1)); diff --git a/src/components/UserPanel/UserPanelMenu.ts b/src/components/UserPanel/UserPanelMenu.ts index e61c64c..3fa3815 100644 --- a/src/components/UserPanel/UserPanelMenu.ts +++ b/src/components/UserPanel/UserPanelMenu.ts @@ -1,8 +1,9 @@ import { QAction, QIcon, QMenu, WidgetAttribute } from '@nodegui/nodegui'; import { PresenceStatusData } from 'discord.js'; -import { __ } from 'i18n'; import { join } from 'path'; import { app } from '../..'; +import { PhraseID } from '../../utilities/PhraseID'; +import { __ } from '../../utilities/StringProvider'; export class UserPanelMenu extends QMenu { constructor(parent?: any) { @@ -17,7 +18,7 @@ export class UserPanelMenu extends QMenu { for (const status of ['online', 'idle', 'dnd', 'invisible']) { const item = new QAction(); - item.setText(__(`STATUS_${status.toUpperCase()}`)); + item.setText(__(`STATUS_${status.toUpperCase()}` as PhraseID)); item.setIcon(new QIcon(join(__dirname, `assets/icons/status-${status}.png`))); item.addEventListener('triggered', () => app.client.user?.setPresence({ status })); this.addAction(item); diff --git a/src/components/VoicePanel/NoiseReductor.ts b/src/components/VoicePanel/NoiseReductor.ts index 38ace2f..c7b9020 100644 --- a/src/components/VoicePanel/NoiseReductor.ts +++ b/src/components/VoicePanel/NoiseReductor.ts @@ -9,7 +9,7 @@ export class NoiseReductor extends Transform { constructor( private onSetSpeaking: (isSpeaking: boolean) => void, - private onLoudnessChanged?: (loudness: number) => void, + private onLoudnessChanged?: (loudness: number) => void ) { super(); } diff --git a/src/components/VoicePanel/VoicePanel.ts b/src/components/VoicePanel/VoicePanel.ts index de8e5ef..861aef5 100644 --- a/src/components/VoicePanel/VoicePanel.ts +++ b/src/components/VoicePanel/VoicePanel.ts @@ -18,7 +18,6 @@ import { VoiceConnection, VoiceState, } from 'discord.js'; -import { __ } from 'i18n'; import open from 'open'; import { join } from 'path'; import { VolumeTransformer } from 'prism-media'; @@ -27,6 +26,7 @@ import { app } from '../..'; import { ConfigManager } from '../../utilities/ConfigManager'; import { createLogger } from '../../utilities/Console'; import { Events as AppEvents } from '../../utilities/Events'; +import { __ } from '../../utilities/StringProvider'; import { createPlaybackStream, createRecordStream } from '../../utilities/VoiceStreams'; import { DIconButton } from '../DIconButton/DIconButton'; import { NoiseReductor } from './NoiseReductor'; @@ -245,7 +245,7 @@ export class VoicePanel extends QWidget { type: 's16le', })) as unknown) as Transform, // Change the volume (this.playbackStream = createPlaybackStream()).stdin, // Output to a playback stream - (err) => err && debug("Couldn't finish playback pipeline.", err), + (err) => err && debug("Couldn't finish playback pipeline.", err) ); for (const member of channel.members.filter((m) => m.user !== app.client.user).values()) { @@ -267,7 +267,7 @@ export class VoicePanel extends QWidget { })) as unknown) as Transform, // Change the volume (this.recordNoiseReductor = new NoiseReductor(this.onSpeaking.bind(this))), // Audio gate - (err) => err && debug("Couldn't finish recording pipeline.", err), + (err) => err && debug("Couldn't finish recording pipeline.", err) ); this.connection.play(recorder, { bitrate: 256, type: 'converted', highWaterMark: 0 }); diff --git a/src/dialogs/AcceptInviteDialog.ts b/src/dialogs/AcceptInviteDialog.ts index a48d702..40f86dc 100644 --- a/src/dialogs/AcceptInviteDialog.ts +++ b/src/dialogs/AcceptInviteDialog.ts @@ -1,11 +1,11 @@ import { Direction, QBoxLayout, QLabel, QWidget } from '@nodegui/nodegui'; -import { __ } from 'i18n'; import { URL } from 'url'; import { app } from '..'; import { DColorButton } from '../components/DColorButton/DColorButton'; import { DColorButtonColor } from '../components/DColorButton/DColorButtonColor'; import { DErrorMessage } from '../components/DErrorMessage/DErrorMessage'; import { DTextEdit } from '../components/DTextEdit/DTextEdit'; +import { __ } from '../utilities/StringProvider'; import { Dialog } from './Dialog'; export class AcceptInviteDialog extends Dialog { diff --git a/src/dialogs/ConfirmLeaveGuildDialog.ts b/src/dialogs/ConfirmLeaveGuildDialog.ts index 0e4f6b0..0bb780c 100644 --- a/src/dialogs/ConfirmLeaveGuildDialog.ts +++ b/src/dialogs/ConfirmLeaveGuildDialog.ts @@ -1,10 +1,10 @@ import { Direction, QBoxLayout, QLabel, QWidget } from '@nodegui/nodegui'; import { Guild } from 'discord.js'; -import { __ } from 'i18n'; import { app } from '..'; import { DColorButton } from '../components/DColorButton/DColorButton'; import { DColorButtonColor } from '../components/DColorButton/DColorButtonColor'; import { Events } from '../utilities/Events'; +import { __ } from '../utilities/StringProvider'; import { Dialog } from './Dialog'; export class ConfirmLeaveGuildDialog extends Dialog { diff --git a/src/dialogs/CustomStatusDialog.ts b/src/dialogs/CustomStatusDialog.ts index c8ba7ef..ee54052 100644 --- a/src/dialogs/CustomStatusDialog.ts +++ b/src/dialogs/CustomStatusDialog.ts @@ -9,7 +9,7 @@ import { WidgetEventTypes, } from '@nodegui/nodegui'; import { Emoji } from 'discord.js'; -import { __ } from 'i18n'; +import { __ } from '../utilities/StringProvider'; import { app } from '..'; import { DColorButton } from '../components/DColorButton/DColorButton'; import { DColorButtonColor } from '../components/DColorButton/DColorButtonColor'; @@ -55,7 +55,7 @@ export class CustomStatusDialog extends Dialog { super.show(); this.statusLabel.setText( - __('CUSTOM_STATUS_MODAL_BODY', { username: app.client?.user?.username || '' }), + __('CUSTOM_STATUS_MODAL_BODY', { username: app.client?.user?.username || '' }) ); this.statusInput.setText(app.client.user.customStatus?.text || ''); diff --git a/src/dialogs/Dialog.ts b/src/dialogs/Dialog.ts index bb3b5ce..bb64c75 100644 --- a/src/dialogs/Dialog.ts +++ b/src/dialogs/Dialog.ts @@ -9,8 +9,8 @@ import { QWidget, WidgetEventTypes, } from '@nodegui/nodegui'; -import { __ } from 'i18n'; import { join } from 'path'; +import { __ } from '../utilities/StringProvider'; import { DIconButton } from '../components/DIconButton/DIconButton'; import { MainWindow } from '../windows/MainWindow/MainWindow'; @@ -60,7 +60,7 @@ export class Dialog extends QWidget { protected initEvents() { (this.nodeParent as MainWindow).addEventListener( WidgetEventTypes.Resize, - this.resizeToWindow.bind(this), + this.resizeToWindow.bind(this) ); this.resizeToWindow(); diff --git a/src/dialogs/NicknameChangeDialog.ts b/src/dialogs/NicknameChangeDialog.ts index 503b0d7..2ce02fd 100644 --- a/src/dialogs/NicknameChangeDialog.ts +++ b/src/dialogs/NicknameChangeDialog.ts @@ -1,6 +1,6 @@ import { Direction, QBoxLayout, QLabel, QWidget } from '@nodegui/nodegui'; import { GuildMember } from 'discord.js'; -import { __ } from 'i18n'; +import { __ } from '../utilities/StringProvider'; import { DColorButton } from '../components/DColorButton/DColorButton'; import { DColorButtonColor } from '../components/DColorButton/DColorButtonColor'; import { DErrorMessage } from '../components/DErrorMessage/DErrorMessage'; diff --git a/locales/de-DE.json b/src/locales/de-DE.json similarity index 100% rename from locales/de-DE.json rename to src/locales/de-DE.json diff --git a/locales/en-US.json b/src/locales/en-US.json similarity index 97% rename from locales/en-US.json rename to src/locales/en-US.json index 685cec8..469ce8c 100644 --- a/locales/en-US.json +++ b/src/locales/en-US.json @@ -27,6 +27,7 @@ "CLEAR_CACHE_MOTIVATIONAL_MESSAGE": "Yay! More hard drive space!", "EMOJI_PICKER_PRO_TIP_BODY": "Pressing Ctrl key adds the emoji as a file!", "OPTIMIZE_FOR_MOBILE": "Make the user interface more mobile-friendly", + "PLATFORM_NOT_SUPPORTED": "This feature is not supported on this platform.", "SEARCH_FOR_EMOJI": "Find the perfect emoji", "CONNECTION_STATUS_CONNECTING": "Connecting", @@ -154,5 +155,6 @@ "OPEN": "Open", "QUIT": "Quit", "MEMBER_LIST": "Member List", - "ACCESSIBILITY_ZOOM_LEVEL_LABEL": "Zoom level" + "ACCESSIBILITY_ZOOM_LEVEL_LABEL": "Zoom level", + "INVITE_BUTTON_INVALID": "Invalid Invite", } diff --git a/locales/ru-RU.json b/src/locales/ru-RU.json similarity index 97% rename from locales/ru-RU.json rename to src/locales/ru-RU.json index f16920d..0beefa7 100644 --- a/locales/ru-RU.json +++ b/src/locales/ru-RU.json @@ -27,6 +27,7 @@ "CLEAR_CACHE_MOTIVATIONAL_MESSAGE": "Ура! Больше места на диске!", "EMOJI_PICKER_PRO_TIP_BODY": "Вставляйте эмодзи как картинки при помощи Ctrl.", "OPTIMIZE_FOR_MOBILE": "Оптимизировать интерфейс под мобильные устройства", + "PLATFORM_NOT_SUPPORTED": "Данная функция недоступна для данной платформы.", "SEARCH_FOR_EMOJI": "Найдите идеальный эмодзи", "CONNECTION_STATUS_CONNECTING": "Подключение", @@ -152,5 +153,6 @@ "OPEN": "Открыть", "QUIT": "Закрыть", "MEMBER_LIST": "Список участников", - "ACCESSIBILITY_ZOOM_LEVEL_LABEL": "Уровень масштабирования" + "ACCESSIBILITY_ZOOM_LEVEL_LABEL": "Уровень масштабирования", + "INVITE_BUTTON_INVALID": "Приглашение недействительно" } diff --git a/src/patches/ClientUser.ts b/src/patches/ClientUser.ts index a4ce44e..6201d47 100644 --- a/src/patches/ClientUser.ts +++ b/src/patches/ClientUser.ts @@ -115,9 +115,8 @@ ClientUser.prototype.acceptInvite = async function acceptInvite(code: { id: stri reject(new Error('Accepting invite timed out')); }, 120e3); }) - .catch((e: Error) => { - console.error(e); + .catch(() => { reject(new Error('Invite code is not valid')); - }), + }) ); }; diff --git a/src/patches/Guild.ts b/src/patches/Guild.ts index 0db4ebe..35d7856 100644 --- a/src/patches/Guild.ts +++ b/src/patches/Guild.ts @@ -9,7 +9,7 @@ Object.defineProperty(Guild.prototype, 'acknowledged', { (channel: any) => ['news', 'text'].includes(channel.type) && channel.can(Permissions.FLAGS.VIEW_CHANNEL) && - !channel.muted, + !channel.muted ) .every((channel: any) => channel.acknowledged); }, diff --git a/src/patches/Handlers.ts b/src/patches/Handlers.ts index 4e6e5ff..4306424 100644 --- a/src/patches/Handlers.ts +++ b/src/patches/Handlers.ts @@ -25,7 +25,7 @@ Object.assign(handlers, { for (const settings of data.user_guild_settings) { client.user.guildSettings.set( settings.guild_id, - new ClientUserGuildSettings(settings, client), + new ClientUserGuildSettings(settings, client) ); } } @@ -61,13 +61,13 @@ Object.assign(handlers, { } else { client.user.guildSettings.set( packet.d.guild_id, - new ClientUserGuildSettings(packet.d, client), + new ClientUserGuildSettings(packet.d, client) ); } client.emit( ((Constants as unknown) as DQConstants).Events.USER_GUILD_SETTINGS_UPDATE, - client.user.guildSettings.get(packet.d.guild_id), + client.user.guildSettings.get(packet.d.guild_id) ); }, diff --git a/src/patches/QWidget.ts b/src/patches/QWidget.ts index bc134a5..ec28ba0 100644 --- a/src/patches/QWidget.ts +++ b/src/patches/QWidget.ts @@ -43,7 +43,7 @@ for (const object of consts) { trace( `Method ${String(prop)} was called of a dereferenced object of type ${ target.constructor.name - }`, + }` ); return noop; @@ -73,7 +73,7 @@ const processDelete = function processDelete(this: any) { const processPress = function processPress(this: any) { if (app.window?.shiftKeyPressed) { - console.log(this); + debug(this); } }; diff --git a/src/patches/TextBasedChannel.ts b/src/patches/TextBasedChannel.ts index d92187d..8fce120 100644 --- a/src/patches/TextBasedChannel.ts +++ b/src/patches/TextBasedChannel.ts @@ -40,7 +40,7 @@ TextBasedChannel.applyToClass = (structure: any, full = false, ignore: string[] Object.defineProperty( structure.prototype, prop, - Object.getOwnPropertyDescriptor(TextBasedChannel.prototype, prop) as PropertyDescriptor, + Object.getOwnPropertyDescriptor(TextBasedChannel.prototype, prop) as PropertyDescriptor ); } } diff --git a/src/utilities/ClientManager.ts b/src/utilities/ClientManager.ts index 77e5ec8..17153bd 100644 --- a/src/utilities/ClientManager.ts +++ b/src/utilities/ClientManager.ts @@ -1,6 +1,6 @@ import { Client, Constants, HTTPError } from 'discord.js'; -import { __ } from 'i18n'; import { notify } from 'node-notifier'; +import { __ } from './StringProvider'; import { app } from '..'; import { Account } from './Account'; import { clientOptions } from './ClientOptions'; @@ -79,7 +79,7 @@ export class ClientManager { type: 'error', icon: await pictureWorker.loadImage( message.author.displayAvatarURL({ size: 64, format: 'png' }), - { roundify: false }, + { roundify: false } ), category: 'im', hint: 'string:desktop-entry:discord', diff --git a/src/utilities/Console.ts b/src/utilities/Console.ts index 08a30b5..6822fe4 100644 --- a/src/utilities/Console.ts +++ b/src/utilities/Console.ts @@ -1,3 +1,4 @@ +/* eslint-disable no-console */ import { app } from '..'; export function createLogger(prefix: string) { diff --git a/src/utilities/PhraseID.ts b/src/utilities/PhraseID.ts new file mode 100644 index 0000000..8e9feb0 --- /dev/null +++ b/src/utilities/PhraseID.ts @@ -0,0 +1 @@ +export type PhraseID = keyof typeof import('../locales/en-US.json'); diff --git a/src/utilities/PluginManager.ts b/src/utilities/PluginManager.ts index 43a4d7a..a6797d8 100644 --- a/src/utilities/PluginManager.ts +++ b/src/utilities/PluginManager.ts @@ -40,7 +40,7 @@ export class PluginManager { recursiveSearch(root: string): Promise[] { mkdirSync(root, { recursive: true }); const dirs = readdirSync(root, { withFileTypes: true }).filter( - (dir) => !['.git', 'node_modules'].includes(dir.name), + (dir) => !['.git', 'node_modules'].includes(dir.name) ); let tasks: Promise[] = []; diff --git a/src/utilities/StringProvider.ts b/src/utilities/StringProvider.ts new file mode 100644 index 0000000..85dccd1 --- /dev/null +++ b/src/utilities/StringProvider.ts @@ -0,0 +1,6 @@ +import { __ as _i } from 'i18n'; +import { PhraseID } from './PhraseID'; + +export function __(id: PhraseID, ...args: any[]) { + return _i(id, ...args); +} diff --git a/src/views/SettingsView/Footer.ts b/src/views/SettingsView/Footer.ts index 2b841b3..0cf9c34 100644 --- a/src/views/SettingsView/Footer.ts +++ b/src/views/SettingsView/Footer.ts @@ -41,7 +41,7 @@ export class Footer extends QWidget { label.setText( `${app.name} ${me.version}${__BUILDNUM__ !== 0 ? ` (build ${__BUILDNUM__})` : ''}
node ${ process.versions.node - }
qode ${process.versions.qode}
${process.platform} ${process.arch}`, + }
qode ${process.versions.qode}
${process.platform} ${process.arch}` ); label.setOpenExternalLinks(true); diff --git a/src/views/SettingsView/SectionList.ts b/src/views/SettingsView/SectionList.ts index 6db8719..2f93ce0 100644 --- a/src/views/SettingsView/SectionList.ts +++ b/src/views/SettingsView/SectionList.ts @@ -6,7 +6,7 @@ import { QScrollArea, Shape, } from '@nodegui/nodegui'; -import { __ } from 'i18n'; +import { __ } from '../../utilities/StringProvider'; import { app, MAX_QSIZE } from '../..'; import { Events } from '../../utilities/Events'; import { Page } from './pages/Page'; diff --git a/src/views/SettingsView/SettingsView.ts b/src/views/SettingsView/SettingsView.ts index c1f6cad..ed74515 100644 --- a/src/views/SettingsView/SettingsView.ts +++ b/src/views/SettingsView/SettingsView.ts @@ -14,18 +14,18 @@ import { ScrollBarPolicy, Shape, } from '@nodegui/nodegui'; -import { __ } from 'i18n'; import { join } from 'path'; import { app, MAX_QSIZE } from '../..'; import { Events } from '../../utilities/Events'; +import { __ } from '../../utilities/StringProvider'; import { CategoryHeader } from './CategoryHeader'; import { Divider } from './Divider'; import { Footer } from './Footer'; import { AccountsPage } from './pages/AccountsPage'; import { AppearancePage } from './pages/AppearancePage'; import { MyAccountPage } from './pages/MyAccountPage'; -import { SystemPage } from './pages/SystemPage'; import { Page } from './pages/Page'; +import { SystemPage } from './pages/SystemPage'; import { VoicePage } from './pages/VoicePage'; import { SectionList } from './SectionList'; diff --git a/src/views/SettingsView/pages/AccountsPage.ts b/src/views/SettingsView/pages/AccountsPage.ts index 71b8b11..61f018e 100644 --- a/src/views/SettingsView/pages/AccountsPage.ts +++ b/src/views/SettingsView/pages/AccountsPage.ts @@ -10,7 +10,7 @@ import { WidgetEventTypes, } from '@nodegui/nodegui'; import { Client } from 'discord.js'; -import { __ } from 'i18n'; +import { __ } from '../../../utilities/StringProvider'; import { app } from '../../..'; import { DColorButton } from '../../../components/DColorButton/DColorButton'; import { DColorButtonColor } from '../../../components/DColorButton/DColorButtonColor'; @@ -113,7 +113,7 @@ export class AccountsPage extends Page { uname.setObjectName('UserName'); uname.setText( - `${account.username}#${account.discriminator}`, + `${account.username}#${account.discriminator}` ); const deleteBtn = new DColorButton(DColorButtonColor.RED); @@ -123,7 +123,7 @@ export class AccountsPage extends Page { deleteBtn.addEventListener('clicked', () => { app.config.set( 'accounts', - app.config.get('accounts').filter((v) => v !== account), + app.config.get('accounts').filter((v) => v !== account) ); accWidget.hide(); @@ -177,7 +177,7 @@ export class AccountsPage extends Page { accounts.map((acc, j) => ({ ...acc, autoLogin: i === j ? !isAutoLogin : false, - })), + })) ); void app.config.save(); @@ -215,7 +215,7 @@ export class AccountsPage extends Page { __('ACCOUNTS_PAGE_HELPER', { guideURL: 'https://github.com/Tyrrrz/DiscordChatExporter/wiki/Obtaining-Token-and-Channel-IDs', - }), + }) ); const addTokenField = new DLineEdit(); diff --git a/src/views/SettingsView/pages/AppearancePage.ts b/src/views/SettingsView/pages/AppearancePage.ts index 081661f..c4c6971 100644 --- a/src/views/SettingsView/pages/AppearancePage.ts +++ b/src/views/SettingsView/pages/AppearancePage.ts @@ -1,7 +1,8 @@ import { QLabel, QVariant } from '@nodegui/nodegui'; import { existsSync, promises } from 'fs'; -import { getLocale, setLocale, __ } from 'i18n'; +import { getLocale, setLocale } from 'i18n'; import { basename, join } from 'path'; +import { __ } from '../../../utilities/StringProvider'; import { app } from '../../..'; import { DComboBox } from '../../../components/DComboBox/DComboBox'; import { Events } from '../../../utilities/Events'; @@ -43,7 +44,19 @@ export class AppearancePage extends Page { } private async initPage() { - const { title, header, enavcx, rdavcx, ismbcx, prmdcx, dbgcx, themeSel, langSel, zoomSel, layout } = this; + const { + title, + header, + enavcx, + rdavcx, + ismbcx, + prmdcx, + dbgcx, + themeSel, + langSel, + zoomSel, + layout, + } = this; header.setObjectName('Header2'); header.setText(title); @@ -143,7 +156,7 @@ export class AppearancePage extends Page { try { const file = JSON.parse( - (await readFile(join('./dist/locales/', locale.name))).toString(), + (await readFile(join('./dist/locales/', locale.name))).toString() ); this.langSel.addItem(undefined, file['locale.name'], new QVariant(localeName)); @@ -152,7 +165,7 @@ export class AppearancePage extends Page { } return localeName; - }), + }) ); } catch (e) { error("Couldn't load languages.", e); @@ -173,7 +186,7 @@ export class AppearancePage extends Page { themeSel.setCurrentText(theme); } - zoomSel.setCurrentText(app.config.get('zoomLevel')) + zoomSel.setCurrentText(app.config.get('zoomLevel')); langSel.setCurrentIndex(this.langs.indexOf(getLocale())); } diff --git a/src/views/SettingsView/pages/MyAccountPage.ts b/src/views/SettingsView/pages/MyAccountPage.ts index 489ae9a..f776355 100644 --- a/src/views/SettingsView/pages/MyAccountPage.ts +++ b/src/views/SettingsView/pages/MyAccountPage.ts @@ -1,6 +1,6 @@ import { Direction, QBoxLayout, QLabel, QPixmap, QWidget } from '@nodegui/nodegui'; import { Client, Constants } from 'discord.js'; -import { __ } from 'i18n'; +import { __ } from '../../../utilities/StringProvider'; import { app, MAX_QSIZE } from '../../..'; import { DColorButton } from '../../../components/DColorButton/DColorButton'; import { DLabel } from '../../../components/DLabel/DLabel'; @@ -105,7 +105,7 @@ export class MyAccountPage extends Page { twoFAHelper.setText( __('TWO_FA_UNAVAILABLE', { tfaURL: 'https://discord.com/channels/@me/settings', - }), + }) ); layout.addWidget(header); diff --git a/src/views/SettingsView/pages/Page.ts b/src/views/SettingsView/pages/Page.ts index 2dc08f3..4fa8c76 100644 --- a/src/views/SettingsView/pages/Page.ts +++ b/src/views/SettingsView/pages/Page.ts @@ -1,5 +1,5 @@ import { Direction, QBoxLayout, QLabel, QWidget, WidgetEventTypes } from '@nodegui/nodegui'; -import { __ } from 'i18n'; +import { __ } from '../../../utilities/StringProvider'; import { app, MAX_QSIZE } from '../../..'; import { createLogger } from '../../../utilities/Console'; import { IConfig } from '../../../utilities/IConfig'; diff --git a/src/views/SettingsView/pages/SystemPage.ts b/src/views/SettingsView/pages/SystemPage.ts index 83867a0..e53ab75 100644 --- a/src/views/SettingsView/pages/SystemPage.ts +++ b/src/views/SettingsView/pages/SystemPage.ts @@ -1,8 +1,8 @@ import { QLabel } from '@nodegui/nodegui'; import { promises } from 'fs'; -import { __ } from 'i18n'; import { notify } from 'node-notifier'; import { basename } from 'path'; +import { __ } from '../../../utilities/StringProvider'; import { app } from '../../..'; import { DColorButton } from '../../../components/DColorButton/DColorButton'; import { createLogger } from '../../../utilities/Console'; diff --git a/src/views/SettingsView/pages/VoicePage.ts b/src/views/SettingsView/pages/VoicePage.ts index 47feda4..5ffec46 100644 --- a/src/views/SettingsView/pages/VoicePage.ts +++ b/src/views/SettingsView/pages/VoicePage.ts @@ -8,7 +8,6 @@ import { QSlider, } from '@nodegui/nodegui'; import { ChildProcessWithoutNullStreams, execSync } from 'child_process'; -import { __ } from 'i18n'; import { basename } from 'path'; import { app, MAX_QSIZE } from '../../..'; import { DComboBox } from '../../../components/DComboBox/DComboBox'; @@ -17,6 +16,8 @@ import { NoiseReductor } from '../../../components/VoicePanel/NoiseReductor'; import { ConfigManager } from '../../../utilities/ConfigManager'; import { createLogger } from '../../../utilities/Console'; import { Events } from '../../../utilities/Events'; +import { PhraseID } from '../../../utilities/PhraseID'; +import { __ } from '../../../utilities/StringProvider'; import { createRecordStream } from '../../../utilities/VoiceStreams'; import { Divider } from '../Divider'; import { Page } from './Page'; @@ -52,7 +53,7 @@ export class VoicePage extends Page { app.on(Events.CONFIG_UPDATE, this.loadConfig.bind(this)); } - private createHeader(id: string) { + private createHeader(id: PhraseID) { const label = new QLabel(this); label.setObjectName('Header3'); @@ -74,9 +75,9 @@ export class VoicePage extends Page { () => {}, (loudness) => { this.sensCheck.setValue( - loudness * (app.config.get('voiceSettings').inputVolume ?? 100) * 0.1, + loudness * (app.config.get('voiceSettings').inputVolume ?? 100) * 0.1 ); - }, + } ); const tester = this.recordTester.stdout.pipe(noiseReductor); diff --git a/src/windows/OverlayWindow/OverlayWindow.ts b/src/windows/OverlayWindow/OverlayWindow.ts index 6f30d86..06bde4d 100644 --- a/src/windows/OverlayWindow/OverlayWindow.ts +++ b/src/windows/OverlayWindow/OverlayWindow.ts @@ -32,7 +32,7 @@ export class OverlayWindow extends QWidget { WindowType.NoDropShadowWindowHint | WindowType.WindowSystemMenuHint | WindowType.WindowMinimizeButtonHint, - true, + true ); this.initWindow(); diff --git a/webpack.config.js b/webpack.config.js index efa1649..6b14130 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -122,7 +122,7 @@ module.exports = (_env, argv) => { new CopyPlugin({ patterns: [ { from: 'assets', to: 'assets' }, - { from: 'locales', to: 'locales' }, + { from: 'src/locales', to: 'locales' }, { from: 'node_modules/opusscript/build/opusscript_native_wasm.wasm' }, { from: 'node_modules/ffmpeg-static/ffmpeg', noErrorOnMissing: true }, { from: 'node_modules/ffmpeg-static/ffmpeg.exe', noErrorOnMissing: true } diff --git a/worker/index.ts b/worker/index.ts index 47e11c0..7457f4c 100644 --- a/worker/index.ts +++ b/worker/index.ts @@ -1,3 +1,4 @@ +/* eslint-disable no-console */ import envPaths from 'env-paths'; import { existsSync, promises } from 'fs'; import { dirname, join } from 'path';