Commit 21a141fa authored by rocosen's avatar rocosen

fix:打包设置

parent cbc06c75
This diff was suppressed by a .gitattributes entry.
This diff was suppressed by a .gitattributes entry.
This diff was suppressed by a .gitattributes entry.
This diff was suppressed by a .gitattributes entry.
This diff is collapsed.
...@@ -116,6 +116,7 @@ ...@@ -116,6 +116,7 @@
"electron-debug": "^3.2.0", "electron-debug": "^3.2.0",
"electron-log": "^4.4.8", "electron-log": "^4.4.8",
"electron-root-path": "^1.1.0", "electron-root-path": "^1.1.0",
"electron-traywindow-positioner": "^1.1.1",
"electron-updater": "^5.2.1", "electron-updater": "^5.2.1",
"express": "^4.18.2", "express": "^4.18.2",
"history": "^5.3.0", "history": "^5.3.0",
......
...@@ -9,12 +9,13 @@ ...@@ -9,12 +9,13 @@
* `./src/main.js` using webpack. This gives us some performance wins. * `./src/main.js` using webpack. This gives us some performance wins.
*/ */
import path from 'path'; import path from 'path';
import { app, BrowserWindow, shell, ipcMain } from 'electron'; import { app, BrowserWindow, shell, ipcMain, Tray, Menu } from 'electron';
import { autoUpdater } from 'electron-updater'; import { autoUpdater } from 'electron-updater';
import log from 'electron-log'; import log from 'electron-log';
import MenuBuilder from './menu'; import MenuBuilder from './menu';
import { resolveHtmlPath } from './util'; import { resolveHtmlPath } from './util';
const nativeImage = require('electron').nativeImage;
const positioner = require('electron-traywindow-positioner');
class AppUpdater { class AppUpdater {
constructor() { constructor() {
...@@ -23,18 +24,37 @@ class AppUpdater { ...@@ -23,18 +24,37 @@ class AppUpdater {
autoUpdater.checkForUpdatesAndNotify(); autoUpdater.checkForUpdatesAndNotify();
} }
} }
let tray: Tray | null = null;
let mainWindow: BrowserWindow | null = null; let mainWindow: BrowserWindow | null = null;
let win: BrowserWindow | null = null; let siteWindown: BrowserWindow | null = null;
let homeWindown: BrowserWindow | null = null;
const isDev = process.env.NODE_ENV === 'development'; const isDev = process.env.NODE_ENV === 'development';
const alignment = { x: 'left', y: 'up' };
const RESOURCES_PATH = app.isPackaged
? path.join(process.resourcesPath, 'assets')
: path.join(__dirname, '../../assets');
const getAssetPath = (...paths: string[]): string => {
return path.join(RESOURCES_PATH, ...paths);
};
let image = nativeImage.createFromPath(getAssetPath('icon.jpg'));
image = image.resize({
width: 32,
height: 32,
});
Menu.setApplicationMenu(null);
ipcMain.on('createNewWindow-site', (event, arg) => { ipcMain.on('createNewWindow-site', (event, arg) => {
if (win) { if (siteWindown) {
win.focus(); siteWindown.focus();
return; return;
} }
win = new BrowserWindow({ siteWindown = new BrowserWindow({
width: 620, width: 620,
height: 482, height: 482,
minWidth: 100, minWidth: 100,
...@@ -47,24 +67,43 @@ ipcMain.on('createNewWindow-site', (event, arg) => { ...@@ -47,24 +67,43 @@ ipcMain.on('createNewWindow-site', (event, arg) => {
contextIsolation: false, contextIsolation: false,
webSecurity: false, webSecurity: false,
}, },
// parent: win, //win是主窗口 // parent: siteWindown, //win是主窗口
}); });
win.loadURL(resolveHtmlPath(`index.html#/site`)); siteWindown.loadURL(resolveHtmlPath(`index.html#/site`));
isDev && win.webContents.openDevTools(); isDev && siteWindown.webContents.openDevTools();
win.on('closed', () => { siteWindown.on('closed', () => {
win = null; siteWindown = null;
}); });
}); });
ipcMain.on('resize-home', (event) => { ipcMain.on('resize-home', (event) => {
if (mainWindow) { if (!tray) return;
mainWindow.setContentSize(350, 425); mainWindow?.close();
// mainWindow.setResizable(true); if (homeWindown) {
mainWindow.setMaximizable(false); homeWindown.focus();
// mainWindow.setFrame(false); return;
// mainWindow.center();
} }
homeWindown = new BrowserWindow({
width: 350,
height: 425,
minWidth: 100,
minHeight: 100,
frame: false,
resizable: false,
webPreferences: {
sandbox: false,
nodeIntegration: true,
contextIsolation: false,
webSecurity: false,
},
});
homeWindown.loadURL(resolveHtmlPath(`index.html#/home`));
positioner.position(homeWindown, tray.getBounds(), alignment);
isDev && homeWindown.webContents.openDevTools();
homeWindown.on('closed', () => {
homeWindown = null;
});
}); });
ipcMain.on('window-close', (event) => { ipcMain.on('window-close', (event) => {
...@@ -101,23 +140,17 @@ const createWindow = async () => { ...@@ -101,23 +140,17 @@ const createWindow = async () => {
await installExtensions(); await installExtensions();
} }
const RESOURCES_PATH = app.isPackaged
? path.join(process.resourcesPath, 'assets')
: path.join(__dirname, '../../assets');
const getAssetPath = (...paths: string[]): string => {
return path.join(RESOURCES_PATH, ...paths);
};
mainWindow = new BrowserWindow({ mainWindow = new BrowserWindow({
show: false, show: false,
width: 480, width: 480,
height: 486, height: 486,
minWidth: 100, minWidth: 100,
minHeight: 100, minHeight: 100,
icon: getAssetPath('icon.png'), icon: getAssetPath('icon.ico'),
frame: true, frame: true,
resizable: false, resizable: false,
titleBarStyle: 'hidden',
// autoHideMenuBar: true,
webPreferences: { webPreferences: {
sandbox: false, sandbox: false,
nodeIntegration: true, nodeIntegration: true,
...@@ -126,8 +159,14 @@ const createWindow = async () => { ...@@ -126,8 +159,14 @@ const createWindow = async () => {
}, },
}); });
mainWindow.loadURL(resolveHtmlPath('index.html')); tray = new Tray(image);
// tray.setTitle('test');
// mainWindow.setMenuBarVisibility(false);
// mainWindow.removeMenu();
// mainWindow.setMenu(null);
mainWindow.loadURL(resolveHtmlPath('index.html'));
// mainWindow.webContents.openDevTools();
mainWindow.on('ready-to-show', () => { mainWindow.on('ready-to-show', () => {
if (!mainWindow) { if (!mainWindow) {
throw new Error('"mainWindow" is not defined'); throw new Error('"mainWindow" is not defined');
...@@ -136,6 +175,7 @@ const createWindow = async () => { ...@@ -136,6 +175,7 @@ const createWindow = async () => {
mainWindow.minimize(); mainWindow.minimize();
} else { } else {
mainWindow.show(); mainWindow.show();
// mainWindow.webContents.openDevTools();
} }
}); });
...@@ -143,8 +183,8 @@ const createWindow = async () => { ...@@ -143,8 +183,8 @@ const createWindow = async () => {
mainWindow = null; mainWindow = null;
}); });
const menuBuilder = new MenuBuilder(mainWindow); // const menuBuilder = new MenuBuilder(mainWindow);
menuBuilder.buildMenu(); // menuBuilder.buildMenu();
// Open urls in the user's browser // Open urls in the user's browser
mainWindow.webContents.setWindowOpenHandler((edata) => { mainWindow.webContents.setWindowOpenHandler((edata) => {
...@@ -156,16 +196,15 @@ const createWindow = async () => { ...@@ -156,16 +196,15 @@ const createWindow = async () => {
// eslint-disable-next-line // eslint-disable-next-line
new AppUpdater(); new AppUpdater();
// function initLoginWindow(windowObj: any) { tray.on('click', function () {
// windowObj.setContentSize(500, 500); if (mainWindow) {
// windowObj.setResizable(false); mainWindow.show();
// windowObj.setMaximizable(false); return;
// windowObj.center(); }
// } if (!homeWindown || !tray) return;
homeWindown.show();
// ipcMain.on('showLoginWindow', (event) => { positioner.position(homeWindown, tray.getBounds(), alignment);
// initLoginWindow(mainWindow); });
// });
}; };
/** /**
......
...@@ -15,6 +15,7 @@ body { ...@@ -15,6 +15,7 @@ body {
); */ ); */
font-family: sans-serif; font-family: sans-serif;
overflow-y: hidden; overflow-y: hidden;
-webkit-app-region: drag;
/* display: flex; /* display: flex;
justify-content: center; justify-content: center;
align-items: center; */ align-items: center; */
...@@ -32,6 +33,7 @@ button { ...@@ -32,6 +33,7 @@ button {
transition: all ease-in 0.1s; transition: all ease-in 0.1s;
cursor: pointer; cursor: pointer;
opacity: 0.9; opacity: 0.9;
-webkit-app-region: no-drag;
} }
button:hover { button:hover {
......
import { HashRouter as Router, Route, Switch, Routes } from 'react-router-dom'; import { HashRouter as Router, Route, Switch, Routes } from 'react-router-dom';
import { Switch } from 'react-router-dom'; import { Switch } from 'react-router-dom';
import icon from '../../assets/icon.svg';
import { createBrowserHistory } from 'history'; import { createBrowserHistory } from 'history';
import './App.css'; import './App.css';
import path from 'path'; import path from 'path';
......
...@@ -249,7 +249,7 @@ export default (props) => { ...@@ -249,7 +249,7 @@ export default (props) => {
sx={{ sx={{
fontSize: '12px', fontSize: '12px',
color: '#565C66', color: '#565C66',
marginLeft: '4px', marginLeft: '8px',
}} }}
> >
加载更多… 加载更多…
......
...@@ -22,7 +22,7 @@ const useStyles = makeStyles()((theme) => { ...@@ -22,7 +22,7 @@ const useStyles = makeStyles()((theme) => {
export default (props) => { export default (props) => {
const { classes } = useStyles(); const { classes } = useStyles();
const { render, navigate } = public(); const { render, navigate } = public();
const [value, setValue] = useState('two'); const [value, setValue] = useState('one');
const handleChange = (event, newValue) => { const handleChange = (event, newValue) => {
setValue(newValue); setValue(newValue);
......
...@@ -29,7 +29,7 @@ const useStyles = makeStyles()((theme) => { ...@@ -29,7 +29,7 @@ const useStyles = makeStyles()((theme) => {
flexDirection: 'column', flexDirection: 'column',
width: '300px', width: '300px',
margin: '0 auto', margin: '0 auto',
marginTop: '10%', paddingTop: '10%',
}, },
root: { root: {
height: '40px', height: '40px',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment