Skip to content

Commit 6708395

Browse files
authored
Merge pull request #5 from HughIsaacs2/experimental
Experimental
2 parents 0d17c48 + 657eed8 commit 6708395

File tree

7 files changed

+210
-144
lines changed

7 files changed

+210
-144
lines changed

chrome extension/dat_error.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ var onx = document.createElement('br');
2828
document.body.appendChild(onx);
2929

3030
var datLink = document.createElement('a');
31-
datLink.href = "dat://"+datHash+"/"+datPath;
31+
datLink.href = "dat://"+datHash+datPath;
3232
datLink.innerText = "Dat link";
3333
datLink.className = "button";
3434
document.body.appendChild(datLink);

chrome extension/manifest.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
"short_name": "DatPart",
44
"description": "DatPart extension.",
55
"manifest_version": 2,
6-
"version": "0.0.5",
7-
"version_name": "0.0.5 alpha",
6+
"version": "0.0.6",
7+
"version_name": "0.0.6 alpha",
88
"permissions": ["tabs", "webRequestBlocking", "webRequest", "webNavigation", "proxy", "*://*.dat_site/*", "*://*.torrent_site/*", "storage", "unlimitedStorage", "nativeMessaging"],
99
"optional_permissions": [ "tabs", "notifications", "background", "*://*/", "<all_urls>" ],
1010
"externally_connectable": { "ids": [ "pgdnnmekclkafnpfofleebhhnmolopgl" ] },
+83-115
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
1-
var dev = true;
2-
3-
if (typeof process === 'object') {
4-
if (typeof process.versions === 'object') {
5-
if (typeof process.versions['electron'] !== 'undefined') {
1+
var dev = false;
62

73
const {app, BrowserWindow, Menu, Tray} = require('electron')
84
const path = require('path')
95
const url = require('url')
10-
const fs = require('fs');
6+
const fs = require('fs')
117

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

22-
if (fs.existsSync(appPath + "/dats/")) {
23-
fs.mkdir(appPath + "/dats/");
24-
}
25-
26-
app.on('ready', () => {
27-
tray = new Tray(appIcon)
28-
const contextMenu = Menu.buildFromTemplate([
29-
{label: 'Show', click: function() {win.show();}},
30-
{label: 'Quit', click: function() {app.isQuiting = true; app.quit();}}
31-
])
32-
tray.setToolTip(appName + " v" + versionNumber)
33-
tray.setContextMenu(contextMenu)
34-
tray.on('click', () => {
35-
win.show()
36-
})
37-
38-
if(app.isDefaultProtocolClient(appName)) {
39-
40-
} else {
41-
app.setAsDefaultProtocolClient(appName)
42-
}
43-
44-
/*
45-
if(app.isDefaultProtocolClient('dat')) {
46-
47-
} else {
48-
app.setAsDefaultProtocolClient('dat')
18+
if (!fs.existsSync(__dirname + '/../../dats/')) {
19+
fs.mkdirSync(__dirname + '/../../dats/');
4920
}
50-
*/
51-
52-
process.argv.forEach(function (val, index, array) {
53-
console.log(index + ': ' + val);
54-
});
55-
56-
})
57-
58-
const isSecondInstance = app.makeSingleInstance((commandLine, workingDirectory) => {
59-
// Someone tried to run a second instance, we should focus our window.
60-
if (win) {
61-
if (win.isMinimized()) win.restore()
62-
win.show()
63-
win.focus()
64-
}
65-
})
66-
67-
if (isSecondInstance) {
68-
app.quit()
69-
}
7021

7122
function createWindow () {
7223
// Create the browser window.
73-
win = new BrowserWindow(
74-
{
24+
win = new BrowserWindow({
7525
width: 800,
7626
height: 600,
77-
icon: __dirname+'/logo_128.png',
27+
icon: appIcon,
7828
backgroundColor: '#424242',
7929
show: false
8030
})
8131

82-
win.setMenu(null)
83-
84-
// and load the index.html of the app.
85-
win.loadURL('file://' + __dirname + '/server_app.html')
86-
32+
const devTopMenu = Menu.buildFromTemplate([
33+
{label: appName + " v" + versionNumber + " dev mode"},
34+
{label: 'Quit for real', click: function() {app.isQuiting = true; app.quit();}}
35+
])
8736

8837
// Open the DevTools if dev is true.
8938
if(dev == true) {
90-
win.webContents.openDevTools({mode:'detach'})
39+
win.setMenu(devTopMenu)
40+
win.setThumbnailToolTip(appName + " v" + versionNumber + " dev mode")
41+
win.setTitle(appName + " v" + versionNumber + " dev mode")
42+
win.webContents.openDevTools({mode:'detach'})
43+
} else if (dev != true) {
44+
win.setMenu(null)
45+
win.setThumbnailToolTip(appName + " v" + versionNumber)
46+
win.setTitle(appName + " v" + versionNumber)
9147
}
9248

49+
win.on('show', () => {
50+
if(dev == true) {
51+
win.webContents.openDevTools({mode:'detach'})
52+
}
53+
})
54+
55+
// and load the index.html of the app.
56+
win.loadURL('file://' + __dirname + '/server_app.html')
57+
9358
win.on('close', function (event) {
9459
if( !app.isQuiting){
9560
event.preventDefault()
@@ -105,65 +70,68 @@ function createWindow () {
10570
// when you should delete the corresponding element.
10671
win = null
10772
})
108-
73+
10974
}
11075

111-
// This method will be called when Electron has finished
112-
// initialization and is ready to create browser windows.
113-
// Some APIs can only be used after this event occurs.
114-
app.on('ready', createWindow)
76+
const isSecondInstance = app.makeSingleInstance((commandLine, workingDirectory) => {
77+
// Someone tried to run a second instance, we should focus our window.
78+
if (win) {
79+
if (win.isMinimized()) win.restore()
80+
win.show()
81+
win.focus()
82+
}
83+
})
84+
85+
if (isSecondInstance) {
86+
app.quit()
87+
}
88+
89+
app.on('ready', () => {
90+
if (!fs.existsSync(__dirname + '/../../dats/')) {
91+
fs.mkdirSync(__dirname + '/../../dats/');
92+
}
93+
94+
tray = new Tray(appIcon)
95+
96+
const contextMenu = Menu.buildFromTemplate([
97+
{label: 'Show', click: function() {win.show();}},
98+
{label: 'Quit', click: function() {app.isQuiting = true; app.quit();}}
99+
])
100+
101+
const devContextMenu = Menu.buildFromTemplate([
102+
{label: 'Show', click: function() {win.show();}},
103+
{label: 'Quit', click: function() {app.isQuiting = true; app.quit();}},
104+
{label: appName + " v" + versionNumber + " dev mode"}
105+
])
106+
107+
if(dev == true) {
108+
tray.setContextMenu(devContextMenu)
109+
tray.setToolTip(appName + " v" + versionNumber + " dev mode")
110+
} else if (dev != true) {
111+
tray.setContextMenu(contextMenu)
112+
tray.setToolTip(appName + " v" + versionNumber)
113+
}
114+
115+
tray.on('click', () => {
116+
win.show()
117+
})
118+
119+
if(app.isDefaultProtocolClient(appName)) {
120+
121+
} else {
122+
app.setAsDefaultProtocolClient(appName)
123+
}
124+
125+
//var openingNotification = new Notification({title: "ggggggggo", body: "lol"})
126+
//openingNotification.show()
127+
128+
createWindow();
129+
})
115130

116131
app.on('activate', () => {
117132
// On macOS it's common to re-create a window in the app when the
118133
// dock icon is clicked and there are no other windows open.
119134
if (win === null) {
120135
createWindow()
121136
}
122-
})
123-
124-
// In this file you can include the rest of your app's specific main process
125-
// code. You can also put them in separate files and require them here.
126-
127-
}}} else if (window && window.chrome && chrome.runtime && chrome.runtime.id) {
128-
129-
chrome.app.runtime.onLaunched.addListener(function() {
130-
chrome.app.window.create('/server_app.html?platform=chromeApp', {
131-
'innerBounds': {
132-
'width': 800,
133-
'height': 600
134-
},
135-
'minWidth': 800,
136-
'minHeight': 400,
137-
'frame': {
138-
'type': 'chrome',
139-
'color': '#424242',
140-
'activeColor': '#ffffff',
141-
'inactiveColor': '#424242'
142-
},
143-
id: 'other_web_server'
144-
});
145-
});
146-
147-
chrome.runtime.onMessageExternal.addListener(function() {
148-
if(chrome.app.window.get('other_web_server')){
149-
//Do Nothing
150-
} else {
151-
chrome.app.window.create('/server_app.html?platform=chromeApp', {
152-
'innerBounds': {
153-
'width': 800,
154-
'height': 600
155-
},
156-
'minWidth': 800,
157-
'minHeight': 400,
158-
'state': 'minimized',
159-
'frame': {
160-
'type': 'chrome',
161-
'color': '#424242',
162-
'activeColor': '#ffffff',
163-
'inactiveColor': '#424242'
164-
},
165-
id: 'other_web_server'
166-
});
167-
}
168-
});
169-
}
137+
})

electron app/resources/datpart/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"type": "git",
88
"url": "https://github.com/HughIsaacs2/DatPart.git"
99
},
10-
"version": "0.0.5",
10+
"version": "0.0.6",
1111
"author": "Hugh Isaacs II <[email protected]>",
1212
"license": "MIT",
1313
"main": "launch.js",

0 commit comments

Comments
 (0)