Futur3Sn0w

appbar stuff

Oct 3rd, 2023 (edited)
1,366
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Appbar stuff
  2.  
  3. const ffi = require('@lwahonen/ffi-napi');
  4. const ref = require('@lwahonen/ref-napi');
  5. const Struct = require('ref-struct-di')(ref);
  6.  
  7. // Define the APPBARDATA structure as per the Microsoft documentation
  8. const APPBARDATA = Struct({
  9.     cbSize: ref.types.int,
  10.     hWnd: ref.refType(ref.types.void),
  11.     uCallbackMessage: ref.types.int,
  12.     uEdge: ref.types.int,
  13.     rc: Struct({
  14.         left: ref.types.int,
  15.         top: ref.types.int,
  16.         right: ref.types.int,
  17.         bottom: ref.types.int,
  18.     }),
  19.     lParam: ref.refType(ref.types.void)
  20. });
  21.  
  22. const shabm_shell32 = ffi.Library('shell32.dll', {
  23.     'SHAppBarMessage': ['int32', ['uint32', APPBARDATA]]
  24. });
  25.  
  26. const registerwm_user32 = new ffi.Library('user32', {
  27.     'RegisterWindowMessageA': ['uint', ['string']]
  28. });
  29.  
  30. // user32 MoveWindow signature. may or may not work, i suck at javascript
  31. const movewindow_user32 = new ffi.Library('user32', {
  32.     'MoveWindow': ['bool', [ref.refType(ref.types.void), 'uint32', 'uint32', 'uint32', 'uint32', 'bool']]
  33. });
  34.  
  35. function ABSetPos(hWnd) {
  36.     let appBarDataPos = new APPBARDATA();
  37.     appBarDataPos.cbSize = APPBARDATA.size;
  38.     appBarDataPos.hWnd = hWnd;
  39.     appBarDataPos.uEdge = 1;
  40.     appBarDataPos.rc.left = 0;
  41.     appBarDataPos.rc.right = 1366;
  42.     appBarDataPos.rc.top = 0;
  43.     appBarDataPos.rc.bottom = 50;
  44.  
  45.     shabm_shell32.SHAppBarMessage(2 /* ABMsg_QUERYPOS */, appBarDataPos.ref());
  46.     shabm_shell32.SHAppBarMessage(3 /* ABMsg_SETPOS */, appBarDataPos.ref());
  47.     // let result = movewindow_user32.MoveWindow(appBarDataPos.hWnd, appBarDataPos.rc.left, appBarDataPos.rc.top, appBarDataPos.rc.right - appBarDataPos.rc.left, appBarDataPos.rc.bottom - appBarDataPos.rc.top, true);
  48.     movewindow_user32.MoveWindow(appBarDataPos.hWnd, appBarDataPos.rc.left, appBarDataPos.rc.top, appBarDataPos.rc.right - appBarDataPos.rc.left, appBarDataPos.rc.bottom - appBarDataPos.rc.top, true);
  49.     // console.log(result);
  50. }
  51.  
  52. app.whenReady().then(() => {
  53.     createWindow()
  54.  
  55.     sWidth = screen.getPrimaryDisplay().workAreaSize.width;
  56.  
  57.     const trayMenu = Menu.buildFromTemplate([
  58.         { label: 'Settings', type: 'normal', click: () => { optionsPopup() } },
  59.         { label: 'DevTools', type: 'normal', click: () => { win.openDevTools({ mode: 'detach' }) } },
  60.         { type: 'separator' },
  61.         { label: 'Relaunch', type: 'normal', click: () => { app.quit(0); app.relaunch(0) } },
  62.         { label: 'Quit', type: 'normal', click: () => { app.quit() } }
  63.     ])
  64.     const icon = nativeImage.createFromPath('12bar.ico')
  65.     const tray = new Tray(icon)
  66.     tray.setContextMenu(trayMenu)
  67.     tray.on('double-click', () => {
  68.         win.webContents.send('get-theme')
  69.     });
  70.  
  71.     win.setSize(sWidth, 50, true);
  72.     volumeLevel = audio.get();
  73.  
  74.     // const networkInterfaces = os.networkInterfaces();
  75.     // console.log(networkInterfaces);
  76.     networkInfo();
  77.  
  78.     let handle = win.getNativeWindowHandle();
  79.     let hWnd = handle.readUInt32LE(0);
  80.     const hWndBuffer = Buffer.alloc(ref.sizeof.pointer);
  81.     hWndBuffer.writeUInt32LE(hWnd, 0);
  82.  
  83.     // Register 12bar to allow for it to send AppBar messages to Windows
  84.     let registerUCallback = registerwm_user32.RegisterWindowMessageA("AppBarMessage")
  85.  
  86.     // Initialize the APPBARDATA structure
  87.     let appBarData = new APPBARDATA();
  88.     appBarData.cbSize = APPBARDATA.size;
  89.     appBarData.hWnd = hWndBuffer;
  90.     appBarData.uCallbackMessage = registerUCallback;
  91.     appBarData.uEdge = 1;
  92.     appBarData.rc.left = 0;
  93.     appBarData.rc.top = 0;
  94.     appBarData.rc.right = 1366;
  95.     appBarData.rc.bottom = 50;
  96.  
  97.     // Register the appbar
  98.     let result = shabm_shell32.SHAppBarMessage(0, appBarData.ref());
  99.     shabm_shell32.SHAppBarMessage(0, appBarData.ref());
  100.     console.log(result);
  101.     ABSetPos(hWndBuffer);
  102. })
Advertisement
Add Comment
Please, Sign In to add comment