Mark24 преди 2 години
родител
ревизия
0436a03a40
променени са 3 файла, в които са добавени 36 реда и са изтрити 78 реда
  1. 34 6
      lib/core.rb
  2. 0 72
      lib/task_manager.rb
  3. 2 0
      os/mac.rb

+ 34 - 6
lib/core.rb

@@ -46,7 +46,7 @@ module RimeDeploy
         @items.each_with_index do |item, index|
           puts "[#{index + 1}] " + item[0]
         end
-        puts "Tips: input the index. e.g: 01"
+        puts "Tips: input the index. e.g: 1"
         puts "Message: #{message}".red if message
         print ">>".green
         choose_mode = gets
@@ -80,7 +80,7 @@ module RimeDeploy
 
   class JobGroup
     def initialize(jobs)
-      @title = "=== Rime Deploy ===="
+      @title = "=== Rime Deploy ====".green
       @queue = []
       jobs.each { |job| @queue << job.new }
 
@@ -107,7 +107,7 @@ module RimeDeploy
       end
 
       if @current_index < @queue.length
-        puts "total: #{@queue.length}".ljust(10)
+        puts "Total: #{@queue.length}".ljust(10)
         puts "Detail " + "-" * 20
       end
     end
@@ -121,15 +121,18 @@ module RimeDeploy
           @current_index += 1
         else
           # 失败处理
+          current_job.rollback if current_job.respond_to? :rollback
           raise RimeDeployError
         end
         print_progress
       rescue RimeDeployError
-        run_jobs_handle
+        what_next
       end
     end
 
     def guidance
+      puts @title
+      puts "welcome to use Rime installer."
       ChooseSession.new(
         [
           [
@@ -148,6 +151,8 @@ module RimeDeploy
     end
 
     def run_jobs_handle
+      system("clear")
+      puts "[Handle Mode]".yellow
       handle_jobs = []
       @queue.each_with_index do |job, index|
         job_intro = job.intro.to_s.ljust(20).green
@@ -155,10 +160,17 @@ module RimeDeploy
           ["#{job_intro}", -> { run_job_with_info_wrapper(job) }]
         )
       end
-      ChooseSession.new(handle_jobs).call
+      begin
+        ChooseSession.new(handle_jobs).call
+        return
+      rescue RimeDeployError
+        what_next
+      end
     end
 
     def run_jobs_auto
+      system("clear")
+      puts "[Auto Mode]".green
       print_progress
       while @current_index < @queue.length
         current_job = @queue[@current_index]
@@ -175,9 +187,25 @@ module RimeDeploy
           end
           print_progress
         rescue RimeDeployError
-          run_jobs_handle
+          what_next
         end
       end
     end
+
+    def reset_status
+      @queue.each { |q| q.status = :waiting }
+    end
+
+    def what_next
+      puts ""
+      puts "Raise an error. Next, you want to...".red
+      ChooseSession.new(
+        [
+          ["Retry", -> {}],
+          ["Change to: Handle mode", -> { run_jobs_handle }],
+          ["Exit", -> { exit 0 }]
+        ]
+      ).call
+    end
   end
 end

+ 0 - 72
lib/task_manager.rb

@@ -1,72 +0,0 @@
-module RimeDeploy
-  class TaskManager
-    def initialize
-      @osname = nil
-      @proxy = nil
-      @queue = nil
-      @current_job = nil
-      check_os
-    end
-
-    def call
-      require "./lib/os/#{@osname}.job.rb"
-      job_group_klass = Object.const_get("#{@osname.capitalize}Jobs")
-      @proxy = job_group_klass.new
-      @queue = @proxy.queue
-      while @queue.size > 0
-        @current_job = proxy.queue.pop
-        job.result = job.exe
-        dispatch_job(result)
-      end
-    end
-
-    def dispatch_job
-      if result == false
-        # 任务失败
-        puts "The job meets errors. What next do you want?"
-        puts "Enter first character : c(ontinue) /e(xit)/ r(etry) /s(kip)"
-        next_step = gets
-        next_step.strip!
-
-        case next_step.strip!
-        when "c"
-          puts "contine..."
-        when "e"
-          puts ""
-          puts "Bye~"
-          exit 0
-        when "r"
-          result = @current_job.rollback
-          if result
-            @queue.push(@current_job)
-            @current_job = nil
-          else
-            puts "#{@current_job.class.to_s} rollback failed."
-          end
-        end
-      end
-    end
-
-    private
-
-    def check_os
-      case RUBY_PLATFORM
-      when /darwin/
-        @osname = "mac"
-      when /linux/
-        @osname = "linux"
-      when /unix/
-        @osname = "unix"
-      when /mswin|win32|mingw|cygwin/
-        @osname = "win"
-        call_exit
-      else
-        call_exit
-      end
-    end
-
-    def call_exit
-      puts "We don't support this system."
-    end
-  end
-end

+ 2 - 0
os/mac.rb

@@ -13,6 +13,7 @@ module RimeDeploy
       def call
         puts "Job: BackupRimeConfigJob".blue
         sleep 1
+        raise RimeDeployError
         # system("mv ~/Library/Rime ~/Library/Rime.#{Time.now.to_i}.old")
         return :next
       end
@@ -33,6 +34,7 @@ module RimeDeploy
       def call
         puts "Job: CopyCustomConfigJob".blue
         sleep 1
+
         # system("cp ./default.custom.yaml ~/Library/Rime/")
         # system("cp ./squirrel.custom.yaml ~/Library/Rime/")
         return :next