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