From bd29570e3160c476b4c38313d1bbba45bc4a6dcc Mon Sep 17 00:00:00 2001 From: kunkka Date: Tue, 27 Oct 2020 03:56:05 +0800 Subject: [PATCH] feat: update electron config --- package.json | 2 ++ src/background.js | 29 +++++++++++++++++++++++++++-- vue.config.js | 28 ++++++++++++++++------------ 3 files changed, 45 insertions(+), 14 deletions(-) diff --git a/package.json b/package.json index 2ea2ec4..ef94503 100644 --- a/package.json +++ b/package.json @@ -2,6 +2,8 @@ "name": "YesPlayMusic", "version": "0.2.0", "private": true, + "description": "A third party music application for Netease Cloud Music", + "author": "qier222", "scripts": { "serve": "vue-cli-service serve", "build": "vue-cli-service build", diff --git a/src/background.js b/src/background.js index 99a3250..4ea6e34 100644 --- a/src/background.js +++ b/src/background.js @@ -1,9 +1,12 @@ "use strict"; - +const { exec } = require("child_process"); +// const fs = require('fs') import { app, protocol, BrowserWindow } from "electron"; import { createProtocol } from "vue-cli-plugin-electron-builder/lib"; import installExtension, { VUEJS_DEVTOOLS } from "electron-devtools-installer"; const isDevelopment = process.env.NODE_ENV !== "production"; +// maybe use for modify app menu +// const contextMenu = require('electron-context-menu'); // 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. @@ -15,14 +18,35 @@ protocol.registerSchemesAsPrivileged([ ]); function createWindow() { + console.log("Node Version: ", process.version); + const napi = exec("npm run napi:run"); + let scriptOutput = ""; + napi.stdout.setEncoding('utf8'); + napi.stdout.on('data', (data) => { + console.log('napi: ' + data); + data = data.toString(); + scriptOutput += data + '\n'; + // TODO write file with stream + // const log = fs.createWriteStream(__dirname, '/tmp/' + +new Date + '.log') + // log.write(scriptOutput) + }); + // napi.stdout.on('error', (err) => { + // console.log('napi error: ' + err); + // data = err.toString(); + // scriptOutput += data + '\n'; + // const log = fs.createWriteStream(__dirname, '/tmp/' + +new Date + 'error.log') + // log.write(scriptOutput) + // }); + // Create the browser window. win = new BrowserWindow({ width: 1920, height: 768, webPreferences: { + webSecurity: false, // Use pluginOptions.nodeIntegration, leave this alone // See nklayman.github.io/vue-cli-plugin-electron-builder/guide/security.html#node-integration for more info - nodeIntegration: process.env.ELECTRON_NODE_INTEGRATION, + nodeIntegration: true, }, }); @@ -34,6 +58,7 @@ function createWindow() { createProtocol("app"); // Load the index.html when not in development win.loadURL("app://./index.html"); + win.webContents.openDevTools(); } win.on("closed", () => { diff --git a/vue.config.js b/vue.config.js index 03f87a1..c08614c 100644 --- a/vue.config.js +++ b/vue.config.js @@ -1,4 +1,5 @@ const path = require("path"); +const CopywebpackPlugin = require('copy-webpack-plugin') function resolve(dir) { return path.join(__dirname, dir); } @@ -75,19 +76,22 @@ module.exports = { nsis: { oneClick: false, allowToChangeInstallationDirectory: true - } + }, + // 集成 nodejs, https://nklayman.github.io/vue-cli-plugin-electron-builder/guide/security.html#node-integration + // nodeIntegration: true }, - // chainWebpackMainProcess: config => { - // config.module - // .rule('babel') - // .test(/\*.js$/) - // .use('babel') - // .loader('babel-loader') - // .options({ - // presets: [['@babel/preset-env', '@vue/cli-plugin-babel/preset', { modules: false }]], - // plugins: ['@babel/plugin-proposal-class-properties'] - // }) - // }, + chainWebpackMainProcess: config => { + // console.log(config) + let outputDir = 'dist_electron/bundled' + config.plugin('copy').use(CopywebpackPlugin, [ + [ + { + from: path.resolve(__dirname, './NeteaseCloudMusicApi-master'), + to: path.join(__dirname, outputDir, 'NeteaseCloudMusicApi-master') + } + ] + ]) + } // 渲染线程的配置文件 // chainWebpackRendererProcess: config => { // // 渲染线程的一些其他配置