Skip to content

Commit

Permalink
Refactor windowed logic into a method in build_exe
Browse files Browse the repository at this point in the history
- Extract the windowed logic from build_exe into a new class method windowed?.
- The windowed? method determines if the application should run in windowed mode based on the script extension and force flags.
- This refactoring improves code readability and maintainability by encapsulating the logic in a dedicated method.
  • Loading branch information
shinokaro committed Jun 2, 2024
1 parent 8ec62f5 commit 8f6e072
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions bin/ocran
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,10 @@ EOF
end
end

def self.windowed?
(Ocran.main_script.extname?(".rbw") || Ocran.force_windows) && !Ocran.force_console
end

def Ocran.init(argv)
save_environment
parseargs(argv)
Expand Down Expand Up @@ -741,8 +745,6 @@ EOF

executable = Ocran.output_executable

windowed = (Ocran.main_script.extname?(".rbw") || Ocran.force_windows) && !Ocran.force_console

Ocran.msg "Building #{executable}"
target_script = nil
direction = proc do |sb|
Expand Down Expand Up @@ -772,7 +774,7 @@ EOF
end

# Add the ruby executable and DLL
rubyexe = windowed ? rubyw_exe : ruby_exe
rubyexe = Ocran.windowed? ? rubyw_exe : ruby_exe
Ocran.msg "Adding ruby executable #{rubyexe}"
sb.create_file(bindir / rubyexe, BINDIR / rubyexe)
if libruby_so
Expand Down Expand Up @@ -850,7 +852,7 @@ EOF
debug_extract: Ocran.debug_extract,
debug_mode: Ocran.debug,
enable_compression: Ocran.lzma_mode,
gui_mode: windowed,
gui_mode: Ocran.windowed?,
icon_path: Ocran.icon_filename,
&direction)
Ocran.msg "Finished building #{executable} (#{File.size(executable)} bytes)"
Expand Down

0 comments on commit 8f6e072

Please sign in to comment.