From 297219f5c14845bf75de4475cabab4dbf6e6599d Mon Sep 17 00:00:00 2001 From: Eben60 Date: Sat, 11 Jan 2025 13:56:30 +0100 Subject: [PATCH] =?UTF-8?q?macro=20@unsafe=20refactoring.=20=E2=86=91v0.1.?= =?UTF-8?q?6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Project.toml | 4 +++- src/PackageMaker.jl | 4 ++++ src/macro_unsafe.jl | 41 +++++++++++++++++++++++++++++++++++++++++ src/processvals.jl | 35 ----------------------------------- 4 files changed, 48 insertions(+), 36 deletions(-) create mode 100644 src/macro_unsafe.jl diff --git a/Project.toml b/Project.toml index 1f59aad..9a88132 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "PackageMaker" uuid = "29c12bd1-d721-479e-9f19-f3213c237221" authors = ["Eben60"] -version = "0.1.5" +version = "0.1.6" [deps] Blink = "ad839575-38b3-5650-b840-f874b8c74a25" @@ -13,6 +13,7 @@ LibGit2 = "76f85450-5226-5b5a-8eaa-529ad045b433" NativeFileDialog = "e1fe445b-aa65-4df4-81c1-2041507f0fd4" Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" PkgTemplates = "14b8a8f1-9102-5b29-a752-f990bacb7fe1" +Sockets = "6462fe0b-24de-5631-8697-dd941f90decc" TOML = "fa267f1f-6049-4f14-aa54-33bafae1ed76" UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4" @@ -33,6 +34,7 @@ LibGit2 = "<0.0.1, 1" NativeFileDialog = "0.2.1" Pkg = "1.10" PkgTemplates = "=0.7.53" +Sockets = "<0.0.1, 1" TOML = "1.0.3" UUIDs = "<0.0.1, 1" julia = "1.10" diff --git a/src/PackageMaker.jl b/src/PackageMaker.jl index b9d02ec..a56c47d 100644 --- a/src/PackageMaker.jl +++ b/src/PackageMaker.jl @@ -40,6 +40,10 @@ include("html.jl") include("blink_interactions.jl") include("handleinput.jl") +include("macro_unsafe.jl") +using .MacroUnsafe +export @unsafe + include("jld2_to_extend.jl") export gogui diff --git a/src/macro_unsafe.jl b/src/macro_unsafe.jl new file mode 100644 index 0000000..0dde2d8 --- /dev/null +++ b/src/macro_unsafe.jl @@ -0,0 +1,41 @@ +module MacroUnsafe + +using Blink, Blink.AtomShell +using Sockets: @ip_str + +using Blink.AtomShell: port, inspector, try_connect, electron, initcbs, mainjs + +""" + @unsafe + +A workaround for an upstream bug on Ubuntu 24. It disables sandboxing in Electron. +Run this macro before calling `gogui()`. + +The recommended way of using PackageMaker on Ubuntu 24 is however to use from VSCode, as +in this case it works OK without calling `@unsafe` + +# Examples +```julia-repl +julia> @unsafe; +julia> gogui() +``` +""" +macro unsafe() # https://github.com/JuliaGizmos/Blink.jl/issues/325#issuecomment-2252670794 + return quote + function Blink.AtomShell.init(; debug = false) + electron() # Check path exists + p, dp = port(), port() + debug && inspector(dp) + dbg = debug ? "--debug=$dp" : [] + proc = (debug ? run_rdr : run)( + `$(electron()) --no-sandbox $dbg $mainjs port $p`; wait=false) + conn = try_connect(ip"127.0.0.1", p) + shell = Electron(proc, conn) + initcbs(shell) + return shell + end + end +end +export @unsafe + +end \ No newline at end of file diff --git a/src/processvals.jl b/src/processvals.jl index 6145996..729dd4a 100644 --- a/src/processvals.jl +++ b/src/processvals.jl @@ -326,41 +326,6 @@ Starts the GUI. If `exitjulia` is `true`, then after the GUI is exited and the p """ gogui(exitjulia=true) = (_gogui(exitjulia); return nothing) -""" - @unsafe - -A workaround for an upstream bug on Ubuntu 24. It disables sandboxing in Electron. -Run this macro before calling `gogui()`. - -The recommended way of using PackageMaker on Ubuntu 24 is however to use from VSCode, as -in this case it works OK without calling `@unsafe` - -# Examples -```julia-repl -julia> @unsafe; -julia> gogui() -``` -""" -macro unsafe() # https://github.com/JuliaGizmos/Blink.jl/issues/325#issuecomment-2252670794 - return @eval AtomShell begin - function init(; debug = false) - electron() # Check path exists - p, dp = port(), port() - debug && inspector(dp) - dbg = debug ? "--debug=$dp" : [] - proc = (debug ? run_rdr : run)( - `$(electron()) --no-sandbox $dbg $mainjs port $p`; wait=false) - conn = try_connect(ip"127.0.0.1", p) - shell = Electron(proc, conn) - initcbs(shell) - return shell - end - end - end -export @unsafe - - - startyourpk(args...; kwargs...) = @warn "Function startyourpk is deprecated as of v.0.0.9. Please use gogui instead" export startyourpk