LOCKING客户端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

93 lines
2.9 KiB

  1. // Modules to control application life and create native browser window
  2. const { app, BrowserWindow, protocol, ipcMain, dialog, nativeImage } = require('electron')
  3. const path = require('path')
  4. const gotTheLock = app.requestSingleInstanceLock();
  5. if (!gotTheLock) {
  6. app.quit();
  7. return;
  8. }
  9. let mainWindow;
  10. function createWindow() {
  11. // Create the browser window.
  12. mainWindow = new BrowserWindow({
  13. width: 1080,
  14. height: 600,
  15. webPreferences: {
  16. nodeIntegration: true,
  17. // javascript: true,
  18. // plugins: true,
  19. preload: path.join(__dirname, './', 'preload.js'),
  20. },
  21. // frame: false,
  22. })
  23. // and load the index.html of the app.
  24. // mainWindow.loadFile('./dist/index.html')
  25. mainWindow.loadURL('http://www.lockingos.org:9000', { "extraHeaders": "pragma: no-cache\n" });
  26. // mainWindow.loadURL('http://localhost:8081');
  27. // 隐藏菜单栏
  28. mainWindow.setMenuBarVisibility(false);
  29. // Open the DevTools.
  30. // mainWindow.webContents.openDevTools()
  31. mainWindow.maximize();
  32. }
  33. // This method will be called when Electron has finished
  34. // initialization and is ready to create browser windows.
  35. // Some APIs can only be used after this event occurs.
  36. app.whenReady().then(() => {
  37. createWindow()
  38. app.on('activate', function () {
  39. // On macOS it's common to re-create a window in the app when the
  40. // dock icon is clicked and there are no other windows open.
  41. if (BrowserWindow.getAllWindows().length === 0) createWindow()
  42. })
  43. })
  44. // Quit when all windows are closed, except on macOS. There, it's common
  45. // for applications and their menu bar to stay active until the user quits
  46. // explicitly with Cmd + Q.
  47. app.on('window-all-closed', function () {
  48. if (process.platform !== 'darwin') app.quit()
  49. })
  50. app.on('second-instance', (event, commandLine, workingDirectory) => {
  51. // 当运行第二个实例时,将会聚焦到mainWindow这个窗口
  52. if (mainWindow) {
  53. if (mainWindow.isMinimized()) mainWindow.restore()
  54. mainWindow.focus()
  55. mainWindow.show()
  56. }
  57. })
  58. // In this file you can include the rest of your app's specific main process
  59. // code. You can also put them in separate files and require them here.
  60. // 监听必要的自定义事件
  61. /**
  62. * 项目中的文件上传
  63. */
  64. ipcMain.handle('project-choose-files', async (event, args) => {
  65. const res = await dialog.showOpenDialog({
  66. properties: ['multiSelections', 'openFile'],
  67. });
  68. return res;
  69. });
  70. ipcMain.handle('project-choose-folders', async (event, args) => {
  71. const res = await dialog.showOpenDialog({
  72. properties: ['multiSelections', 'openDirectory'],
  73. });
  74. return res;
  75. });
  76. const testIcon = nativeImage.createFromPath(path.resolve(__dirname, 'file_word.png'));
  77. ipcMain.handle('project-file-dnd', (event, filePath) => {
  78. console.log('receive file path: ', filePath)
  79. event.sender.startDrag({
  80. file: filePath, // path.resolve(__dirname, 'file_word.png'),
  81. // icon: nativeImage.createFromNamedImage('NS')
  82. icon: testIcon,
  83. });
  84. })