Skip to content
This repository was archived by the owner on May 12, 2021. It is now read-only.

Commit 33bda27

Browse files
authored
Merge pull request #1153 from ssbc/remove-unused
Refactor to remove unused code
2 parents 33f96c4 + a9ac053 commit 33bda27

File tree

156 files changed

+1354
-1375
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

156 files changed

+1354
-1375
lines changed

index.js

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,21 @@ process.on('uncaughtException', function (err) {
33
process.exit()
44
})
55

6-
var electron = require('electron')
7-
var openWindow = require('./lib/window')
6+
const electron = require('electron')
7+
const openWindow = require('./lib/window')
88

9-
var Path = require('path')
10-
var defaultMenu = require('electron-default-menu')
11-
var WindowState = require('electron-window-state')
12-
var Menu = electron.Menu
13-
var extend = require('xtend')
14-
var ssbKeys = require('ssb-keys')
9+
const Path = require('path')
10+
const defaultMenu = require('electron-default-menu')
11+
const WindowState = require('electron-window-state')
12+
const Menu = electron.Menu
13+
const extend = require('xtend')
14+
const ssbKeys = require('ssb-keys')
1515

16-
var windows = {
16+
const windows = {
1717
dialogs: new Set()
1818
}
19-
var ssbConfig = null
20-
var quitting = false
19+
let ssbConfig = null
20+
let quitting = false
2121

2222
/**
2323
* It's not possible to run two instances of patchwork as it would create two
@@ -31,7 +31,7 @@ function quitIfAlreadyRunning () {
3131
console.log('Please close the existing instance before starting a new one.')
3232
return electron.app.quit()
3333
}
34-
electron.app.on('second-instance', (event, commandLine, workingDirectory) => {
34+
electron.app.on('second-instance', () => {
3535
// Someone tried to run a second instance, we should focus our window.
3636
if (windows.main) {
3737
if (windows.main.isMinimized()) windows.main.restore()
@@ -40,7 +40,7 @@ function quitIfAlreadyRunning () {
4040
})
4141
}
4242

43-
var config = {
43+
const config = {
4444
server: !(process.argv.includes('-g') || process.argv.includes('--use-global-ssb'))
4545
}
4646
// a flag so we don't start git-ssb-web if a custom path is passed in
@@ -54,8 +54,8 @@ electron.app.on('ready', () => {
5454
setupContext(process.env.ssb_appname || 'ssb', {
5555
server: !(process.argv.includes('-g') || process.argv.includes('--use-global-ssb'))
5656
}, () => {
57-
var browserWindow = openMainWindow()
58-
var menu = defaultMenu(electron.app, electron.shell)
57+
const browserWindow = openMainWindow()
58+
const menu = defaultMenu(electron.app, electron.shell)
5959

6060
menu.splice(4, 0, {
6161
label: 'Navigation',
@@ -84,7 +84,7 @@ electron.app.on('ready', () => {
8484
]
8585
})
8686

87-
var view = menu.find(x => x.label === 'View')
87+
const view = menu.find(x => x.label === 'View')
8888
view.submenu = [
8989
{ role: 'reload' },
9090
{ role: 'toggledevtools' },
@@ -95,15 +95,15 @@ electron.app.on('ready', () => {
9595
{ type: 'separator' },
9696
{ role: 'togglefullscreen' }
9797
]
98-
var help = menu.find(x => x.label === 'Help')
98+
const help = menu.find(x => x.label === 'Help')
9999
help.submenu = [
100100
{
101101
label: 'Learn More',
102102
click () { require('electron').shell.openExternal('https://scuttlebutt.nz') }
103103
}
104104
]
105105
if (process.platform === 'darwin') {
106-
var win = menu.find(x => x.label === 'Window')
106+
const win = menu.find(x => x.label === 'Window')
107107
win.submenu = [
108108
{ role: 'minimize' },
109109
{ role: 'zoom' },
@@ -116,7 +116,7 @@ electron.app.on('ready', () => {
116116
Menu.setApplicationMenu(Menu.buildFromTemplate(menu))
117117
})
118118

119-
electron.app.on('activate', function (e) {
119+
electron.app.on('activate', function () {
120120
if (windows.main) {
121121
windows.main.show()
122122
}
@@ -126,7 +126,7 @@ electron.app.on('ready', () => {
126126
quitting = true
127127
})
128128

129-
electron.ipcMain.on('open-background-devtools', function (ev, config) {
129+
electron.ipcMain.on('open-background-devtools', function () {
130130
if (windows.background) {
131131
windows.background.webContents.openDevTools({ mode: 'detach' })
132132
}
@@ -135,7 +135,7 @@ electron.app.on('ready', () => {
135135

136136
function openMainWindow () {
137137
if (!windows.main) {
138-
var windowState = WindowState({
138+
const windowState = WindowState({
139139
defaultWidth: 1024,
140140
defaultHeight: 768
141141
})

lib/anchor-hook.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
var watch = require('mutant/watch')
1+
const watch = require('mutant/watch')
22

33
module.exports = AnchorHook
44

@@ -13,7 +13,7 @@ function AnchorHook (name, current, cb) {
1313

1414
// HACK: due to a browser bug, sometimes the window scrolls down below the top bar
1515
// Why not just hack it!!!
16-
var topBar = document.querySelector('.MainWindow > div.top')
16+
const topBar = document.querySelector('.MainWindow > div.top')
1717
if (topBar) {
1818
topBar.scrollIntoViewIfNeeded()
1919
}

lib/catch-links.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,23 @@ module.exports = function (root, cb) {
55
return true
66
}
77

8-
var anchor = null
9-
for (var n = ev.target; n.parentNode; n = n.parentNode) {
8+
let anchor = null
9+
for (let n = ev.target; n.parentNode; n = n.parentNode) {
1010
if (n.nodeName === 'A') {
1111
anchor = n
1212
break
1313
}
1414
}
1515
if (!anchor) return true
1616

17-
var href = anchor.getAttribute('href')
17+
const href = anchor.getAttribute('href')
1818

1919
if (href) {
20-
var isUrl
20+
let isUrl
21+
let url
2122

2223
try {
23-
var url = new URL(href)
24+
url = new URL(href)
2425
isUrl = true
2526
} catch (e) {
2627
isUrl = false

lib/context-menu-and-spellcheck.js

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
var { remote, shell, clipboard, ipcRenderer } = require('electron')
2-
var { SpellCheckHandler, ContextMenuListener, ContextMenuBuilder } = require('electron-spellchecker')
3-
var { MenuItem, Menu } = remote
4-
var ref = require('ssb-ref')
1+
const { remote, shell, clipboard, ipcRenderer } = require('electron')
2+
const { SpellCheckHandler, ContextMenuListener, ContextMenuBuilder } = require('electron-spellchecker')
3+
const { MenuItem, Menu } = remote
4+
const ref = require('ssb-ref')
55

6-
var navigateHandler = null
6+
let navigateHandler = null
77
module.exports = setupContextMenuAndSpellCheck
88

99
function setupContextMenuAndSpellCheck (config, { navigate, get }) {
@@ -14,7 +14,7 @@ function setupContextMenuAndSpellCheck (config, { navigate, get }) {
1414
// Start off as US English, America #1 (lol)
1515
spellCheckHandler.switchLanguage('en-US')
1616

17-
var contextMenuBuilder = new ContextMenuBuilder(spellCheckHandler, null, true, (menu, menuInfo) => {
17+
const contextMenuBuilder = new ContextMenuBuilder(spellCheckHandler, null, true, (menu, menuInfo) => {
1818
const ddg = new MenuItem({
1919
label: 'Search with DuckDuckGo',
2020
click: () => {
@@ -38,25 +38,25 @@ function setupContextMenuAndSpellCheck (config, { navigate, get }) {
3838
})
3939

4040
contextMenuBuilder.buildMenuForLink = function (menuInfo) {
41-
var element = document.elementFromPoint(menuInfo.x, menuInfo.y)
41+
const element = document.elementFromPoint(menuInfo.x, menuInfo.y)
4242

43-
var menu = new Menu()
44-
var isEmailAddress = menuInfo.linkURL.startsWith('mailto:')
45-
var isFile = menuInfo.linkURL.startsWith('file:')
43+
const menu = new Menu()
44+
const isEmailAddress = menuInfo.linkURL.startsWith('mailto:')
45+
const isFile = menuInfo.linkURL.startsWith('file:')
4646

4747
// use the anchor of a link if it directly references an ID
48-
var extractedRef = element && ref.isLink(element.anchor) ? element.anchor : ref.extract(menuInfo.linkURL)
48+
const extractedRef = element && ref.isLink(element.anchor) ? element.anchor : ref.extract(menuInfo.linkURL)
4949

5050
if (!isFile) {
51-
var copyLink = new MenuItem({
51+
const copyLink = new MenuItem({
5252
label: isEmailAddress ? this.stringTable.copyMail() : this.stringTable.copyLinkUrl(),
5353
click: () => {
5454
// Omit the mailto: portion of the link; we just want the address
5555
clipboard.writeText(isEmailAddress ? menuInfo.linkText : menuInfo.linkURL)
5656
}
5757
})
5858

59-
var openLink = new MenuItem({
59+
const openLink = new MenuItem({
6060
label: this.stringTable.openLinkUrl(),
6161
click: () => {
6262
shell.openExternal(menuInfo.linkURL)
@@ -77,7 +77,7 @@ function setupContextMenuAndSpellCheck (config, { navigate, get }) {
7777
}))
7878
this.addSeparator(menu)
7979
}
80-
var copyRef = new MenuItem({
80+
const copyRef = new MenuItem({
8181
label: `Copy Link Ref (${extractedRef.slice(0, 10)}...)`,
8282
click: () => {
8383
// Omit the mailto: portion of the link; we just want the address
@@ -87,7 +87,7 @@ function setupContextMenuAndSpellCheck (config, { navigate, get }) {
8787
menu.append(copyRef)
8888

8989
if (ref.isBlob(extractedRef) && menuInfo.hasImageContents) {
90-
var copyEmbed = new MenuItem({
90+
const copyEmbed = new MenuItem({
9191
label: `Copy Embed Markdown`,
9292
click: () => {
9393
// Omit the mailto: portion of the link; we just want the address
@@ -111,7 +111,7 @@ function setupContextMenuAndSpellCheck (config, { navigate, get }) {
111111

112112
module.exports.menu = new ContextMenuListener((info) => {
113113
contextMenuBuilder.buildMenuForElement(info).then((menu) => {
114-
var element = document.elementFromPoint(info.x, info.y)
114+
let element = document.elementFromPoint(info.x, info.y)
115115
while (element && !element.msg) {
116116
element = element.parentNode
117117
}

lib/depject/about/async/latest-values.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
var nest = require('depnest')
2-
var { onceTrue } = require('mutant')
1+
const nest = require('depnest')
2+
const { onceTrue } = require('mutant')
33

44
exports.needs = nest({
55
'sbot.obs.connection': 'first'

lib/depject/about/html/image.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
var h = require('mutant/h')
2-
var nest = require('depnest')
1+
const h = require('mutant/h')
2+
const nest = require('depnest')
33

44
exports.needs = nest({
55
'about.obs.imageUrl': 'first',

lib/depject/about/html/link.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
var h = require('mutant/h')
2-
var nest = require('depnest')
1+
const h = require('mutant/h')
2+
const nest = require('depnest')
33

44
exports.needs = nest({
55
'about.obs.name': 'first'

lib/depject/about/obs.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
var { computed } = require('mutant')
2-
var nest = require('depnest')
3-
var ref = require('ssb-ref')
4-
var colorHash = new (require('color-hash'))()
5-
var fallbackImageUrl = 'data:image/gif;base64,R0lGODlhAQABAPAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw=='
6-
var MutantPullValue = require('../../mutant-pull-value')
7-
var MutantPullDict = require('../../mutant-pull-dict')
1+
const { computed } = require('mutant')
2+
const nest = require('depnest')
3+
const ref = require('ssb-ref')
4+
const colorHash = new (require('color-hash'))()
5+
const fallbackImageUrl = 'data:image/gif;base64,R0lGODlhAQABAPAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw=='
6+
const MutantPullValue = require('../../mutant-pull-value')
7+
const MutantPullDict = require('../../mutant-pull-dict')
88

99
exports.needs = nest({
1010
'sbot.pull.stream': 'first',
@@ -31,7 +31,7 @@ exports.gives = nest({
3131
})
3232

3333
exports.create = function (api) {
34-
var socialValueCache = {}
34+
const socialValueCache = {}
3535
return nest({
3636
'about.obs': {
3737
// quick helpers, probably should deprecate!
@@ -71,7 +71,7 @@ exports.create = function (api) {
7171
function socialValue (id, key, defaultValue) {
7272
if (!ref.isLink(id)) throw new Error('About requires an ssb ref!')
7373
if (!socialValueCache[id + '/' + key]) {
74-
var obs = socialValueCache[id + '/' + key] = MutantPullValue(() => {
74+
const obs = socialValueCache[id + '/' + key] = MutantPullValue(() => {
7575
return api.sbot.pull.stream((sbot) => sbot.about.socialValueStream({ dest: id, key }))
7676
}, {
7777
onListen: () => { socialValueCache[id + '/' + key] = obs },
@@ -99,9 +99,9 @@ function checkDelete (msg) {
9999
}
100100

101101
function getGroupedValues (lookup) {
102-
var values = {}
103-
for (var author in lookup) {
104-
var value = getValue(lookup[author])
102+
const values = {}
103+
for (const author in lookup) {
104+
const value = getValue(lookup[author])
105105
if (value != null) {
106106
values[value] = values[value] || []
107107
values[value].push(author)

lib/depject/about/sync.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
var nest = require('depnest')
1+
const nest = require('depnest')
22

33
exports.gives = nest('about.sync.shortFeedId')
44

5-
exports.create = function (api) {
5+
exports.create = function () {
66
return nest('about.sync.shortFeedId', function (id) {
77
return id.slice(1, 10)
88
})

lib/depject/about/sync/short-feed-id.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
var nest = require('depnest')
1+
const nest = require('depnest')
22

33
exports.gives = nest('about.sync.shortFeedId')
44

5-
exports.create = function (api) {
5+
exports.create = function () {
66
return nest('about.sync.shortFeedId', function (id) {
77
return `${id.slice(0, 10)}...`
88
})

0 commit comments

Comments
 (0)