changeset 59:824f6d74b1d4

use launcher
author Franklin Schmidt <fschmidt@gmail.com>
date Wed, 04 Jun 2025 18:21:45 -0600
parents 7e2d6426c155
children 855669ece914
files src/luan_editor/Window.luan src/luan_editor/editor.luan
diffstat 2 files changed, 26 insertions(+), 46 deletions(-) [+]
line wrap: on
line diff
--- a/src/luan_editor/Window.luan	Fri May 30 13:17:51 2025 -0600
+++ b/src/luan_editor/Window.luan	Wed Jun 04 18:21:45 2025 -0600
@@ -27,8 +27,6 @@
 local create_empty_border = Border.create_empty_border or error()
 local new_label = require("luan:swing/Label.luan").new or error()
 local make_find_panel = require "classpath:luan_editor/find.luan"
-local Swing = require "luan:swing/Swing.luan"
-local run_later = Swing.run_later or error()
 local File_chooser = require "luan:swing/File_chooser.luan"
 local choose_file = File_chooser.awt_choose_file or error()
 local Option_pane = require "luan:swing/Option_pane.luan"
--- a/src/luan_editor/editor.luan	Fri May 30 13:17:51 2025 -0600
+++ b/src/luan_editor/editor.luan	Wed Jun 04 18:21:45 2025 -0600
@@ -1,56 +1,21 @@
 local Luan = require "luan:Luan.luan"
 local error = Luan.error
 local ipairs = Luan.ipairs or error()
+local stringify = Luan.stringify or error()
 local String = require "luan:String.luan"
-local contains = String.contains or error()
 local to_number = String.to_number or error()
 local Io = require "luan:Io.luan"
 local new_file = Io.schemes.file or error()
-local Rpc = require "luan:Rpc.luan"
-local Swing = require "luan:swing/Swing.luan"
-local swing_run = Swing.run or error()
-local swing_run_later = Swing.run_later or error()
-local Window = require "classpath:luan_editor/Window.luan"
-local new_window = Window.new_window or error()
-local open_windows = Window.open_windows or error()
+local Launcher = require "luan:swing/Launcher.luan"
 local Java = require "classpath:luan_editor/Java.luan"
 local Logging = require "luan:logging/Logging.luan"
 local logger = Logging.logger "editor/editor"
 
 
-local port = Java.port
-if port == nil then
-	port = 56587
-else
-	port = to_number(port) or error("bad port: "..port)
-end
+local function open(args)
+	local Window = require "classpath:luan_editor/Window.luan"
+	local new_window = Window.new_window or error()
 
-Rpc.cipher_suites = nil
-local server_socket
-try
-	server_socket = Rpc.new_server_socket(port)
-catch e
-	--logger.info(e.get_message())
-	if not contains( e.get_message(), "java.net.BindException" ) then
-		e.throw()
-	end
-	local host = Rpc.remote("localhost",port)
-	local args = Luan.arg
-	local file_paths = {}
-	for _, arg in ipairs(args) do
-		local file = new_file(arg)
-		file = file.canonical().to_string()
-		file_paths[#file_paths+1] = file
-	end
-	host.open_windows(file_paths)
-	host.close()
-	return
-end
-
-Rpc.functions.open_windows = open_windows
-
-swing_run(function()
-	local args = Luan.arg
 	if #args == 0 then
 		new_window()
 	else
@@ -59,8 +24,25 @@
 			new_window(file)
 		end
 	end
-end)
+end
+
+local function reopen(args)
+	local Window = require "classpath:luan_editor/Window.luan"
+	local open_windows = Window.open_windows or error()
+
+	open_windows(args)
+end
 
-Rpc.serve_socket(server_socket,nil,function(socket,fns)
-	swing_run_later(Rpc.new_server_fn(socket,fns))
-end)
+local port = Java.port
+if port ~= nil then
+	Launcher.port = to_number(port) or error("bad port: "..port)
+end
+
+local args = {nil}
+for _, arg in ipairs(Luan.arg) do
+	local file = new_file(arg)
+	file = file.canonical().to_string()
+	args[#args+1] = file
+end
+
+Launcher.launch(open,reopen,args)