Skip to content

Commit

Permalink
fix most 0.7 deprecations and errors
Browse files Browse the repository at this point in the history
  • Loading branch information
rdeits committed Jul 21, 2018
1 parent a3c87af commit cc98391
Show file tree
Hide file tree
Showing 11 changed files with 54 additions and 38 deletions.
4 changes: 2 additions & 2 deletions deps/build.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ module BuildBlink
include(joinpath(@__DIR__, "../src/AtomShell/install.jl"))

function get_installed_version()
_path = is_apple() ?
_path = isapple() ?
joinpath(folder(), "version") :
joinpath(folder(), "atom", "version")
strip(readstring(_path), 'v')
strip(read(_path, String), 'v')
end

if isinstalled() && !(version == get_installed_version())
Expand Down
4 changes: 3 additions & 1 deletion src/AtomShell/AtomShell.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module AtomShell

using Compat; import Compat.String
using Compat
using Compat.Sockets
using Compat.Sys: isapple, isunix, islinux, iswindows

abstract type Shell end

Expand Down
14 changes: 7 additions & 7 deletions src/AtomShell/install.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,21 @@ const version = "1.8.6"

folder() = normpath(joinpath(@__FILE__, "../../../deps"))

@static if is_apple()
@static if isapple()
uninstall() = map(rm′, filter(x -> !endswith(x, "build.jl"), readdir(folder())))
else
uninstall() = rm′(joinpath(folder(), "atom"))
end

isinstalled() = is_apple() ?
isinstalled() = isapple() ?
isfile(joinpath(folder(), "version")) :
isdir(joinpath(folder(), "atom"))


function install()
dir = folder()
if is_apple()
const _icons = normpath(joinpath(@__FILE__, "../../../res/julia-icns.icns"))
if isapple()
_icons = normpath(joinpath(@__FILE__, "../../../res/julia-icns.icns"))
end
!isdir(dir) && mkpath(dir)
uninstall()
Expand All @@ -29,7 +29,7 @@ function install()

download("http://junolab.s3.amazonaws.com/blink/julia.png")

if is_apple()
if isapple()
file = "electron-v$version-darwin-x64.zip"
download("https://github.com/electron/electron/releases/download/v$version/$file")
run(`unzip -q $file`)
Expand All @@ -41,15 +41,15 @@ function install()
run(`touch Julia.app`) # Apparently this is necessary to tell the OS to double-check for the new icons.
end

if is_windows()
if iswindows()
arch = Int == Int64 ? "x64" : "ia32"
file = "electron-v$version-win32-$arch.zip"
download("https://github.com/electron/electron/releases/download/v$version/$file")
run(`7z x $file -oatom`)
rm(file)
end

if is_linux()
if islinux()
arch = Int == Int64 ? "x64" : "ia32"
file = "electron-v$version-linux-$arch.zip"
download("https://github.com/electron/electron/releases/download/v$version/$file")
Expand Down
33 changes: 21 additions & 12 deletions src/AtomShell/process.jl
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
using Lazy, JSON, MacroTools

hascommand(c) =
try readstring(`which $c`); true catch e false end
try read(`which $c`, String); true catch e false end

spawn_rdr(cmd) = spawn(cmd, Base.spawn_opts_inherit()...)

resolve(pkg, path...) =
joinpath(Base.find_in_path(pkg, nothing), "..","..", path...) |> normpath
"""
resolve_blink_asset(path...)
Find a file, expressed as a relative path from the Blink package
folder. Example:
resolve_blink_asset("src", "Blink.jl") -> /home/<user>/.julia/v0.6/Blink/src/Blink.jl
"""
resolve_blink_asset(path...) = joinpath(@__DIR__, "..", "..", path...)

@deprecate resolve(pkg, path...) resolve_blink_asset(path...)

# node-inspector

Expand All @@ -27,26 +36,26 @@ end

# atom-shell

import Base: Process, TCPSocket
import Base: Process

export Electron

type Electron <: Shell
mutable struct Electron <: Shell
proc::Process
sock::TCPSocket
handlers::Dict{String, Any}
end

Electron(proc, sock) = Electron(proc, sock, Dict())

