func NewDeviceWatcher()

in plugins/internal/plugin/device_watcher.go [52:105]


func NewDeviceWatcher(
	expectedVersion string,
	deviceFilter discovery.DeviceFilter,
	includeIntegrated bool,
	includeDetachable bool,
	additionalRuntimeFiles map[string][]*discovery.RuntimeFile,
	additionalRuntimeFilesWow64 map[string][]*discovery.RuntimeFile,
	logger *zap.SugaredLogger,
) (*DeviceWatcher, error) {

	// Attempt to load the DirectX device discovery library
	if err := discovery.LoadDiscoveryLibrary(); err != nil {
		return nil, err
	}

	// Verify that the version of the device discovery library matches our expected version
	libraryVersion := discovery.GetDiscoveryLibraryVersion()
	if libraryVersion != expectedVersion {
		return nil, fmt.Errorf(
			"device discovery library version mismatch (found %s, expected %s)",
			libraryVersion,
			expectedVersion,
		)
	}

	// Enable verbose logging for the device discovery library
	discovery.EnableDiscoveryLogging()

	// Create a new DeviceDiscovery object
	deviceDiscovery, err := discovery.NewDeviceDiscovery()
	if err != nil {
		return nil, err
	}

	// Create the DeviceWatcher
	watcher := &DeviceWatcher{
		deviceDiscovery:             deviceDiscovery,
		deviceFilter:                deviceFilter,
		includeIntegrated:           includeIntegrated,
		includeDetachable:           includeDetachable,
		additionalRuntimeFiles:      additionalRuntimeFiles,
		additionalRuntimeFilesWow64: additionalRuntimeFilesWow64,
		logger:                      logger,
		refresh:                     make(chan struct{}, 1),
		shutdown:                    make(chan struct{}),
		Errors:                      make(chan error, 1),
		Updates:                     make(chan []*discovery.Device, 1),
	}

	// Start the watcher goroutine
	go watcher.watchDevices()

	return watcher, nil
}