Quellcode durchsuchen

refactor: use linux distro concept

Mark24 vor 2 Jahren
Ursprung
Commit
5ea15b55a8
5 geänderte Dateien mit 102 neuen und 92 gelöschten Zeilen
  1. 1 1
      README.md
  2. 1 15
      installer.rb
  3. 4 4
      lib/config.rb
  4. 0 72
      os/DebianDistroLinux.rb
  5. 96 0
      os/Linux.rb

+ 1 - 1
README.md

@@ -24,7 +24,7 @@ Debian发行版,默认注册了
 * linuxmint
 * linux-mint
 
-可以在 `lib/config` 中 `Config::DebianDistroLinux::DebianDistro` 中自行添加关键字支持。
+可以在 `lib/config` 中 `Config::LinuxDistro::DebianDistro` 中自行添加关键字支持。
 
 ### 参考&感谢:
 

+ 1 - 15
installer.rb

@@ -4,26 +4,12 @@ require "./lib/core"
 require "./lib/config"
 
 module OSPatch
-  def check_linux_debian_distro
-    os_release_file = "/etc/os-release"
-    if File.exist?(os_release_file)
-      os_release = File.read(os_release_file)
-      ::RimeDeploy::Config::DebianDistroLinux::DebianDistro.each do |distro|
-        return true if os_release.include?(distro)
-      end
-    end
-    return false
-  end
   def check_os
     case RUBY_PLATFORM.downcase
     when /darwin/
       @osname = "MacOS"
     when /linux/
-      if check_linux_debian_distro
-        @osname = "DebianDistroLinux"
-      else
-        not_support_exit
-      end
+      @osname = "LinuxDistro"
     when /mswin|win32|mingw|cygwin/
       @osname = "win"
       not_support_exit

+ 4 - 4
lib/config.rb

@@ -8,10 +8,10 @@ module RimeDeploy
       ConfigPath = "~/Library/Rime"
     end
 
-    class DebianDistroLinux
-      DebianDistro = %w[debian ubuntu linuxmint linux-mint]
-      InstallCmd = "sudo apt install ibus-rime"
-      ConfigPath = "~/.config/ibus/rime"
+    class LinuxDistro
+      ConfigPathIbus = "~/.config/ibus/rime"
+      ConfigPathFcitx = "~/.config/fcitx/rime"
+      ConfigPathFcitx5 = "~/.local/share/fcitx5/rime"
     end
   end
 end

+ 0 - 72
os/DebianDistroLinux.rb

@@ -1,72 +0,0 @@
-module RimeDeploy
-  module DebianDistroLinux
-    class InstallRimeJob < Job
-      def call
-        puts intro
-        puts "use Rime-ibus".yellow
-        system(Config::DebianDistroLinux::InstallCmd)
-        sleep 1
-        return :next
-      end
-    end
-
-    class BackupRimeConfigJob < Job
-      def call
-        puts intro
-        system(
-          "mv #{Config::DebianDistroLinux::ConfigPath} #{Config::DebianDistroLinux::ConfigPath}.#{Time.now.to_i}.old"
-        )
-        sleep 1
-        return :next
-      end
-    end
-
-    class CloneConfigJob < Job
-      def call
-        puts intro
-        system(
-          "git clone --depth=1 #{Config::RIME_CONFIG_REPO} #{Config::DebianDistroLinux::ConfigPath}"
-        )
-        sleep 1
-        return :next
-      end
-    end
-
-    class CopyCustomConfigJob < Job
-      def call
-        puts intro
-        system(
-          "cp ./custom/default.custom.yaml #{Config::DebianDistroLinux::ConfigPath}/"
-        )
-        system(
-          "cp ./custom/squirrel.custom.yaml #{Config::DebianDistroLinux::ConfigPath}/"
-        )
-        sleep 1
-        return :next
-      end
-    end
-
-    class FinishedJob < Job
-      def call
-        puts ""
-        puts "Tips: When finished all jobs. You need to do follow:".yellow
-        puts "1) Restart system."
-        puts "2) open Rime input method setting pane and click " +
-               "DEPLOY".yellow + " button."
-        puts "Enjoy~ 🍻"
-        puts "more info:".yellow
-        puts "Config path: #{Config::DebianDistroLinux::ConfigPath}/"
-        return :next
-      end
-    end
-
-    Jobs = [
-      InstallRimeJob,
-      BackupRimeConfigJob,
-      CloneConfigJob,
-      CopyCustomConfigJob
-    ]
-
-    FinishedHook = [FinishedJob]
-  end
-end

+ 96 - 0
os/Linux.rb

@@ -0,0 +1,96 @@
+module RimeDeploy
+  module LinuxDistro
+    class InstallRimeJob < Job
+      def update_config_path(path)
+        module ::RimeDeploy::Config::LinuxDistro
+          alias ConfigPath path
+        end
+      end
+      def call
+        puts intro
+        puts "Different Linux has it's own package manager. So make sure you had installed Rime before."
+        tips = <<-TIP
+Different Linux has it's own package manager. So make sure you had installed Rime before.
+
+For Fcitx5, installfcitx5-rime.
+For Fcitx, install fcitx-rime.
+For IBus, install ibus-rime.
+
+more:
+https://wiki.archlinux.org/title/Rime
+        TIP
+        puts tips
+        puts ""
+        puts "Then choose what your had installed."
+        ChooseSession.new(
+          [
+            ["ibus-rime", -> { update_config_path(::RimeDeploy::Config::LinuxDistro::ConfigPathIbus) }],
+            ["fcitx-rime", -> { update_config_path(::RimeDeploy::Config::LinuxDistro::ConfigPathFcitx) }],
+            ["fcitx5-rime", -> { update_config_path(::RimeDeploy::Config::LinuxDistro::ConfigPathFcitx5) }],
+          ]
+        ).call
+        sleep 1
+        return :next
+      end
+    end
+
+    class BackupRimeConfigJob < Job
+      def call
+        puts intro
+        system(
+          "mv #{Config::LinuxDistro::ConfigPath} #{Config::LinuxDistro::ConfigPath}.#{Time.now.to_i}.old"
+        )
+        sleep 1
+        return :next
+      end
+    end
+
+    class CloneConfigJob < Job
+      def call
+        puts intro
+        system(
+          "git clone --depth=1 #{Config::RIME_CONFIG_REPO} #{Config::LinuxDistro::ConfigPath}"
+        )
+        sleep 1
+        return :next
+      end
+    end
+
+    class CopyCustomConfigJob < Job
+      def call
+        puts intro
+        system(
+          "cp ./custom/default.custom.yaml #{Config::LinuxDistro::ConfigPath}/"
+        )
+        system(
+          "cp ./custom/squirrel.custom.yaml #{Config::LinuxDistro::ConfigPath}/"
+        )
+        sleep 1
+        return :next
+      end
+    end
+
+    class FinishedJob < Job
+      def call
+        puts ""
+        puts "Tips: When finished all jobs. You need to do follow:".yellow
+        puts "1) Restart system."
+        puts "2) open Rime input method setting pane and click " +
+               "DEPLOY".yellow + " button."
+        puts "Enjoy~ 🍻"
+        puts "more info:".yellow
+        puts "Config path: #{Config::LinuxDistro::ConfigPath}/"
+        return :next
+      end
+    end
+
+    Jobs = [
+      InstallRimeJob,
+      BackupRimeConfigJob,
+      CloneConfigJob,
+      CopyCustomConfigJob
+    ]
+
+    FinishedHook = [FinishedJob]
+  end
+end