Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add FOCUS component #227

Closed
fttx opened this issue Dec 5, 2019 · 2 comments
Closed

Add FOCUS component #227

fttx opened this issue Dec 5, 2019 · 2 comments
Assignees
Labels
Milestone

Comments

@fttx
Copy link
Owner

fttx commented Dec 5, 2019

To focus a specific program

@fttx fttx added the feature label Dec 5, 2019
@fttx fttx added this to the v4.0.0 milestone Dec 5, 2019
@fttx fttx modified the milestones: v4.0.0, v3.12.0 Jul 4, 2020
@fttx fttx self-assigned this Jul 18, 2020
@fttx
Copy link
Owner Author

fttx commented Aug 30, 2020

Library: https://github.com/sentialx/node-window-manager/

❌ No Linux support
❌ Handles macOS menu bar apps as windows: sentialx/node-window-manager#34
❌ External libraries required to ask for permissions: sentialx/node-window-manager#32 (macOS)

Sample code:

const { windowManager, Window } = require("node-window-manager");
const {
    hasScreenCapturePermission,
    hasPromptedForPermission
} = require('mac-screen-capture-permissions');

const fs = require('fs');
const path = require("path");

// Request recording permissions (required for getTitle() on macOS)
if (!(hasScreenCapturePermission())) {
    console.log('no permission')
    // TODO open sys. preferences
    // See this: https://github.com/karaggeorge/mac-screen-capture-permissions
}

// This method has to be called on macOS before changing the window's bounds, otherwise it will throw an error.
// It will prompt an accessibility permission request dialog, if needed.
windowManager.requestAccessibility();


const window = windowManager.getActiveWindow();
// Prints the currently focused window bounds.
// console.log(window.getBounds());
// Sets the active window's bounds.
// window.setBounds({ x: 0, y: 0 });

let lastAppName = null;
windowManager.getWindows().forEach(window => {
    if (window.isWindow() && window.getTitle()) {
        let icon = window.getIcon(64);
        let appName = path.basename(window.path);
        if (icon && lastAppName != appName) {
            fs.writeFile('icons/' + appName.split('/')[0] + '.png', icon, 'binary', (err) => { if (err) throw err });
            console.log(appName);
            lastAppName = appName;

            // Focus the requested window
            if (appName == 'Finder.app') {
                window.bringToTop();
            }
        }
        console.log(' |- ' + window.getTitle())
    }
    // console.log(window)
})

@fttx
Copy link
Owner Author

fttx commented Sep 12, 2020

8938ddd

@fttx fttx closed this as completed Sep 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant