Skip to content

Commit

Permalink
fea: 调试主进程分支
Browse files Browse the repository at this point in the history
  • Loading branch information
CoderArthurXin committed Nov 25, 2019
1 parent 61fc872 commit 7a75ff2
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 14 deletions.
16 changes: 16 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Debug Main Process",
"type": "node",
"request": "launch",
"cwd": "${workspaceRoot}",
"runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron.cmd",
"windows": {
"runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron.cmd"
},
"args" : ["."]
}
]
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "electron-builder-start",
"version": "1.0.0",
"license": "MIT",
"main": "./src/main/index.js",
"scripts": {
"dev": "electron-webpack dev",
"compile": "electron-webpack",
Expand Down
18 changes: 11 additions & 7 deletions src/main/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
'use strict'

import { app, BrowserWindow } from 'electron'
import * as path from 'path'
import { format as formatUrl } from 'url'
import * as tray from './tray'
const { app, BrowserWindow } = require('electron')
const path = require('path')
const { format } = require('url')
const tray = require('./tray')

const isDevelopment = process.env.NODE_ENV !== 'production'

Expand All @@ -18,9 +18,9 @@ function createMainWindow() {
}

// 把html放入static
let indexPath = path.join(__static, '/html/index.html')
let indexPath = path.join(__dirname, '../../static/html/index.html')
console.log('indexPath:', indexPath)
window.loadURL(formatUrl({
window.loadURL(format({
pathname: indexPath,
protocol: 'file',
slashes: true
Expand Down Expand Up @@ -63,6 +63,10 @@ app.on('ready', () => {
tray.creatTray()
})

export function getWin () {
function getWin () {
return mainWindow
}

module.exports = {
getWin
}
16 changes: 9 additions & 7 deletions src/main/tray/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Menu, Tray, app, dialog } from 'electron'
import path from 'path'
import { getWin } from '../index'
const { Menu, Tray, app, dialog } = require('electron')
const path = require('path')
const { getWin } = require('../index')

let tray = null

Expand All @@ -24,14 +24,14 @@ app.on('quit', () => {


// 创建系统托盘
export function creatTray () {
function creatTray () {
// 写法一
// 路径是:.\dist\win-ia32-unpacked\resources\static\resource\win, 后面部分不要加static
// tray = new Tray(path.join(__static, './resource/win/icon.ico'))
tray = new Tray('./static/resource/win/icon.ico')

// 写法二
// 路径是:.\dist\win-ia32-unpacked\resources\app.asar\..\static\resource\win
tray = new Tray(path.join(__dirname, '../static/resource/win/icon.ico'))
// tray = new Tray(path.join(__dirname, '../static/resource/win/icon.ico'))

const contextMenu = Menu.buildFromTemplate([
{
Expand Down Expand Up @@ -71,4 +71,6 @@ export function creatTray () {
})
}


module.exports = {
creatTray
}

0 comments on commit 7a75ff2

Please sign in to comment.