Skip to content

Commit

Permalink
Merge pull request #5 from HughIsaacs2/experimental
Browse files Browse the repository at this point in the history
Experimental
  • Loading branch information
HughIsaacs2 authored Dec 12, 2017
2 parents 0d17c48 + 657eed8 commit 6708395
Show file tree
Hide file tree
Showing 7 changed files with 210 additions and 144 deletions.
2 changes: 1 addition & 1 deletion chrome extension/dat_error.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ var onx = document.createElement('br');
document.body.appendChild(onx);

var datLink = document.createElement('a');
datLink.href = "dat://"+datHash+"/"+datPath;
datLink.href = "dat://"+datHash+datPath;
datLink.innerText = "Dat link";
datLink.className = "button";
document.body.appendChild(datLink);
4 changes: 2 additions & 2 deletions chrome extension/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"short_name": "DatPart",
"description": "DatPart extension.",
"manifest_version": 2,
"version": "0.0.5",
"version_name": "0.0.5 alpha",
"version": "0.0.6",
"version_name": "0.0.6 alpha",
"permissions": ["tabs", "webRequestBlocking", "webRequest", "webNavigation", "proxy", "*://*.dat_site/*", "*://*.torrent_site/*", "storage", "unlimitedStorage", "nativeMessaging"],
"optional_permissions": [ "tabs", "notifications", "background", "*://*/", "<all_urls>" ],
"externally_connectable": { "ids": [ "pgdnnmekclkafnpfofleebhhnmolopgl" ] },
Expand Down
198 changes: 83 additions & 115 deletions electron app/resources/datpart/launch.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
var dev = true;

