Skip to content

Commit

Permalink
create app version of the program and add autorun
Browse files Browse the repository at this point in the history
  • Loading branch information
cesque committed Aug 7, 2019
1 parent a04fe7a commit 0270d5b
Show file tree
Hide file tree
Showing 15 changed files with 1,550 additions and 28 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,6 @@ typings/
# DynamoDB Local files
.dynamodb/

.DS_Store
.DS_Store

dist/
Binary file added build/app-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
1 change: 1 addition & 0 deletions build/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
help
File renamed without changes.
File renamed without changes.
Empty file removed index.html
Empty file.
46 changes: 34 additions & 12 deletions index.js → main.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ const { createError } = require('micro')
const path = require('path')
const fs = require('fs')
const internalip = require('internal-ip')
const { clipboard, nativeImage, Menu } = require('electron')
const AutoLaunch = require('auto-launch')
const { clipboard, Menu } = require('electron')

const PORT = 4500

Expand All @@ -16,15 +17,15 @@ let files = []
let ip = internalip.v4.sync()

let staticFiles = [
'/static/script.js',
'/static/style.css',
'/build/script.js',
'/build/style.css',
]

function page(contents) {
return `<html>
<head>
<title>drop - local file sharing</title>
<link rel="stylesheet" href="static/style.css">
<link rel="stylesheet" href="./build/style.css">
</head>
<body>
${contents}
Expand All @@ -33,13 +34,17 @@ function page(contents) {
</div>
<div class="credit">by cesque :)</div>
</body>
<script src="static/script.js"></script>
<script src="./build/script.js"></script>
</html>`
}

mb.on('ready', async () => {
console.log('ready')

var autoLauncher = new AutoLaunch({
name: 'Drop',
})

const server = new http.Server(micro(async (req, res) => {
if(req.url == '/') {
if(files.length > 0) {
Expand All @@ -53,12 +58,13 @@ mb.on('ready', async () => {

return page(urls.join(''))
} else {
return page(`<p>${Menu}</p>`)
return page(`<p class=no-files>no files uploaded yet :)</p>`)
}
} else if (staticFiles.includes(req.url)) {
let parts = req.url.split('/')
let last = parts[parts.length - 1]
return fs.readFileSync('./' + last)
return fs.readFileSync(__dirname + '/build/' + last)
} else {
let file = files.find(x => ('/' + x.filename) == req.url)

Expand All @@ -70,8 +76,11 @@ mb.on('ready', async () => {

server.listen(PORT)

mb.tray.removeAllListeners('click')
mb.tray.setTitle('drop')
mb.tray.setImage('./icon.png')
mb.tray.setImage(__dirname + '/build/icon.png')

let isAutoLaunch = await autoLauncher.isEnabled()

let contextMenu = Menu.buildFromTemplate([
{
Expand All @@ -80,6 +89,21 @@ mb.on('ready', async () => {
clipboard.writeText('http://' + ip + ':' + PORT)
},
},
{
label: 'Launch at login',
type: 'checkbox',
checked: isAutoLaunch,
click: (menuItem, browserWindow, event) => {
if(menuItem.checked) {
autoLauncher.enable()
} else {
autoLauncher.disable()
}
}
},
{
type: 'separator'
},
{
label: 'Quit',
role: 'quit',
Expand All @@ -88,8 +112,6 @@ mb.on('ready', async () => {

mb.tray.setContextMenu(contextMenu)

mb.tray.removeAllListeners('click')

mb.tray.on('drop-files', (event, dropped) => {

for(let file of dropped) {
Expand All @@ -100,7 +122,7 @@ mb.on('ready', async () => {
})
}

mb.tray.setImage('./icon-full.png')
mb.tray.setImage(__dirname + '/build/icon-full.png')

clipboard.writeText('http://' + ip + ':' + PORT)
})
Expand All @@ -117,8 +139,8 @@ mb.on('ready', async () => {
files = files.filter(x => x.timeout > 0)

if(files.length == 0) {
mb.tray.setImage('./icon.png')
mb.tray.setImage(__dirname + '/build/icon.png')
}
}, 1000)

})
})
Loading

0 comments on commit 0270d5b

Please sign in to comment.