Browse Source

fixed bug

master
1549469775 4 years ago
parent
commit
f50f281916
  1. 4
      .babelrc
  2. 165
      package-lock.json
  3. 3
      package.json
  4. 2
      script/webpack/runMain.js
  5. 4
      script/webpack/webpack.main.config.js
  6. 18
      src/main/index.dev.ts
  7. 17
      src/main/index.ts
  8. 66
      src/main/menu.ts
  9. 5
      src/main/share/index.ts
  10. 6
      src/render/views/About/index.tsx
  11. 2
      tsconfig.json

4
.babelrc

@ -3,10 +3,10 @@
"env": {
"main": {
"presets": [
["env", {
["@babel/preset-env", {
"targets": { "node": 7 }
}],
"stage-0"
"@babel/preset-typescript"
]
}
},

165
package-lock.json

@ -697,6 +697,15 @@
"@babel/helper-plugin-utils": "^7.14.5"
}
},
"@babel/plugin-syntax-typescript": {
"version": "7.14.5",
"resolved": "https://registry.nlark.com/@babel/plugin-syntax-typescript/download/@babel/plugin-syntax-typescript-7.14.5.tgz",
"integrity": "sha1-uCxs5HGxZbXOQgz5KRTW+0YiVxY=",
"dev": true,
"requires": {
"@babel/helper-plugin-utils": "^7.14.5"
}
},
"@babel/plugin-transform-arrow-functions": {
"version": "7.14.5",
"resolved": "https://registry.nlark.com/@babel/plugin-transform-arrow-functions/download/@babel/plugin-transform-arrow-functions-7.14.5.tgz",
@ -1022,6 +1031,17 @@
"@babel/helper-plugin-utils": "^7.14.5"
}
},
"@babel/plugin-transform-typescript": {
"version": "7.14.6",
"resolved": "https://registry.nlark.com/@babel/plugin-transform-typescript/download/@babel/plugin-transform-typescript-7.14.6.tgz?cache=0&sync_timestamp=1623708810675&other_urls=https%3A%2F%2Fregistry.nlark.com%2F%40babel%2Fplugin-transform-typescript%2Fdownload%2F%40babel%2Fplugin-transform-typescript-7.14.6.tgz",
"integrity": "sha1-bpwtmNolB+vgqIOxAM3jxyed82w=",
"dev": true,
"requires": {
"@babel/helper-create-class-features-plugin": "^7.14.6",
"@babel/helper-plugin-utils": "^7.14.5",
"@babel/plugin-syntax-typescript": "^7.14.5"
}
},
"@babel/plugin-transform-unicode-escapes": {
"version": "7.14.5",
"resolved": "https://registry.nlark.com/@babel/plugin-transform-unicode-escapes/download/@babel/plugin-transform-unicode-escapes-7.14.5.tgz?cache=0&sync_timestamp=1623280468339&other_urls=https%3A%2F%2Fregistry.nlark.com%2F%40babel%2Fplugin-transform-unicode-escapes%2Fdownload%2F%40babel%2Fplugin-transform-unicode-escapes-7.14.5.tgz",
@ -1141,6 +1161,17 @@
"integrity": "sha1-tqDsoaO3Lgf5yvWPmY6XVoAo9vU=",
"dev": true
},
"@babel/preset-typescript": {
"version": "7.14.5",
"resolved": "https://registry.nlark.com/@babel/preset-typescript/download/@babel/preset-typescript-7.14.5.tgz",
"integrity": "sha1-qpjeEZz5hSt5UR8Z5/RKLTebzOA=",
"dev": true,
"requires": {
"@babel/helper-plugin-utils": "^7.14.5",
"@babel/helper-validator-option": "^7.14.5",
"@babel/plugin-transform-typescript": "^7.14.5"
}
},
"@babel/runtime": {
"version": "7.14.8",
"resolved": "https://registry.nlark.com/@babel/runtime/download/@babel/runtime-7.14.8.tgz",
@ -4568,6 +4599,72 @@
}
}
},
"electron-debug": {
"version": "3.2.0",
"resolved": "https://registry.npm.taobao.org/electron-debug/download/electron-debug-3.2.0.tgz?cache=0&sync_timestamp=1608556231395&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Felectron-debug%2Fdownload%2Felectron-debug-3.2.0.tgz",
"integrity": "sha1-RqFbVVw7EYciGMZeoB0FiqCBSSA=",
"dev": true,
"requires": {
"electron-is-dev": "^1.1.0",
"electron-localshortcut": "^3.1.0"
}
},
"electron-devtools-installer": {
"version": "3.2.0",
"resolved": "https://registry.nlark.com/electron-devtools-installer/download/electron-devtools-installer-3.2.0.tgz",
"integrity": "sha1-rMSNJOtwM/5a8oShlmfnO3jUBtA=",
"dev": true,
"requires": {
"rimraf": "^3.0.2",
"semver": "^7.2.1",
"tslib": "^2.1.0",
"unzip-crx-3": "^0.2.0"
},
"dependencies": {
"rimraf": {
"version": "3.0.2",
"resolved": "https://registry.npm.taobao.org/rimraf/download/rimraf-3.0.2.tgz?cache=0&sync_timestamp=1614946161596&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Frimraf%2Fdownload%2Frimraf-3.0.2.tgz",
"integrity": "sha1-8aVAK6YiCtUswSgrrBrjqkn9Bho=",
"dev": true,
"requires": {
"glob": "^7.1.3"
}
},
"semver": {
"version": "7.3.5",
"resolved": "https://registry.nlark.com/semver/download/semver-7.3.5.tgz?cache=0&sync_timestamp=1618847119601&other_urls=https%3A%2F%2Fregistry.nlark.com%2Fsemver%2Fdownload%2Fsemver-7.3.5.tgz",
"integrity": "sha1-C2Ich5NI2JmOSw5L6Us/EuYBjvc=",
"dev": true,
"requires": {
"lru-cache": "^6.0.0"
}
}
}
},
"electron-is-accelerator": {
"version": "0.1.2",
"resolved": "https://registry.npm.taobao.org/electron-is-accelerator/download/electron-is-accelerator-0.1.2.tgz",
"integrity": "sha1-UJ5RDCala1Xhf4Y6SwThEYRqsns=",
"dev": true
},
"electron-is-dev": {
"version": "1.2.0",
"resolved": "https://registry.npm.taobao.org/electron-is-dev/download/electron-is-dev-1.2.0.tgz",
"integrity": "sha1-LlzqChs8zxyG9XfO53Nj71XesF4=",
"dev": true
},
"electron-localshortcut": {
"version": "3.2.1",
"resolved": "https://registry.npm.taobao.org/electron-localshortcut/download/electron-localshortcut-3.2.1.tgz",
"integrity": "sha1-z8g6Pv9eKPr5jdzIf4Cizk9iPNM=",
"dev": true,
"requires": {
"debug": "^4.0.1",
"electron-is-accelerator": "^0.1.0",
"keyboardevent-from-electron-accelerator": "^2.0.0",
"keyboardevents-areequal": "^0.2.1"
}
},
"electron-publish": {
"version": "22.11.7",
"resolved": "https://registry.nlark.com/electron-publish/download/electron-publish-22.11.7.tgz?cache=0&sync_timestamp=1627148601382&other_urls=https%3A%2F%2Fregistry.nlark.com%2Felectron-publish%2Fdownload%2Felectron-publish-22.11.7.tgz",
@ -5921,6 +6018,12 @@
"dev": true,
"optional": true
},
"immediate": {
"version": "3.0.6",
"resolved": "https://registry.nlark.com/immediate/download/immediate-3.0.6.tgz",
"integrity": "sha1-nbHb0Pr43m++D13V5Wu2BigN5ps=",
"dev": true
},
"import-lazy": {
"version": "2.1.0",
"resolved": "https://registry.nlark.com/import-lazy/download/import-lazy-2.1.0.tgz",
@ -6440,6 +6543,30 @@
"graceful-fs": "^4.1.6"
}
},
"jszip": {
"version": "3.7.0",
"resolved": "https://registry.nlark.com/jszip/download/jszip-3.7.0.tgz",
"integrity": "sha1-m4uZWk58kCRlPOdD6QIHaoL99OY=",
"dev": true,
"requires": {
"lie": "~3.3.0",
"pako": "~1.0.2",
"readable-stream": "~2.3.6",
"set-immediate-shim": "~1.0.1"
}
},
"keyboardevent-from-electron-accelerator": {
"version": "2.0.0",
"resolved": "https://registry.npm.taobao.org/keyboardevent-from-electron-accelerator/download/keyboardevent-from-electron-accelerator-2.0.0.tgz",
"integrity": "sha1-rOIbGqTkcUiBXRYAV/nttmVnxQw=",
"dev": true
},
"keyboardevents-areequal": {
"version": "0.2.2",
"resolved": "https://registry.npm.taobao.org/keyboardevents-areequal/download/keyboardevents-areequal-0.2.2.tgz",
"integrity": "sha1-iBkexzjOn3WRwl6QVt6Si0AncZQ=",
"dev": true
},
"keyv": {
"version": "3.1.0",
"resolved": "https://registry.npm.taobao.org/keyv/download/keyv-3.1.0.tgz?cache=0&sync_timestamp=1600337463601&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fkeyv%2Fdownload%2Fkeyv-3.1.0.tgz",
@ -6476,6 +6603,15 @@
"integrity": "sha1-bPO59bwxzufuPjacCDK3WD3Nkj0=",
"dev": true
},
"lie": {
"version": "3.3.0",
"resolved": "https://registry.npm.taobao.org/lie/download/lie-3.3.0.tgz",
"integrity": "sha1-3Pgt7lRfRgdNryAMfBxaCOD0D2o=",
"dev": true,
"requires": {
"immediate": "~3.0.5"
}
},
"lines-and-columns": {
"version": "1.1.6",
"resolved": "https://registry.npm.taobao.org/lines-and-columns/download/lines-and-columns-1.1.6.tgz",
@ -7204,6 +7340,12 @@
"semver": "^6.2.0"
}
},
"pako": {
"version": "1.0.11",
"resolved": "https://registry.nlark.com/pako/download/pako-1.0.11.tgz",
"integrity": "sha1-bJWZ00DVTf05RjgCUqNXBaa5kr8=",
"dev": true
},
"param-case": {
"version": "3.0.4",
"resolved": "https://registry.npm.taobao.org/param-case/download/param-case-3.0.4.tgz?cache=0&sync_timestamp=1606867292797&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fparam-case%2Fdownload%2Fparam-case-3.0.4.tgz",
@ -8270,6 +8412,12 @@
"integrity": "sha1-BF+XgtARrppoA93TgrJDkrPYkPc=",
"dev": true
},
"set-immediate-shim": {
"version": "1.0.1",
"resolved": "https://registry.nlark.com/set-immediate-shim/download/set-immediate-shim-1.0.1.tgz",
"integrity": "sha1-SysbJ+uAip+NzEgaWOXlb1mfP2E=",
"dev": true
},
"set-value": {
"version": "2.0.1",
"resolved": "https://registry.nlark.com/set-value/download/set-value-2.0.1.tgz",
@ -9412,6 +9560,17 @@
}
}
},
"unzip-crx-3": {
"version": "0.2.0",
"resolved": "https://registry.npm.taobao.org/unzip-crx-3/download/unzip-crx-3-0.2.0.tgz",
"integrity": "sha1-1TJBR7EEqK7ZroY5yVUh9vfNopI=",
"dev": true,
"requires": {
"jszip": "^3.1.0",
"mkdirp": "^0.5.1",
"yaku": "^0.16.6"
}
},
"upath": {
"version": "1.2.0",
"resolved": "https://registry.npm.taobao.org/upath/download/upath-1.2.0.tgz",
@ -10539,6 +10698,12 @@
"integrity": "sha1-f0k00PfKjFb5UxSTndzS3ZHOHVU=",
"dev": true
},
"yaku": {
"version": "0.16.7",
"resolved": "https://registry.npm.taobao.org/yaku/download/yaku-0.16.7.tgz",
"integrity": "sha1-HRlceKqbW/hHnIlblQT9TwhHmE4=",
"dev": true
},
"yallist": {
"version": "4.0.0",
"resolved": "https://registry.npm.taobao.org/yallist/download/yallist-4.0.0.tgz",

3
package.json

@ -29,6 +29,7 @@
"@babel/plugin-transform-runtime": "^7.14.5",
"@babel/preset-env": "^7.14.8",
"@babel/preset-stage-0": "^7.8.3",
"@babel/preset-typescript": "^7.14.5",
"@rollup/plugin-alias": "^3.1.4",
"@rollup/plugin-commonjs": "^19.0.1",
"@rollup/plugin-json": "^4.1.0",
@ -52,6 +53,8 @@
"dotenv": "^10.0.0",
"electron": "^13.1.7",
"electron-builder": "^22.11.7",
"electron-debug": "^3.2.0",
"electron-devtools-installer": "^3.2.0",
"electron-squirrel-startup": "^1.0.0",
"execa": "^5.1.1",
"i18next": "^20.3.4",

2
script/webpack/runMain.js

@ -65,7 +65,7 @@ function buildMain () {
}
function startMain (callback) {
return new Promise((resolve, reject) => {
mainConfig.entry.main = [path.join(__dirname, '../../src/main/index.ts')]//.concat(mainConfig.entry.main)
mainConfig.entry.main = [path.join(__dirname, '../../src/main/index.dev.ts')]//.concat(mainConfig.entry.main)
mainConfig.mode = 'development'
const compiler = webpack(mainConfig)

4
script/webpack/webpack.main.config.js

@ -18,8 +18,8 @@ let mainConfig = {
module: {
rules: [
{
test: /\.js$/,
use: ['babel-loader'],
test: /\.(js|ts)$/,
use: ['babel-loader','ts-loader'],
exclude: /node_modules/
},
{

18
src/main/index.dev.ts

@ -0,0 +1,18 @@
// Install `electron-debug` with `devtron`
import electronDebug from "electron-debug"
electronDebug({ showDevTools: true })
// Install `vue-devtools`
require('electron').app.on('ready', () => {
let installExtension = require('electron-devtools-installer')
installExtension.default(installExtension.VUEJS_DEVTOOLS)
.then(() => {})
.catch((err:Error) => {
console.log('Unable to install `vue-devtools`: \n', err)
})
})
// Require `main` process to boot app
import './index'

17
src/main/index.ts

@ -5,6 +5,7 @@
import Shared from "./share"
const { join } = require("path")
const { app, BrowserWindow } = require("electron")
import "./menu"
Shared.data = {
mainWindow: null,
@ -19,12 +20,19 @@ if (!isDev) {
// @ts-ignore
global.__static = require("path").join(__dirname, "/static").replace(/\\/g, "\\\\")
}
function createWin() {
// 创建浏览器窗口dsaasdad
Shared.data.mainWindow = new BrowserWindow({
width: 1024,
height: 768,
height: 800,
useContentSize: true,
width: 900,
// resizable: false,
// minWidth: 450,
// minHeight: 400,
// frame: false,
// transparent: true,
alwaysOnTop: true,
icon: __static + "/icon.png",
webPreferences: {
// 下面两个必须这么用,看a.md的文档
@ -37,7 +45,8 @@ function createWin() {
const URL = app.isPackaged
? `file://${__dirname}/index.html` // vite 构建后的静态文件地址
: `http://localhost:${process.env.PORT}/#/` // vite 启动的服务器地址
// : `http://localhost:${process.env.PORT}/#/` // vite 启动的服务器地址
: `http://localhost:8080/#/` // vite 启动的服务器地址
Shared.data.mainWindow?.loadURL(URL)
}

66
src/main/menu.ts

@ -0,0 +1,66 @@
import electron from "electron"
const BrowserWindow = electron.BrowserWindow
const Menu = electron.Menu
const app = electron.app
const dialog = electron.dialog
const ipcMain = electron.ipcMain
let newwin:electron.BrowserWindow|null = null
let template = [
{
label: "关于",
click: function (item:any, focusedWindow:any) {
// https://www.electronjs.org/docs/api/browser-window#winsetmenubarvisibilityvisible-windows-linux
if (focusedWindow && !newwin) {
newwin = new BrowserWindow({
width: 600,
height: 200,
// modal: true,
show: false,
resizable: true,
parent: focusedWindow, // win是主窗口
//
webPreferences: {
// 下面两个必须这么用,看a.md的文档
nodeIntegration: true,
contextIsolation: false,
// 预加载动画
// preload: join(__dirname, "../../src/preload/index.js"),
},
})
// 隐藏菜单
newwin?.setMenuBarVisibility(false)
newwin.loadURL(process.env.NODE_ENV === "development" ? `http://localhost:${process.env.PORT}/#/about` : `file://${__dirname}/index.html#/about`);
newwin.on("ready-to-show", () => {
newwin?.show()
})
newwin.on("closed", () => {
newwin = null
})
}
},
},
]
// if (process.platform === 'darwin') {
//
// }
//
// if (process.platform === 'win32') {
//
// }
app.on("ready", function () {
const menu = Menu.buildFromTemplate(template)
Menu.setApplicationMenu(menu)
})
app.on("browser-window-created", function () {
// let reopenMenuItem = findReopenMenuItem()
// if (reopenMenuItem) reopenMenuItem.enabled = false
})
app.on("window-all-closed", function () {
app.exit()
// let reopenMenuItem = findReopenMenuItem()
// if (reopenMenuItem) reopenMenuItem.enabled = true
})

5
src/main/share/index.ts

@ -1,7 +1,8 @@
interface IPayload{
data: {
[key:string]: any;
}
[propName:string]: any;
};
[propName:string]: any;
}
const payload:IPayload = {

6
src/render/views/About/index.tsx

@ -7,7 +7,7 @@ function Test() {
export default function About(props: any) {
let history = useHistory()
let location = useLocation()
// let location = useLocation()
function back(){
console.log(1231);
@ -16,7 +16,9 @@ export default function About(props: any) {
return (
<div className="">
<div onClick={() =>back()}> asdasd</div>
<div>22{props.children}</div>
<div>22{props.children}{location.href}</div>
<p>sadsa</p>
<p>sadsa</p>
<Route path="/about/aa" exact={true}>
<Test></Test>
</Route>

2
tsconfig.json

@ -13,7 +13,7 @@
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"noEmit": false,
"jsx": "react",
"rootDir": ".",
"baseUrl": ".",

Loading…
Cancel
Save