浏览代码

feat: add finished hooks

Mark24 2 年之前
父节点
当前提交
90f2866279
共有 3 个文件被更改,包括 24 次插入10 次删除
  1. 3 1
      installer.rb
  2. 6 1
      lib/core.rb
  3. 15 8
      os/mac.rb

+ 3 - 1
installer.rb

@@ -39,7 +39,9 @@ module RimeDeploy
       code = <<-CODE
   class #{os_prefix}JobGroup < JobGroup
   end
-  #{os_prefix}JobGroup.new(#{os_prefix}::Jobs).call
+  mod = #{os_prefix}JobGroup.new(#{os_prefix}::Jobs, #{os_prefix}::FinishedHook)
+  mod.call
+
 CODE
       instance_eval(code)
     end

+ 6 - 1
lib/core.rb

@@ -79,12 +79,15 @@ module RimeDeploy
   end
 
   class JobGroup
-    def initialize(jobs)
+    def initialize(jobs, finished_hooks)
       @title = "=== Rime Deploy ====".green
       @queue = []
       jobs.each { |job| @queue << job.new }
 
       @current_index = 0
+
+      @finished_queue = []
+      finished_hooks.each { |job| @finished_queue << job.new }
     end
 
     def print_progress
@@ -148,6 +151,8 @@ module RimeDeploy
     end
     def call
       guidance
+
+      @finished_queue.each { |job| job.call }
     end
 
     def run_jobs_handle

+ 15 - 8
os/mac.rb

@@ -3,7 +3,7 @@ module RimeDeploy
     class InstallRimeJob < Job
       def call
         puts intro
-        system("brew install --cask squirrel")
+        # system("brew install --cask squirrel")
         return :next
       end
     end
@@ -11,7 +11,7 @@ module RimeDeploy
     class BackupRimeConfigJob < Job
       def call
         puts "Job: BackupRimeConfigJob".blue
-        system("mv ~/Library/Rime ~/Library/Rime.#{Time.now.to_i}.old")
+        # system("mv ~/Library/Rime ~/Library/Rime.#{Time.now.to_i}.old")
         return :next
       end
     end
@@ -19,7 +19,7 @@ module RimeDeploy
     class CloneConfigJob < Job
       def call
         puts intro
-        system("git clone https://github.com/iDvel/rime-ice.git ~/Library/Rime")
+        # system("git clone https://github.com/iDvel/rime-ice.git ~/Library/Rime")
         return :next
       end
     end
@@ -27,15 +27,21 @@ module RimeDeploy
     class CopyCustomConfigJob < Job
       def call
         puts intro
-        system("cp ./custom/default.custom.yaml ~/Library/Rime/")
-        system("cp ./custom/squirrel.custom.yaml ~/Library/Rime/")
+        # system("cp ./custom/default.custom.yaml ~/Library/Rime/")
+        # system("cp ./custom/squirrel.custom.yaml ~/Library/Rime/")
         return :next
       end
     end
 
     class FinishedJob < Job
       def call
-        puts "Please restart system then open Rime Setting and click DEPLOY."
+        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: ~/Library/Rime/"
         return :next
       end
     end
@@ -44,8 +50,9 @@ module RimeDeploy
       InstallRimeJob,
       BackupRimeConfigJob,
       CloneConfigJob,
-      CopyCustomConfigJob,
-      FinishedJob
+      CopyCustomConfigJob
     ]
+
+    FinishedHook = [FinishedJob]
   end
 end