Sha256: 14c0eb4ef6f5b36f8303f7bfda563bbda8b8672be133158119c2294740cd3b71

Contents?: true

Size: 1.18 KB

Versions: 7

Compression:

Stored size: 1.18 KB

Contents

# frozen_string_literal: true

require "fusuma/plugin/appmatcher/version"

require_relative "appmatcher/x11"
require_relative "appmatcher/gnome"
require_relative "appmatcher/gnome_extension"
require_relative "appmatcher/gnome_extensions/installer"

module Fusuma
  module Plugin
    # Detect focused applications.
    module Appmatcher
      module_function

      # @return [Class]
      def backend_klass
        case xdg_session_type
        when /x11/
          return X11
        when /wayland/
          case xdg_current_desktop
          when /GNOME/
            return GnomeExtension if GnomeExtensions::Installer.new.installed?

            return Gnome
          end
        end

        error_message_not_supported
        exit 1
      end

      def xdg_session_type
        ENV.fetch("XDG_SESSION_TYPE", "")
      end

      def xdg_current_desktop
        ENV.fetch("XDG_CURRENT_DESKTOP", "")
      end

      def error_message_not_supported
        MultiLogger.error(
          <<~ERROR
            appmatcher doesn't support
            XDG_CURRENT_DESKTOP: '#{xdg_current_desktop}'
            XDG_SESSION_TYPE: '#{xdg_session_type}'"
          ERROR
        )
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
fusuma-plugin-appmatcher-0.4.0 lib/fusuma/plugin/appmatcher.rb
fusuma-plugin-appmatcher-0.3.1 lib/fusuma/plugin/appmatcher.rb
fusuma-plugin-appmatcher-0.3.0 lib/fusuma/plugin/appmatcher.rb
fusuma-plugin-appmatcher-0.2.3 lib/fusuma/plugin/appmatcher.rb
fusuma-plugin-appmatcher-0.2.2 lib/fusuma/plugin/appmatcher.rb
fusuma-plugin-appmatcher-0.2.1 lib/fusuma/plugin/appmatcher.rb
fusuma-plugin-appmatcher-0.2.0 lib/fusuma/plugin/appmatcher.rb