Skip to content

Commit cc27cb3

Browse files
committed
refactor: convert to arrow function
1 parent b8c57df commit cc27cb3

File tree

8 files changed

+87
-87
lines changed

8 files changed

+87
-87
lines changed

src/main/Application.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { EventEmitter } from 'node:events'
2-
import { app, shell, dialog, ipcMain } from 'electron'
3-
import is from 'electron-is'
42
import { readFile, unlink } from 'node:fs'
53
import { extname, basename } from 'node:path'
4+
import { app, shell, dialog, ipcMain } from 'electron'
5+
import is from 'electron-is'
66
import { isEmpty, isEqual } from 'lodash'
77

88
import {
@@ -695,7 +695,7 @@ export default class Application extends EventEmitter {
695695

696696
const sessionPath = this.context.get('session-path')
697697
setTimeout(() => {
698-
unlink(sessionPath, function (err) {
698+
unlink(sessionPath, (err) => {
699699
logger.info('[Motrix] Removed the download seesion file:', err)
700700
})
701701

src/main/core/Engine.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ export default class Engine {
4343
const pid = this.instance.pid.toString()
4444
this.writePidFile(pidPath, pid)
4545

46-
this.instance.once('close', function () {
46+
this.instance.once('close', () => {
4747
try {
48-
unlink(pidPath, function (err) {
48+
unlink(pidPath, (err) => {
4949
if (err) {
5050
logger.warn(`[Motrix] Unlink engine process pid file failed: ${err}`)
5151
}
@@ -56,11 +56,11 @@ export default class Engine {
5656
})
5757

5858
if (is.dev()) {
59-
this.instance.stdout.on('data', function (data) {
59+
this.instance.stdout.on('data', (data) => {
6060
logger.log('[Motrix] engine stdout===>', data.toString())
6161
})
6262

63-
this.instance.stderr.on('data', function (data) {
63+
this.instance.stderr.on('data', (data) => {
6464
logger.log('[Motrix] engine stderr===>', data.toString())
6565
})
6666
}

src/main/ui/Locale.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,20 @@ const localeManager = new LocaleManager({
55
resources
66
})
77

8-
export function getLocaleManager () {
8+
export const getLocaleManager = () => {
99
return localeManager
1010
}
1111

12-
export function setupLocaleManager (locale) {
12+
export const setupLocaleManager = (locale) => {
1313
localeManager.changeLanguageByLocale(locale)
1414

1515
return localeManager
1616
}
1717

18-
export function getI18n () {
18+
export const getI18n = () => {
1919
return localeManager.getI18n()
2020
}
2121

22-
export function getI18nTranslator () {
22+
export const getI18nTranslator = () => {
2323
return localeManager.getI18n().t
2424
}

src/main/utils/index.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@ export const getDhtPath = (protocol) => {
4343
return resolve(getUserDataPath(), `./${name}`)
4444
}
4545

46-
export function getEngineBin (platform) {
46+
export const getEngineBin = (platform) => {
4747
const result = engineBinMap[platform] || ''
4848
return result
4949
}
5050

51-
export function getEngineArch (platform, arch) {
51+
export const getEngineArch = (platform, arch) => {
5252
if (!['darwin', 'win32', 'linux'].includes(platform)) {
5353
return ''
5454
}
@@ -84,7 +84,7 @@ export const getAria2ConfPath = (platform, arch) => {
8484
return resolve(base, './aria2.conf')
8585
}
8686

87-
export function transformConfig (config) {
87+
export const transformConfig = (config) => {
8888
const result = []
8989
for (const [k, v] of Object.entries(config)) {
9090
if (v !== '') {
@@ -94,7 +94,7 @@ export function transformConfig (config) {
9494
return result
9595
}
9696

97-
export function isRunningInDmg () {
97+
export const isRunningInDmg = () => {
9898
if (!is.macOS() || is.dev()) {
9999
return false
100100
}
@@ -103,7 +103,7 @@ export function isRunningInDmg () {
103103
return result
104104
}
105105

106-
export function moveAppToApplicationsFolder (errorMsg = '') {
106+
export const moveAppToApplicationsFolder = (errorMsg = '') => {
107107
return new Promise((resolve, reject) => {
108108
try {
109109
const result = app.moveToApplicationsFolder()
@@ -118,7 +118,7 @@ export function moveAppToApplicationsFolder (errorMsg = '') {
118118
})
119119
}
120120

121-
export function splitArgv (argv) {
121+
export const splitArgv = (argv) => {
122122
const args = []
123123
const extra = {}
124124
for (const arg of argv) {
@@ -134,7 +134,7 @@ export function splitArgv (argv) {
134134
return { args, extra }
135135
}
136136

137-
export function parseArgvAsUrl (argv) {
137+
export const parseArgvAsUrl = (argv) => {
138138
const arg = argv[1]
139139
if (!arg) {
140140
return
@@ -145,7 +145,7 @@ export function parseArgvAsUrl (argv) {
145145
}
146146
}
147147

148-
export function checkIsSupportedSchema (url = '') {
148+
export const checkIsSupportedSchema = (url = '') => {
149149
const str = url.toLowerCase()
150150
if (
151151
str.startsWith('ftp:') ||
@@ -162,11 +162,11 @@ export function checkIsSupportedSchema (url = '') {
162162
}
163163
}
164164

165-
export function isDirectory (path) {
165+
export const isDirectory = (path) => {
166166
return existsSync(path) && lstatSync(path).isDirectory()
167167
}
168168

169-
export function parseArgvAsFile (argv) {
169+
export const parseArgvAsFile = (argv) => {
170170
let arg = argv[1]
171171
if (!arg || isDirectory(arg)) {
172172
return
@@ -197,7 +197,7 @@ export const convertArrayBufferToBuffer = (arrayBuffer) => {
197197
return buffer
198198
}
199199

200-
export function showItemInFolder (fullPath) {
200+
export const showItemInFolder = (fullPath) => {
201201
if (!fullPath) {
202202
return
203203
}

src/main/utils/menu.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { parse } from 'querystring'
22

3-
export function concat (template, submenu, submenuToAdd) {
3+
export const concat = (template, submenu, submenuToAdd) => {
44
submenuToAdd.forEach(sub => {
55
let relativeItem = null
66
if (sub.position) {
@@ -37,7 +37,7 @@ export function concat (template, submenu, submenuToAdd) {
3737
})
3838
}
3939

40-
export function merge (template, item) {
40+
export const merge = (template, item) => {
4141
if (item.id) {
4242
const matched = findById(template, item.id)
4343
if (matched) {
@@ -73,7 +73,7 @@ function findById (template, id) {
7373
return null
7474
}
7575

76-
export function translateTemplate (template, keystrokesByCommand, i18n) {
76+
export const translateTemplate = (template, keystrokesByCommand, i18n) => {
7777
for (const i in template) {
7878
const item = template[i]
7979
if (item.command) {
@@ -101,7 +101,7 @@ export function translateTemplate (template, keystrokesByCommand, i18n) {
101101
return template
102102
}
103103

104-
export function handleCommand (item) {
104+
export const handleCommand = (item) => {
105105
handleCommandBefore(item)
106106

107107
const args = item['command-arg']
@@ -158,7 +158,7 @@ function acceleratorForCommand (command, keystrokesByCommand) {
158158
return null
159159
}
160160

161-
export function flattenMenuItems (menu) {
161+
export const flattenMenuItems = (menu) => {
162162
const flattenItems = {}
163163
menu.items.forEach(item => {
164164
if (item.id) {
@@ -171,7 +171,7 @@ export function flattenMenuItems (menu) {
171171
return flattenItems
172172
}
173173

174-
export function updateStates (itemsById, visibleStates, enabledStates, checkedStates) {
174+
export const updateStates = (itemsById, visibleStates, enabledStates, checkedStates) => {
175175
if (visibleStates) {
176176
for (const command in visibleStates) {
177177
const item = itemsById[command]

src/renderer/utils/native.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { shell, nativeTheme } from '@electron/remote'
21
import { access, constants } from 'node:fs'
32
import { resolve } from 'node:path'
3+
import { shell, nativeTheme } from '@electron/remote'
44
import { Message } from 'element-ui'
55

66
import {
@@ -9,7 +9,7 @@ import {
99
} from '@shared/utils'
1010
import { APP_THEME, TASK_STATUS } from '@shared/constants'
1111

12-
export function showItemInFolder (fullPath, { errorMsg }) {
12+
export const showItemInFolder = (fullPath, { errorMsg }) => {
1313
if (!fullPath) {
1414
return
1515
}
@@ -35,7 +35,7 @@ export const openItem = async (fullPath) => {
3535
return result
3636
}
3737

38-
export function getTaskFullPath (task) {
38+
export const getTaskFullPath = (task) => {
3939
const { dir, files, bittorrent } = task
4040
let result = resolve(dir)
4141

@@ -109,7 +109,7 @@ export const moveTaskFilesToTrash = (task) => {
109109
return deleteResult1 && deleteResult2
110110
}
111111

112-
export function getSystemTheme () {
112+
export const getSystemTheme = () => {
113113
return nativeTheme.shouldUseDarkColors ? APP_THEME.DARK : APP_THEME.LIGHT
114114
}
115115

src/shared/locales/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ export const availableLanguages = [
112112
}
113113
]
114114

115-
function checkLngIsAvailable (locale) {
115+
const checkLngIsAvailable = (locale) => {
116116
return availableLanguages.some(lng => lng.value === locale)
117117
}
118118

@@ -133,7 +133,7 @@ function checkLngIsAvailable (locale) {
133133
* pt, pt-BR, pt-PT
134134
* zh, zh-CN, zh-HK, zh-TW
135135
*/
136-
export function getLanguage (locale = 'en-US') {
136+
export const getLanguage = (locale = 'en-US') => {
137137
if (checkLngIsAvailable(locale)) {
138138
return locale
139139
}

0 commit comments

Comments
 (0)