view src/luan_editor/editor.luan @ 56:6059b4e22d47

almost fix to front
author Franklin Schmidt <fschmidt@gmail.com>
date Wed, 28 May 2025 16:02:27 -0600
parents d5681da8ece8
children 824f6d74b1d4
line wrap: on
line source

local Luan = require "luan:Luan.luan"
local error = Luan.error
local ipairs = Luan.ipairs 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 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

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
		for _, arg in ipairs(args) do
			local file = new_file(arg)
			new_window(file)
		end
	end
end)

Rpc.serve_socket(server_socket,nil,function(socket,fns)
	swing_run_later(Rpc.new_server_fn(socket,fns))
end)