neomjs / neo

The application worker driven frontend framework
https://neomjs.com
MIT License
2.83k stars 151 forks source link

Remove main.addon.Browser #5758

Closed tobiu closed 3 weeks ago

tobiu commented 3 weeks ago

@Dinkh @rwaters: https://github.com/neomjs/neo/blob/dev/src/main/addon/Browser.mjs We should really stick to feature detection and not use regex to try determine a device type, which is not needed. The regex contains very outdated device types, but this is not the point.

Counter example:

    // worker.Manager
    detectFeatures() {
        let me = this;

        NeoConfig.hasMouseEvents = matchMedia('(pointer:fine)').matches;
        NeoConfig.hasTouchEvents = ('ontouchstart' in window) || (navigator.maxTouchPoints > 0);

        if (window.Worker) {
            me.webWorkersEnabled = true
        } else {
            throw new Error('Your browser does not support Web Workers')
        }

        if (window.SharedWorker) {
            me.sharedWorkersEnabled = true
        }
    }

    // main.addon.DragDrop
        if (Neo.config.hasMouseEvents) {
            imports.push(import('../draggable/sensor/Mouse.mjs'))
        }

        if (Neo.config.hasTouchEvents) {
            imports.push(import('../draggable/sensor/Touch.mjs'))
        }

What could be important for styling (like the ContentBoxes inside the Portal App) is the info, if there is a mouse or not. So adding a new CSS rule to the doc body like neo-no-mouse should be fine.

For styling, only the sizes matter (responsive breakpoints).

If you want to get the user agent info for a specific use case, you can already easily do it:

Neo.Main.getByPath({path: 'navigator.userAgent'}).then(userAgent => {});
rwaters commented 3 weeks ago

Agreed that feature detection & media queries over browser detection are the way to go. Provides much more future proof code that does not need to be continually maintained as browsers evolve.