feat: 初始化SSO登录Electron应用
- 创建Electron主进程,加载SSO登录页面 - 配置electron-builder用于打包Mac/Windows/Linux - 添加证书忽略处理,支持自签名证书 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
58
main.js
Normal file
58
main.js
Normal file
@@ -0,0 +1,58 @@
|
||||
const { app, BrowserWindow, session } = require('electron');
|
||||
const path = require('path');
|
||||
|
||||
// SSO登录URL
|
||||
const SSO_URL = 'https://yzsyhr.183.sc.cn/eassso/login?service=http%3A%2F%2Fyzsyhr.183.sc.cn%3A80%2Fshr%2F';
|
||||
|
||||
function createWindow() {
|
||||
const mainWindow = new BrowserWindow({
|
||||
width: 1280,
|
||||
height: 800,
|
||||
webPreferences: {
|
||||
nodeIntegration: false,
|
||||
contextIsolation: true,
|
||||
},
|
||||
title: 'SSO登录',
|
||||
icon: path.join(__dirname, 'icon.png'), // 可选图标
|
||||
});
|
||||
|
||||
// 忽略证书错误(如果有自签名证书)
|
||||
mainWindow.webContents.session.setCertificateVerifyProc((request, callback) => {
|
||||
callback(0); // 0 表示信任证书
|
||||
});
|
||||
|
||||
// 加载SSO页面
|
||||
mainWindow.loadURL(SSO_URL);
|
||||
|
||||
// 监听URL变化,登录成功后可以做后续处理
|
||||
mainWindow.webContents.on('did-navigate', (event, url) => {
|
||||
console.log('Navigated to:', url);
|
||||
|
||||
// 如果跳转到了目标应用,说明登录成功
|
||||
if (url.includes('/shr/') && !url.includes('eassso')) {
|
||||
console.log('Login successful, now at:', url);
|
||||
}
|
||||
});
|
||||
|
||||
// 打开开发者工具(调试用,正式版可注释掉)
|
||||
// mainWindow.webContents.openDevTools();
|
||||
}
|
||||
|
||||
// 忽略证书错误
|
||||
app.commandLine.appendSwitch('ignore-certificate-errors');
|
||||
|
||||
app.whenReady().then(() => {
|
||||
createWindow();
|
||||
|
||||
app.on('activate', () => {
|
||||
if (BrowserWindow.getAllWindows().length === 0) {
|
||||
createWindow();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
app.on('window-all-closed', () => {
|
||||
if (process.platform !== 'darwin') {
|
||||
app.quit();
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user