Skip to content

Commit

Permalink
coding
Browse files Browse the repository at this point in the history
  • Loading branch information
leoding86 committed Nov 18, 2019
1 parent 3fcb981 commit 7e7dfc8
Show file tree
Hide file tree
Showing 18 changed files with 9,118 additions and 191 deletions.
12 changes: 12 additions & 0 deletions jsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"compilerOptions": {
"baseUrl": "./",
"paths": {
"@/*": ["src/main/*"]
}
},
"exclude": [
"node_modules",
"dist"
]
}
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"source-map-support": "^0.5.12"
},
"devDependencies": {
"@babel/plugin-proposal-class-properties": "^7.7.0",
"electron": "5.0.6",
"electron-builder": "^21.0.11",
"electron-webpack": "^2.7.4",
Expand All @@ -29,6 +30,11 @@
"win": {
"target": "NSIS"
},
"nsis": {
"oneClick": false,
"perMachine": false,
"allowToChangeInstallationDirectory": true
},
"protocols": {
"name": "pixiv-omina-protocal",
"schemes": [
Expand Down
164 changes: 81 additions & 83 deletions src/main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
import { app, BrowserWindow, ipcMain, protocol } from 'electron'
import ListenersRegister from './ListenersRegister'
import WindowManager from './modules/WindowManager'
import MangaWorkDownloader from './modules/WorkDownloader/MangaWorkDownloader';
import Downloader from './modules/Downloader';
import DownloadService from '@/services/DownloadService';

/**
* Make sure there is only one instance will be created.
Expand All @@ -13,102 +12,101 @@ const gotTheLock = app.requestSingleInstanceLock();

if (!gotTheLock) {
app.quit();
} else {
/**
* Create window manager, you should use this create window
*/
const windowManager = WindowManager.getManager();

/**
* Configurate downloader
*/
Downloader.setGlobalHeaders({
'referer': 'https://www.pixiv.net/',
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3964.0 Safari/537.36',
});

/**
* If another instance has been created, active the first instance.
*/
app.on('second-instance', (event, commandLine, workingDirectory) => {
if (mainWindow) {
if (mainWindow.isMinimized()) {
mainWindow.restore();
}
// Throw a error
Error("Only one instance could be created");
}

/**
* Create window manager, you should use this create window
*/
const windowManager = WindowManager.getManager();

mainWindow.focus();
/**
* Create download service, in this service, it will handle communication with the render thread.
*/
const downloadService = DownloadService.getService();

/**
* If another instance has been created, active the first instance.
*/
app.on('second-instance', (event, commandLine, workingDirectory) => {
if (mainWindow) {
if (mainWindow.isMinimized()) {
mainWindow.restore();
}
});

// const isDevelopment = process.env.NODE_ENV !== 'production'
mainWindow.focus();
}
});

// global reference to mainWindow (necessary to prevent window from being garbage collected)
let mainWindow
// const isDevelopment = process.env.NODE_ENV !== 'production'

function createMainWindow() {
const window = windowManager.createWindow('app', {
webPreferences: {
nodeIntegration: true,
webSecurity: false
}
});
// global reference to mainWindow (necessary to prevent window from being garbage collected)
let mainWindow

window.on('closed', () => {
mainWindow = null
})
function createMainWindow() {
const window = windowManager.createWindow('app', {
webPreferences: {
nodeIntegration: true,
webSecurity: false
}
});

window.webContents.on('devtools-opened', () => {
window.focus()
setImmediate(() => {
window.focus()
})
});

window.webContents.session.webRequest.onBeforeSendHeaders((detail, cb) => {
let {requestHeaders} = detail;
requestHeaders = Object.assign(requestHeaders, {Referer: 'https://www.pixiv.net/'});
cb({requestHeaders});
}, {
urls: ['<all_urls>'],
types: ['xmlhttprequest']
});

return window
}
window.on('closed', () => {
mainWindow = null
})

app.on('open-url', (event, data) => {
event.preventDefault();
window.webContents.on('devtools-opened', () => {
window.focus()
setImmediate(() => {
window.focus()
})
});

console.log(data);
window.webContents.session.webRequest.onBeforeSendHeaders((detail, cb) => {
let { requestHeaders } = detail;
requestHeaders = Object.assign(requestHeaders, { Referer: 'https://www.pixiv.net/' });
cb({ requestHeaders });
}, {
urls: ['<all_urls>'],
types: ['xmlhttprequest']
});

app.setAsDefaultProtocolClient('pixiv-omina')
return window
}

// quit application when all windows are closed
app.on('window-all-closed', () => {
// on macOS it is common for applications to stay open until the user explicitly quits
if (process.platform !== 'darwin') {
app.quit()
}
})
app.on('open-url', (event, data) => {
event.preventDefault();

app.on('activate', () => {
// on macOS it is common to re-create a window even after all windows have been closed
if (mainWindow === null) {
mainWindow = createMainWindow()
}
})
console.log(data);
});

// create main BrowserWindow when electron is ready
app.on('ready', () => {
mainWindow = createMainWindow();
app.setAsDefaultProtocolClient('pixiv-omina')

new ListenersRegister();
// quit application when all windows are closed
app.on('window-all-closed', () => {
// on macOS it is common for applications to stay open until the user explicitly quits
if (process.platform !== 'darwin') {
app.quit()
}
})

// test
ipcMain.on('work:download', (event, args) => {
let downloader = MangaWorkDownloader.createDownloader();
});
})
app.on('activate', () => {
// on macOS it is common to re-create a window even after all windows have been closed
if (mainWindow === null) {
mainWindow = createMainWindow()
}
})

}
// create main BrowserWindow when electron is ready
app.on('ready', () => {
mainWindow = createMainWindow();

new ListenersRegister();

// test
ipcMain.on('work:download', (event, args) => {
let downloader = MangaWorkDownloader.createDownloader();
});
})
2 changes: 1 addition & 1 deletion src/main/listeners/UserLogin.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import WindowManager from '../modules/WindowManager';
import WindowManager from '@/modules/WindowManager';

function UserLogin() {
this.windowManager = WindowManager.getManager();
Expand Down
41 changes: 0 additions & 41 deletions src/main/modules/DownloadManager.js

This file was deleted.

Loading

0 comments on commit 7e7dfc8

Please sign in to comment.