Skip to content

Commit

Permalink
chore: desktop 调整配置使其在打包状态下能够正常运行
Browse files Browse the repository at this point in the history
  • Loading branch information
moonrailgun committed Jun 4, 2022
1 parent c5455b6 commit 26ee4de
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 78 deletions.
8 changes: 0 additions & 8 deletions desktop/.erb/configs/webpack.config.base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,6 @@ const configuration: webpack.Configuration = {
new webpack.EnvironmentPlugin({
NODE_ENV: 'production',
}),
new webpack.ProvidePlugin({
Buffer: ['buffer', 'Buffer'],
}),
new webpack.DefinePlugin({
process: {
version: JSON.stringify(process.version),
},
}),
],
};

Expand Down
9 changes: 2 additions & 7 deletions desktop/.erb/configs/webpack.config.renderer.dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import ReactRefreshWebpackPlugin from '@pmmmwh/react-refresh-webpack-plugin';
import baseConfig from './webpack.config.base';
import webpackPaths from './webpack.paths';
import checkNodeEnv from '../scripts/check-node-env';
import CopyPlugin from 'copy-webpack-plugin';
import { sharedRendererPlugins } from './webpack.config.renderer.shared';

// When an ESLint server is running, we can't set the NODE_ENV so we'll check if it's
// at the dev webpack config is not accidentally run in a production environment
Expand Down Expand Up @@ -119,6 +119,7 @@ const configuration: webpack.Configuration = {
],
},
plugins: [
...sharedRendererPlugins,
...(requiredByDLLConfig
? []
: [
Expand Down Expand Up @@ -166,12 +167,6 @@ const configuration: webpack.Configuration = {
isDevelopment: process.env.NODE_ENV !== 'production',
nodeModules: webpackPaths.appNodeModulesPath,
}),

new CopyPlugin({
patterns: [
{ from: webpackPaths.srcPublicPath, to: webpackPaths.distPublicPath },
],
}),
],

node: {
Expand Down
9 changes: 2 additions & 7 deletions desktop/.erb/configs/webpack.config.renderer.prod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import baseConfig from './webpack.config.base';
import webpackPaths from './webpack.paths';
import checkNodeEnv from '../scripts/check-node-env';
import deleteSourceMaps from '../scripts/delete-source-maps';
import CopyPlugin from 'copy-webpack-plugin';
import { sharedRendererPlugins } from './webpack.config.renderer.shared';

checkNodeEnv('production');
deleteSourceMaps();
Expand Down Expand Up @@ -112,6 +112,7 @@ const configuration: webpack.Configuration = {
},

plugins: [
...sharedRendererPlugins,
/**
* Create global constants which can be configured at compile time.
*
Expand Down Expand Up @@ -145,12 +146,6 @@ const configuration: webpack.Configuration = {
isBrowser: false,
isDevelopment: process.env.NODE_ENV !== 'production',
}),

new CopyPlugin({
patterns: [
{ from: webpackPaths.srcPublicPath, to: webpackPaths.distPublicPath },
],
}),
],
};

Expand Down
23 changes: 23 additions & 0 deletions desktop/.erb/configs/webpack.config.renderer.shared.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import CopyPlugin from 'copy-webpack-plugin';
import webpack from 'webpack';
import webpackPaths from './webpack.paths';

export const sharedRendererPlugins: webpack.Configuration['plugins'] = [
new webpack.ProvidePlugin({
Buffer: ['buffer', 'Buffer'],
}),
new webpack.DefinePlugin({
process: {
browser: JSON.stringify(true),
version: JSON.stringify(process.version),
env: {
NODE_ENV: JSON.stringify('production'),
},
},
}),
new CopyPlugin({
patterns: [
{ from: webpackPaths.srcPublicPath, to: webpackPaths.distPublicPath },
],
}),
];
3 changes: 2 additions & 1 deletion desktop/electron-builder.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
productName: Tailchat Meeting
appId: com.msgbyte.tailchat-meeting
asar: true
# asar: true
asar: false
asarUnpack: '**\*.{node,dll}'
files:
- dist
Expand Down
122 changes: 67 additions & 55 deletions desktop/src/main/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import MenuBuilder from './menu';
import { resolveHtmlPath } from './util';
import windowStateKeeper from 'electron-window-state';

log.info('Start...');

export default class AppUpdater {
constructor() {
log.transports.file.level = 'info';
Expand Down Expand Up @@ -57,66 +59,76 @@ const installExtensions = async () => {

let mainWindow: BrowserWindow | null = null;
const createWindow = async () => {
if (isDebug) {
await installExtensions();
}
try {
log.info('Create window');

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);
};

const mainWindowState = windowStateKeeper({
defaultWidth: 1024,
defaultHeight: 728,
});

mainWindow = new BrowserWindow({
show: false,
x: mainWindowState.x,
y: mainWindowState.y,
height: mainWindowState.height,
width: mainWindowState.width,
icon: getAssetPath('icon.png'),
webPreferences: {
preload: app.isPackaged
? path.join(__dirname, 'preload.js')
: path.join(__dirname, '../../.erb/dll/preload.js'),
},
});

mainWindow.loadURL(resolveHtmlPath('index.html'));

mainWindow.on('ready-to-show', () => {
if (!mainWindow) {
throw new Error('"mainWindow" is not defined');
}
if (process.env.START_MINIMIZED) {
mainWindow.minimize();
} else {
mainWindow.show();
if (isDebug) {
log.info('Install extensions');
await installExtensions();
}
});

mainWindow.on('closed', () => {
mainWindow = null;
});
const RESOURCES_PATH = app.isPackaged
? path.join(process.resourcesPath, 'assets')
: path.join(__dirname, '../../assets');
log.info('parse resolve path:', RESOURCES_PATH);

const mainWindowState = windowStateKeeper({
defaultWidth: 1024,
defaultHeight: 728,
});
log.info('load window state with:', mainWindow);

const getAssetPath = (...paths: string[]): string => {
return path.join(RESOURCES_PATH, ...paths);
};
mainWindow = new BrowserWindow({
show: false,
x: mainWindowState.x,
y: mainWindowState.y,
height: mainWindowState.height,
width: mainWindowState.width,
icon: getAssetPath('icon.png'),
webPreferences: {
preload: app.isPackaged
? path.join(__dirname, 'preload.js')
: path.join(__dirname, '../../.erb/dll/preload.js'),
},
});

log.info('loadUrl:', resolveHtmlPath('index.html'));
mainWindow.loadURL(resolveHtmlPath('index.html'));

mainWindow.on('ready-to-show', () => {
if (!mainWindow) {
throw new Error('"mainWindow" is not defined');
}
if (process.env.START_MINIMIZED) {
mainWindow.minimize();
} else {
mainWindow.show();
}
});

mainWindow.on('closed', () => {
mainWindow = null;
});

const menuBuilder = new MenuBuilder(mainWindow);
menuBuilder.buildMenu();
log.info('Build menu');
const menuBuilder = new MenuBuilder(mainWindow);
menuBuilder.buildMenu();

// Open urls in the user's browser
mainWindow.webContents.setWindowOpenHandler((edata) => {
shell.openExternal(edata.url);
return { action: 'deny' };
});
// Open urls in the user's browser
mainWindow.webContents.setWindowOpenHandler((edata) => {
shell.openExternal(edata.url);
return { action: 'deny' };
});

// Remove this if your app does not use auto updates
// eslint-disable-next-line
new AppUpdater();
// Remove this if your app does not use auto updates
// eslint-disable-next-line
new AppUpdater();
} catch (err) {
log.error('createWindow error:', err);
}
};

/**
Expand All @@ -141,4 +153,4 @@ app
if (mainWindow === null) createWindow();
});
})
.catch(console.log);
.catch(log.error);

0 comments on commit 26ee4de

Please sign in to comment.