Skip to content

Commit 10fdefd

Browse files
committed
improved JSDoc and fixed ts-ignore highlighted earlier
1 parent 6b692ca commit 10fdefd

File tree

8 files changed

+65
-53
lines changed

8 files changed

+65
-53
lines changed

src/auto-launch.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ module.exports = async function () {
9595
logger.error(`[launch on startup] ${err.toString()}`)
9696

9797
if (feedback) {
98+
// @ts-ignore
9899
recoverableErrorDialog(err, {
99100
title: i18n.t('launchAtLoginFailed.title'),
100101
message: i18n.t('launchAtLoginFailed.message')

src/dialogs/dialog.js

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,23 @@ const i18n = require('i18next')
33
const { IS_MAC } = require('../common/consts')
44
const dock = require('../utils/dock')
55

6+
/**
7+
* @typedef {object} MessageBoxOptions
8+
* @property {string} title
9+
* @property {string} message
10+
* @property {'none'|'info'|'error'|'question'|'warning'} [type='info']
11+
* @property {boolean} [showDock=true]
12+
* @property {string[]} [buttons]
13+
* @property {boolean} [noLink]
14+
*/
15+
16+
/**
17+
* Show a message box with the specified options.
18+
*
19+
* @param {MessageBoxOptions} options
20+
* @returns {number}
21+
*/
22+
623
// NOTE: always send the buttons in the order [OK, Cancel, ...Actions].
724
// See this post for more interesting information about the topic:
825
// https://medium.muz.li/ok-key-and-cancel-key-which-one-should-be-set-up-on-the-left-4780e86c16eb
@@ -12,40 +29,23 @@ module.exports = function ({
1229
i18n.t('cancel')
1330
], ...opts
1431
}) {
32+
const isInverse = !IS_MAC
33+
const defaultId = isInverse ? buttons.length - 1 : 0
34+
const cancelId = isInverse ? buttons.length - 2 : 1
35+
1536
const options = {
1637
type,
17-
buttons,
38+
buttons: isInverse ? buttons.reverse() : buttons,
1839
noLink: true,
40+
title: IS_MAC ? undefined : title,
41+
message: IS_MAC ? title : message,
42+
detail: IS_MAC ? message : undefined,
43+
default: buttons.length > 1 ? defaultId : undefined,
44+
cancelId: buttons.length > 1 ? cancelId : undefined,
1945
...opts
2046
}
2147

22-
if (IS_MAC) {
23-
// @ts-ignore
24-
options.message = title
25-
// @ts-ignore
26-
options.detail = message
27-
} else {
28-
// @ts-ignore
29-
options.title = title
30-
// @ts-ignore
31-
options.message = message
32-
}
33-
34-
const isInverse = !IS_MAC
35-
36-
if (isInverse) {
37-
options.buttons.reverse()
38-
}
39-
40-
if (buttons.length > 1) {
41-
// @ts-ignore
42-
options.defaultId = isInverse ? buttons.length - 1 : 0
43-
// @ts-ignore
44-
options.cancelId = isInverse ? buttons.length - 2 : 1
45-
}
46-
4748
if (showDock) { dock.show() }
48-
// @ts-ignore
4949
const selected = dialog.showMessageBoxSync(options)
5050
if (showDock) { dock.hide() }
5151

src/dialogs/errors.js

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,16 @@ function criticalErrorDialog (e) {
9999
// Shows a recoverable error dialog with the default title and message.
100100
// Passing an options object alongside the error can be used to override
101101
// the title and message.
102+
/**
103+
* Displays a recoverable error dialog with the specified title and message.
104+
*
105+
* @param {any} e - The error object.
106+
* @param {{title?: string; message?: string; type?: string;}} options - The options for the error dialog.
107+
*/
102108
function recoverableErrorDialog (e, options) {
103109
const cfg = {
104-
title: i18n.t('recoverableErrorDialog.title'),
105-
message: i18n.t('recoverableErrorDialog.message'),
110+
title: options.title ? options.title : i18n.t('recoverableErrorDialog.title'),
111+
message: options.message ? options.message : i18n.t('recoverableErrorDialog.message'),
106112
type: 'error',
107113
buttons: [
108114
i18n.t('close'),
@@ -111,16 +117,7 @@ function recoverableErrorDialog (e, options) {
111117
]
112118
}
113119

114-
if (options) {
115-
if (options.title) {
116-
cfg.title = options.title
117-
}
118-
119-
if (options.message) {
120-
cfg.message = options.message
121-
}
122-
}
123-
120+
// @ts-ignore
124121
const option = dialog(cfg)
125122

126123
if (option === 1) {

src/i18n.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ module.exports = async function () {
2929
loadPath: join(__dirname, '../assets/locales/{{lng}}.json')
3030
}
3131
},
32-
(err, t) => {
32+
(err) => {
3333
if (err) {
3434
/**
3535
* even if an error occurs here, i18n still may work properly.

src/protocol-handlers.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,19 @@ const { app, shell } = require('electron')
22
const toUri = require('multiaddr-to-uri')
33
const getCtx = require('./context')
44

5+
/**
6+
* @param {string} protocol
7+
* @param {string} part
8+
* @param {string} base
9+
*/
510
function openLink (protocol, part, base) {
611
shell.openExternal(`${base}/${protocol}/${part}`)
712
return true
813
}
914

15+
/**
16+
* @param {{ toString: () => string | string[]; encapsulate: (arg0: string) => any; }} addr
17+
*/
1018
function parseAddr (addr) {
1119
return toUri(addr.toString().includes('/http') ? addr : addr.encapsulate('/http'))
1220
}

src/run-gc.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ module.exports = function runGarbageCollector () {
6363
} catch (err) {
6464
// @ts-ignore
6565
logger.error(`[run gc] ${err.stack}`)
66+
// @ts-ignore
6667
recoverableErrorDialog(err, {
6768
title: i18n.t('runGarbageCollectorErrored.title'),
6869
message: i18n.t('runGarbageCollectorErrored.message')

src/tray.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ const runGarbageCollector = require('./run-gc')
1818
const { SHORTCUT: SCREENSHOT_SHORTCUT, takeScreenshot } = require('./take-screenshot')
1919
const createToggler = require('./utils/create-toggler')
2020

21+
/**
22+
* @param {string} key
23+
* @param {string} label
24+
*/
2125
function buildCheckbox (key, label) {
2226
return {
2327
id: key,

src/webui/index.js

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// @ts-check
21
const { join } = require('path')
32
const { performance } = require('perf_hooks')
43
const { URL } = require('url')
@@ -22,6 +21,11 @@ const openExternal = require('./open-external')
2221

2322
serve({ scheme: 'webui', directory: join(__dirname, '../../assets/webui') })
2423

24+
/**
25+
* @typedef {object} Ipfsd
26+
* @property {string} apiAddr
27+
*/
28+
2529
/**
2630
*
2731
* @returns {BrowserWindow}
@@ -49,8 +53,7 @@ const createWindow = () => {
4953
}
5054
})
5155

52-
// @ts-ignore
53-
window.webContents.once('did-start-loading', (event) => {
56+
window.webContents.once('did-start-loading', () => {
5457
const msg = '[web ui] loading'
5558
const webContentLoad = logger.start(msg, { withAnalytics: analyticsKeys.WEB_UI_READY })
5659
window.webContents.once('did-finish-load', () => {
@@ -61,8 +64,8 @@ const createWindow = () => {
6164
webContentLoad.fail(`${msg}: ${errorDescription}, code: ${errorCode}`)
6265
})
6366
})
64-
// @ts-ignore
65-
window.webContents.once('dom-ready', async (event) => {
67+
68+
window.webContents.once('dom-ready', async () => {
6669
const endTime = performance.now()
6770
try {
6871
const dur = getSecondsSinceAppStart(endTime)
@@ -73,8 +76,7 @@ const createWindow = () => {
7376
dur
7477
})
7578
} catch (err) {
76-
// @ts-ignore
77-
logger.error(err)
79+
logger.error(String(err))
7880
}
7981
})
8082

@@ -155,7 +157,7 @@ module.exports = async function () {
155157
url.hash = '/blank'
156158
url.searchParams.set('deviceId', await ctx.getProp('countlyDeviceId'))
157159

158-
ctx.setProp('launchWebUI', async (path, { focus = true, forceRefresh = false } = {}) => {
160+
ctx.setProp('launchWebUI', async (/** @type {string} */ path, { focus = true, forceRefresh = false } = {}) => {
159161
if (window.isDestroyed()) {
160162
logger.error(`[web ui] window is destroyed, not launching web ui with ${path}`)
161163
return
@@ -184,12 +186,12 @@ module.exports = async function () {
184186
const getIpfsd = ctx.getFn('getIpfsd')
185187
let ipfsdStatus = null
186188
ipcMain.on(ipcMainEvents.IPFSD, async (status) => {
189+
/** @type {Ipfsd} */
190+
// @ts-ignore
187191
const ipfsd = await getIpfsd(true)
188192
ipfsdStatus = status
189193

190-
// @ts-ignore
191194
if (ipfsd && ipfsd.apiAddr !== apiAddress) {
192-
// @ts-ignore
193195
apiAddress = ipfsd.apiAddr
194196
url.searchParams.set('api', apiAddress.toString())
195197
updateLanguage()
@@ -200,7 +202,7 @@ module.exports = async function () {
200202
// Set user agent
201203
session.defaultSession.webRequest.onBeforeSendHeaders((details, callback) => {
202204
details.requestHeaders['User-Agent'] = `ipfs-desktop/${VERSION} (Electron ${ELECTRON_VERSION})`
203-
callback({ cancel: false, requestHeaders: details.requestHeaders }) // eslint-disable-line
205+
callback({ cancel: false, requestHeaders: details.requestHeaders })
204206
})
205207

206208
const launchWebUI = ctx.getFn('launchWebUI')
@@ -230,8 +232,7 @@ module.exports = async function () {
230232
splashScreen.destroy()
231233
} catch (err) {
232234
logger.error('[web ui] failed to hide splash screen')
233-
// @ts-ignore
234-
logger.error(err)
235+
logger.error(String(err))
235236
}
236237
}
237238

0 commit comments

Comments
 (0)