37
|
1 local Luan = require "luan:Luan.luan"
|
|
2 local error = Luan.error
|
|
3 local ipairs = Luan.ipairs or error()
|
|
4 local String = require "luan:String.luan"
|
|
5 local contains = String.contains or error()
|
|
6 local Io = require "luan:Io.luan"
|
|
7 local new_file = Io.schemes.file or error()
|
|
8 local Rpc = require "luan:Rpc.luan"
|
|
9 local Swing = require "luan:swing/Swing.luan"
|
|
10 local swing_run = Swing.run or error()
|
|
11 local to_front = Swing.to_front or error()
|
|
12 local new_window = require "classpath:luan_editor/window.luan"
|
|
13 local Logging = require "luan:logging/Logging.luan"
|
|
14 local logger = Logging.logger "editor/editor"
|
|
15
|
|
16
|
|
17 local port = 56587
|
|
18
|
|
19 Rpc.cipher_suites = nil
|
|
20 local server_socket
|
|
21 try
|
|
22 server_socket = Rpc.new_server_socket(port)
|
|
23 catch e
|
|
24 --logger.info(e.get_message())
|
|
25 if not contains( e.get_message(), "java.net.BindException" ) then
|
|
26 e.throw()
|
|
27 end
|
|
28 local host = Rpc.remote("localhost",port)
|
|
29 local args = Luan.arg
|
|
30 for _, arg in ipairs(args) do
|
|
31 local file = new_file(arg)
|
|
32 file = file.canonical().to_string()
|
|
33 host.open(file)
|
|
34 end
|
|
35 host.to_front()
|
|
36 host.close()
|
|
37 return
|
|
38 end
|
|
39 function Rpc.functions.open(file_path)
|
|
40 swing_run(function()
|
|
41 local file = new_file(file_path)
|
|
42 new_window(file)
|
|
43 end)
|
|
44 end
|
|
45 function Rpc.functions.to_front()
|
|
46 swing_run(to_front)
|
|
47 end
|
|
48
|
|
49
|
|
50 swing_run(function()
|
|
51 local args = Luan.arg
|
|
52 if #args == 0 then
|
|
53 new_window()
|
|
54 else
|
|
55 for _, arg in ipairs(args) do
|
|
56 local file = new_file(arg)
|
|
57 new_window(file)
|
|
58 end
|
|
59 end
|
|
60 end)
|
|
61
|
|
62 Rpc.serve_socket(server_socket,nil,false)
|