@static if is_apple()
const _electron = resolve("Blink", "deps/Julia.app/Contents/MacOS/Julia")
elseif is_linux()
const _electron = resolve("Blink", "deps/atom/electron")
elseif is_windows()
const _electron = resolve("Blink", "deps", "atom", "electron.exe")
@static if isapple()
const _electron = resolve_blink_asset("deps/Julia.app/Contents/MacOS/Julia")
elseif islinux()
const _electron = resolve_blink_asset("deps/atom/electron")
elseif iswindows()
const _electron = resolve_blink_asset("deps", "atom", "electron.exe")
end
const mainjs = resolve("Blink", "src", "AtomShell", "main.js")
const mainjs = resolve_blink_asset("src", "AtomShell", "main.js")

function electron()
path = get(ENV, "ELECTRON_PATH", _electron)
Expand Down
8 changes: 4 additions & 4 deletions src/AtomShell/window.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@ const window_defaults = @d(:url => "about:blank",
:title => "Julia",
"node-integration" => false,
"use-content-size" => true,
:icon => resolve("Blink", "deps", "julia.png"))
:icon => resolve_blink_asset("deps", "julia.png"))

raw_window(a::Electron, opts) = @js a createWindow($(merge(window_defaults, opts)))

function Window(a::Shell, opts::Associative = Dict())
function Window(a::Shell, opts::AbstractDict = Dict())
return haskey(opts, :url) ?
Window(raw_window(a, opts), a, nothing) :
Window(a, Page(), opts)
end

function Window(a::Shell, content::Page, opts::Associative = Dict())
function Window(a::Shell, content::Page, opts::AbstractDict = Dict())
opts = merge(opts, Dict(:url => Blink.localurl(content)))
return Window(raw_window(a, opts), a, content)
end
Expand Down Expand Up @@ -119,7 +119,7 @@ close(win::Window) =

# Window content APIs

active(::Void) = false
active(::Nothing) = false

handlers(w::Window) = handlers(w.content)

Expand Down
7 changes: 5 additions & 2 deletions src/Blink.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@ __precompile__()
module Blink

using Reexport
using Compat; import Compat.String
using Compat
using Compat.Distributed: Future
using Compat.Sys: isunix, islinux, isapple, iswindows
using Compat.Sockets

include("rpc/rpc.jl")
include("content/content.jl")

include("AtomShell/AtomShell.jl")
export AtomShell
@reexport using .AtomShell
import .AtomShell: resolve
import .AtomShell: resolve_blink_asset

end # module
8 changes: 4 additions & 4 deletions src/content/config.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export localips

const ippat = r"([0-9]+\.){3}[0-9]+"

@static if is_unix()
@static if isunix()
localips() = map(IPv4, readlines(`ifconfig` |>
`grep -Eo $("inet (addr:)?$(ippat.pattern)")` |>
`grep -Eo $(ippat.pattern)` |>
Expand All @@ -13,11 +13,11 @@ end

# Browser Window

@static if is_apple()
@static if isapple()
launch(x) = run(`open $x`)
elseif is_linux()
elseif islinux()
launch(x) = run(`xdg-open $x`)
elseif is_windows()
elseif iswindows()
launch(x) = run(`cmd /C start $x`)
end

Expand Down
4 changes: 2 additions & 2 deletions src/content/content.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ include("api.jl")

# Content

type Page
mutable struct Page
id::Int
sock::WebSocket
handlers::Dict{String, Any}
Expand Down Expand Up @@ -52,5 +52,5 @@ end
include("server.jl")

@init for r in ["blink.js", "blink.css", "reset.css", "spinner.css"]
resource(resolve("Blink", "res", r))
resource(resolve_blink_asset("res", r))
end
2 changes: 1 addition & 1 deletion src/rpc/jsexprs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export JSString

jsexpr(io, x) = JSON.print(io, x)

type JSString
mutable struct JSString
s::String
end

Expand Down
4 changes: 2 additions & 2 deletions src/rpc/rpc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
include("jsexprs.jl")
include("callbacks.jl")

type JSError <: Exception
mutable struct JSError <: Exception
name::String
msg::String
end
Expand All @@ -36,7 +36,7 @@ function js(o, js::JSString; callback = true)

if callback
val = wait(cond)
if isa(val, Associative) && get(val, "type", "") == "error"
if isa(val, AbstractDict) && get(val, "type", "") == "error"
err = JSError(get(val, "name", "unknown"), get(val, "message", "blank"))
throw(err)
end
Expand Down
4 changes: 3 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using Blink
using Base.Test
using Compat.Test
using Compat.Sockets


cleanup = !AtomShell.isinstalled()

Expand Down

0 comments on commit cc98391

Please sign in to comment.