Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Appbar stuff
- const ffi = require('@lwahonen/ffi-napi');
- const ref = require('@lwahonen/ref-napi');
- const Struct = require('ref-struct-di')(ref);
- // Define the APPBARDATA structure as per the Microsoft documentation
- const APPBARDATA = Struct({
- cbSize: ref.types.int,
- hWnd: ref.refType(ref.types.void),
- uCallbackMessage: ref.types.int,
- uEdge: ref.types.int,
- rc: Struct({
- left: ref.types.int,
- top: ref.types.int,
- right: ref.types.int,
- bottom: ref.types.int,
- }),
- lParam: ref.refType(ref.types.void)
- });
- const shabm_shell32 = ffi.Library('shell32.dll', {
- 'SHAppBarMessage': ['int32', ['uint32', APPBARDATA]]
- });
- const registerwm_user32 = new ffi.Library('user32', {
- 'RegisterWindowMessageA': ['uint', ['string']]
- });
- // user32 MoveWindow signature. may or may not work, i suck at javascript
- const movewindow_user32 = new ffi.Library('user32', {
- 'MoveWindow': ['bool', [ref.refType(ref.types.void), 'uint32', 'uint32', 'uint32', 'uint32', 'bool']]
- });
- function ABSetPos(hWnd) {
- let appBarDataPos = new APPBARDATA();
- appBarDataPos.cbSize = APPBARDATA.size;
- appBarDataPos.hWnd = hWnd;
- appBarDataPos.uEdge = 1;
- appBarDataPos.rc.left = 0;
- appBarDataPos.rc.right = 1366;
- appBarDataPos.rc.top = 0;
- appBarDataPos.rc.bottom = 50;
- shabm_shell32.SHAppBarMessage(2 /* ABMsg_QUERYPOS */, appBarDataPos.ref());
- shabm_shell32.SHAppBarMessage(3 /* ABMsg_SETPOS */, appBarDataPos.ref());
- // 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);
- movewindow_user32.MoveWindow(appBarDataPos.hWnd, appBarDataPos.rc.left, appBarDataPos.rc.top, appBarDataPos.rc.right - appBarDataPos.rc.left, appBarDataPos.rc.bottom - appBarDataPos.rc.top, true);
- // console.log(result);
- }
- app.whenReady().then(() => {
- createWindow()
- sWidth = screen.getPrimaryDisplay().workAreaSize.width;
- const trayMenu = Menu.buildFromTemplate([
- { label: 'Settings', type: 'normal', click: () => { optionsPopup() } },
- { label: 'DevTools', type: 'normal', click: () => { win.openDevTools({ mode: 'detach' }) } },
- { type: 'separator' },
- { label: 'Relaunch', type: 'normal', click: () => { app.quit(0); app.relaunch(0) } },
- { label: 'Quit', type: 'normal', click: () => { app.quit() } }
- ])
- const icon = nativeImage.createFromPath('12bar.ico')
- const tray = new Tray(icon)
- tray.setContextMenu(trayMenu)
- tray.on('double-click', () => {
- win.webContents.send('get-theme')
- });
- win.setSize(sWidth, 50, true);
- volumeLevel = audio.get();
- // const networkInterfaces = os.networkInterfaces();
- // console.log(networkInterfaces);
- networkInfo();
- let handle = win.getNativeWindowHandle();
- let hWnd = handle.readUInt32LE(0);
- const hWndBuffer = Buffer.alloc(ref.sizeof.pointer);
- hWndBuffer.writeUInt32LE(hWnd, 0);
- // Register 12bar to allow for it to send AppBar messages to Windows
- let registerUCallback = registerwm_user32.RegisterWindowMessageA("AppBarMessage")
- // Initialize the APPBARDATA structure
- let appBarData = new APPBARDATA();
- appBarData.cbSize = APPBARDATA.size;
- appBarData.hWnd = hWndBuffer;
- appBarData.uCallbackMessage = registerUCallback;
- appBarData.uEdge = 1;
- appBarData.rc.left = 0;
- appBarData.rc.top = 0;
- appBarData.rc.right = 1366;
- appBarData.rc.bottom = 50;
- // Register the appbar
- let result = shabm_shell32.SHAppBarMessage(0, appBarData.ref());
- shabm_shell32.SHAppBarMessage(0, appBarData.ref());
- console.log(result);
- ABSetPos(hWndBuffer);
- })
Advertisement
Add Comment
Please, Sign In to add comment