if (typeof process === 'object') {
if (typeof process.versions === 'object') {
if (typeof process.versions['electron'] !== 'undefined') {
var dev = false;

const {app, BrowserWindow, Menu, Tray} = require('electron')
const path = require('path')
const url = require('url')
const fs = require('fs');
const fs = require('fs')

// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected.
Expand All @@ -19,77 +15,46 @@ var appName = app.getName();
var appIcon = __dirname+'/logo_128.png';
var appPath = app.getAppPath();

if (fs.existsSync(appPath + "/dats/")) {
fs.mkdir(appPath + "/dats/");
}

app.on('ready', () => {
tray = new Tray(appIcon)
const contextMenu = Menu.buildFromTemplate([
{label: 'Show', click: function() {win.show();}},
{label: 'Quit', click: function() {app.isQuiting = true; app.quit();}}
])
tray.setToolTip(appName + " v" + versionNumber)
tray.setContextMenu(contextMenu)
tray.on('click', () => {
win.show()
})

if(app.isDefaultProtocolClient(appName)) {

} else {
app.setAsDefaultProtocolClient(appName)
}

/*
if(app.isDefaultProtocolClient('dat')) {
} else {
app.setAsDefaultProtocolClient('dat')
if (!fs.existsSync(__dirname + '/../../dats/')) {
fs.mkdirSync(__dirname + '/../../dats/');
}
*/

process.argv.forEach(function (val, index, array) {
console.log(index + ': ' + val);
});

})

const isSecondInstance = app.makeSingleInstance((commandLine, workingDirectory) => {
// Someone tried to run a second instance, we should focus our window.
if (win) {
if (win.isMinimized()) win.restore()
win.show()
win.focus()
}
})

if (isSecondInstance) {
app.quit()
}

function createWindow () {
// Create the browser window.
win = new BrowserWindow(
{
win = new BrowserWindow({
width: 800,
height: 600,
icon: __dirname+'/logo_128.png',
icon: appIcon,
backgroundColor: '#424242',
show: false
})

win.setMenu(null)

// and load the index.html of the app.
win.loadURL('file://' + __dirname + '/server_app.html')

const devTopMenu = Menu.buildFromTemplate([
{label: appName + " v" + versionNumber + " dev mode"},
{label: 'Quit for real', click: function() {app.isQuiting = true; app.quit();}}
])

// Open the DevTools if dev is true.
if(dev == true) {
win.webContents.openDevTools({mode:'detach'})
win.setMenu(devTopMenu)
win.setThumbnailToolTip(appName + " v" + versionNumber + " dev mode")
win.setTitle(appName + " v" + versionNumber + " dev mode")
win.webContents.openDevTools({mode:'detach'})
} else if (dev != true) {
win.setMenu(null)
win.setThumbnailToolTip(appName + " v" + versionNumber)
win.setTitle(appName + " v" + versionNumber)
}

win.on('show', () => {
if(dev == true) {
win.webContents.openDevTools({mode:'detach'})
}
})

// and load the index.html of the app.
win.loadURL('file://' + __dirname + '/server_app.html')

win.on('close', function (event) {
if( !app.isQuiting){
event.preventDefault()
Expand All @@ -105,65 +70,68 @@ function createWindow () {
// when you should delete the corresponding element.
win = null
})

}

// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.on('ready', createWindow)
const isSecondInstance = app.makeSingleInstance((commandLine, workingDirectory) => {
// Someone tried to run a second instance, we should focus our window.
if (win) {
if (win.isMinimized()) win.restore()
win.show()
win.focus()
}
})

if (isSecondInstance) {
app.quit()
}

app.on('ready', () => {
if (!fs.existsSync(__dirname + '/../../dats/')) {
fs.mkdirSync(__dirname + '/../../dats/');
}

tray = new Tray(appIcon)

const contextMenu = Menu.buildFromTemplate([
{label: 'Show', click: function() {win.show();}},
{label: 'Quit', click: function() {app.isQuiting = true; app.quit();}}
])

const devContextMenu = Menu.buildFromTemplate([
{label: 'Show', click: function() {win.show();}},
{label: 'Quit', click: function() {app.isQuiting = true; app.quit();}},
{label: appName + " v" + versionNumber + " dev mode"}
])

if(dev == true) {
tray.setContextMenu(devContextMenu)
tray.setToolTip(appName + " v" + versionNumber + " dev mode")
} else if (dev != true) {
tray.setContextMenu(contextMenu)
tray.setToolTip(appName + " v" + versionNumber)
}

tray.on('click', () => {
win.show()
})

if(app.isDefaultProtocolClient(appName)) {

} else {
app.setAsDefaultProtocolClient(appName)
}

//var openingNotification = new Notification({title: "ggggggggo", body: "lol"})
//openingNotification.show()

createWindow();
})

app.on('activate', () => {
// On macOS it's common to re-create a window in the app when the
// dock icon is clicked and there are no other windows open.
if (win === null) {
createWindow()
}
})

// In this file you can include the rest of your app's specific main process
// code. You can also put them in separate files and require them here.

}}} else if (window && window.chrome && chrome.runtime && chrome.runtime.id) {

chrome.app.runtime.onLaunched.addListener(function() {
chrome.app.window.create('/server_app.html?platform=chromeApp', {
'innerBounds': {
'width': 800,
'height': 600
},
'minWidth': 800,
'minHeight': 400,
'frame': {
'type': 'chrome',
'color': '#424242',
'activeColor': '#ffffff',
'inactiveColor': '#424242'
},
id: 'other_web_server'
});
});

chrome.runtime.onMessageExternal.addListener(function() {
if(chrome.app.window.get('other_web_server')){
//Do Nothing
} else {
chrome.app.window.create('/server_app.html?platform=chromeApp', {
'innerBounds': {
'width': 800,
'height': 600
},
'minWidth': 800,
'minHeight': 400,
'state': 'minimized',
'frame': {
'type': 'chrome',
'color': '#424242',
'activeColor': '#ffffff',
'inactiveColor': '#424242'
},
id: 'other_web_server'
});
}
});
}
})
2 changes: 1 addition & 1 deletion electron app/resources/datpart/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"type": "git",
"url": "https://github.com/HughIsaacs2/DatPart.git"
},
"version": "0.0.5",
"version": "0.0.6",
"author": "Hugh Isaacs II <[email protected]>",
"license": "MIT",
"main": "launch.js",
Expand Down
Loading

0 comments on commit 6708395

Please sign in to comment.