Skip to content

Commit

Permalink
feat: 支持以外部URL启动
Browse files Browse the repository at this point in the history
  • Loading branch information
John-Chan committed Oct 14, 2020
1 parent fa028bd commit 466c2df
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ yarn electron:build:uat
yarn electron:build:prod
```

### 命令行参数

`--url ${URL}` 以外部URL启动,比如 `pig-ui.exe --url https://pigx.pig4cloud.com/` 一般用于测试。

### 效果演示

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"crypto-js": "^3.1.9-1",
"element-ui": "^2.13.2",
"js-cookie": "^2.2.1",
"minimist": "^1.2.5",
"nprogress": "^0.2.0",
"script-loader": "^0.7.2",
"vue": "^2.6.10",
Expand Down
16 changes: 11 additions & 5 deletions src/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ 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'

const parseArgs = require('minimist')
const args = parseArgs(process.argv.slice(1), {string: ['url']})
// 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.
let win
Expand All @@ -26,15 +27,20 @@ function createWindow() {
webSecurity: false
}
})

let url = args.url
if (process.env.WEBPACK_DEV_SERVER_URL) {
// Load the url of the dev server if in development mode
win.loadURL(process.env.WEBPACK_DEV_SERVER_URL)
if (!process.env.IS_TEST) win.webContents.openDevTools()
} else {
createProtocol('app')
// Load the index.html when not in development
win.loadURL('app://./index.html')
if(url) {
console.log(`load form url ${url}`)
win.loadURL(url)
} else {
createProtocol('app')
// Load the index.html when not in development
win.loadURL('app://./index.html')
}
}

win.on('closed', () => {
Expand Down

0 comments on commit 466c2df

Please sign in to comment.