mirror of
https://github.com/livebook-dev/livebook.git
synced 2025-10-09 13:07:37 +08:00
Allow overwriting any bundler option per OS (#1213)
This commit is contained in:
parent
fc7328703a
commit
c9f022d637
7 changed files with 130 additions and 58 deletions
|
@ -38,16 +38,22 @@ defmodule WxDemo.MixProject do
|
||||||
name: "WxDemo",
|
name: "WxDemo",
|
||||||
url_schemes: ["wxdemo"],
|
url_schemes: ["wxdemo"],
|
||||||
document_types: [
|
document_types: [
|
||||||
%{
|
[
|
||||||
name: "WxDemo",
|
name: "WxDemo",
|
||||||
extensions: ["wxdemo"],
|
extensions: ["wxdemo"],
|
||||||
macos_role: "Editor"
|
macos: [
|
||||||
}
|
role: "Editor"
|
||||||
|
]
|
||||||
|
]
|
||||||
],
|
],
|
||||||
server: WxDemo,
|
macos: [
|
||||||
macos_build_dmg: macos_notarization != nil,
|
build_dmg: macos_notarization != nil,
|
||||||
macos_notarization: macos_notarization,
|
notarization: macos_notarization
|
||||||
windows_build_installer: true
|
],
|
||||||
|
windows: [
|
||||||
|
server: WxDemo,
|
||||||
|
build_installer: true
|
||||||
|
]
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
|
|
|
@ -1,25 +1,8 @@
|
||||||
defmodule AppBuilder do
|
defmodule AppBuilder do
|
||||||
def bundle(release) do
|
def bundle(release) do
|
||||||
os = os()
|
options = validate_options(release.options[:app])
|
||||||
|
|
||||||
allowed_options = [
|
case os() do
|
||||||
:name,
|
|
||||||
:server,
|
|
||||||
icon_path: [
|
|
||||||
macos: Application.app_dir(:wx, "examples/demo/erlang.png")
|
|
||||||
],
|
|
||||||
url_schemes: [],
|
|
||||||
document_types: [],
|
|
||||||
additional_paths: [],
|
|
||||||
macos_is_agent_app: false,
|
|
||||||
macos_build_dmg: false,
|
|
||||||
macos_notarization: nil,
|
|
||||||
windows_build_installer: true
|
|
||||||
]
|
|
||||||
|
|
||||||
options = Keyword.validate!(release.options[:app], allowed_options)
|
|
||||||
|
|
||||||
case os do
|
|
||||||
:macos ->
|
:macos ->
|
||||||
AppBuilder.MacOS.bundle(release, options)
|
AppBuilder.MacOS.bundle(release, options)
|
||||||
|
|
||||||
|
@ -34,4 +17,72 @@ defmodule AppBuilder do
|
||||||
{:win32, _} -> :windows
|
{:win32, _} -> :windows
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defp validate_options(options) do
|
||||||
|
os = os()
|
||||||
|
|
||||||
|
root_allowed_options = %{
|
||||||
|
all: [
|
||||||
|
:name,
|
||||||
|
:icon_path,
|
||||||
|
url_schemes: [],
|
||||||
|
document_types: [],
|
||||||
|
additional_paths: []
|
||||||
|
],
|
||||||
|
macos: [
|
||||||
|
app_type: :regular,
|
||||||
|
build_dmg: false,
|
||||||
|
notarization: nil
|
||||||
|
],
|
||||||
|
windows: [
|
||||||
|
:server,
|
||||||
|
build_installer: false
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
document_type_allowed_options = %{
|
||||||
|
all: [
|
||||||
|
:name,
|
||||||
|
:extensions,
|
||||||
|
:icon_path
|
||||||
|
],
|
||||||
|
macos: [
|
||||||
|
:role
|
||||||
|
],
|
||||||
|
windows: []
|
||||||
|
}
|
||||||
|
|
||||||
|
options = validate_options(options, root_allowed_options, os)
|
||||||
|
|
||||||
|
Keyword.update!(options, :document_types, fn document_types ->
|
||||||
|
Enum.map(document_types, fn options ->
|
||||||
|
validate_options(options, document_type_allowed_options, os)
|
||||||
|
end)
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
|
defp validate_options(options, allowed, os) do
|
||||||
|
{macos_options, options} = Keyword.pop(options, :macos, [])
|
||||||
|
{windows_options, options} = Keyword.pop(options, :windows, [])
|
||||||
|
|
||||||
|
options_per_os = %{
|
||||||
|
macos: macos_options,
|
||||||
|
windows: windows_options
|
||||||
|
}
|
||||||
|
|
||||||
|
options = Keyword.validate!(options, allowed.all)
|
||||||
|
options_for_os = Map.fetch!(options_per_os, os)
|
||||||
|
|
||||||
|
allowed_without_defaults =
|
||||||
|
for option <- allowed.all do
|
||||||
|
case option do
|
||||||
|
atom when is_atom(atom) -> atom
|
||||||
|
{atom, _default} when is_atom(atom) -> atom
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
allowed_for_os = allowed_without_defaults ++ Map.fetch!(allowed, os)
|
||||||
|
os_options = Keyword.validate!(options_for_os, allowed_for_os)
|
||||||
|
Keyword.merge(options, os_options)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -33,13 +33,15 @@ defmodule AppBuilder.MacOS do
|
||||||
launcher_src_path
|
launcher_src_path
|
||||||
])
|
])
|
||||||
|
|
||||||
icon_path = Keyword.fetch!(options, :icon_path)
|
icon_path =
|
||||||
|
Keyword.get(options, :icon_path, Application.app_dir(:wx, "examples/demo/erlang.png"))
|
||||||
|
|
||||||
dest_path = "#{resources_path}/AppIcon.icns"
|
dest_path = "#{resources_path}/AppIcon.icns"
|
||||||
create_icon(icon_path, dest_path)
|
create_icon(icon_path, dest_path)
|
||||||
|
|
||||||
for type <- Keyword.fetch!(options, :document_types) do
|
for type <- Keyword.fetch!(options, :document_types) do
|
||||||
if src_path = type[:icon_path] do
|
if src_path = Keyword.get(type, :icon_path, icon_path) do
|
||||||
dest_path = "#{resources_path}/#{type.name}Icon.icns"
|
dest_path = "#{resources_path}/#{type[:name]}Icon.icns"
|
||||||
create_icon(src_path, dest_path)
|
create_icon(src_path, dest_path)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -30,11 +30,15 @@ defmodule AppBuilder.Windows do
|
||||||
vcredist_path = ensure_vcredistx64()
|
vcredist_path = ensure_vcredistx64()
|
||||||
copy_file(vcredist_path, "#{app_path}/vcredist_x64.exe")
|
copy_file(vcredist_path, "#{app_path}/vcredist_x64.exe")
|
||||||
|
|
||||||
create_icon(options[:icon_path], "#{app_path}/AppIcon.ico")
|
icon_path = options[:icon_path]
|
||||||
|
|
||||||
|
if icon_path do
|
||||||
|
create_icon(icon_path, "#{app_path}/AppIcon.ico")
|
||||||
|
end
|
||||||
|
|
||||||
for type <- Keyword.fetch!(options, :document_types) do
|
for type <- Keyword.fetch!(options, :document_types) do
|
||||||
if src_path = type[:icon_path] do
|
if src_path = Keyword.get(type, :icon_path, icon_path) do
|
||||||
dest_path = "#{app_path}/#{type.name}Icon.ico"
|
dest_path = "#{app_path}/#{type[:name]}Icon.ico"
|
||||||
create_icon(src_path, dest_path)
|
create_icon(src_path, dest_path)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -41,25 +41,25 @@
|
||||||
<%= for type <- types do %>
|
<%= for type <- types do %>
|
||||||
<dict>
|
<dict>
|
||||||
<key>CFBundleTypeName</key>
|
<key>CFBundleTypeName</key>
|
||||||
<string><%= type.name %></string>
|
<string><%= type[:name] %></string>
|
||||||
<key>CFBundleTypeRole</key>
|
<key>CFBundleTypeRole</key>
|
||||||
<string><%= type.macos_role %></string>
|
<string><%= type[:role] %></string>
|
||||||
<key>CFBundleTypeExtensions</key>
|
<key>CFBundleTypeExtensions</key>
|
||||||
<array>
|
<array>
|
||||||
<%= for ext <- type.extensions do %>
|
<%= for ext <- type[:extensions] do %>
|
||||||
<string><%= ext %></string>
|
<string><%= ext %></string>
|
||||||
<% end %>
|
<% end %>
|
||||||
</array>
|
</array>
|
||||||
<%= if type[:icon_path] do %>
|
<%= if type[:icon_path] do %>
|
||||||
<key>CFBundleTypeIconFile</key>
|
<key>CFBundleTypeIconFile</key>
|
||||||
<string><%= type.name %>Icon</string>
|
<string><%= type[:name] %>Icon</string>
|
||||||
<% end %>
|
<% end %>
|
||||||
</dict>
|
</dict>
|
||||||
<% end %>
|
<% end %>
|
||||||
</array>
|
</array>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<%= if @app_options[:macos_is_agent_app] do %>
|
<%= if @app_options[:app_type] == :agent do %>
|
||||||
<key>LSUIElement</key>
|
<key>LSUIElement</key>
|
||||||
<true/>
|
<true/>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
|
@ -23,7 +23,9 @@ RequestExecutionLevel admin
|
||||||
;Pages
|
;Pages
|
||||||
|
|
||||||
;!insertmacro MUI_PAGE_COMPONENTS
|
;!insertmacro MUI_PAGE_COMPONENTS
|
||||||
|
<%= if @app_options[:icon_path] do %>
|
||||||
!define MUI_ICON "AppIcon.ico"
|
!define MUI_ICON "AppIcon.ico"
|
||||||
|
<% end %>
|
||||||
!insertmacro MUI_PAGE_DIRECTORY
|
!insertmacro MUI_PAGE_DIRECTORY
|
||||||
!insertmacro MUI_PAGE_INSTFILES
|
!insertmacro MUI_PAGE_INSTFILES
|
||||||
|
|
||||||
|
@ -46,18 +48,22 @@ Section "Install"
|
||||||
|
|
||||||
File /r rel rel
|
File /r rel rel
|
||||||
File "<%= app_name %>Launcher.vbs"
|
File "<%= app_name %>Launcher.vbs"
|
||||||
|
<%= if @app_options[:icon_path] do %>
|
||||||
File "AppIcon.ico"
|
File "AppIcon.ico"
|
||||||
|
<% end %>
|
||||||
|
|
||||||
CreateDirectory "$INSTDIR\Logs"
|
CreateDirectory "$INSTDIR\Logs"
|
||||||
WriteUninstaller "$INSTDIR\<%= app_name %>Uninstall.exe"
|
WriteUninstaller "$INSTDIR\<%= app_name %>Uninstall.exe"
|
||||||
|
|
||||||
<%= for type <- Keyword.fetch!(@app_options, :document_types) do %>
|
<%= for type <- Keyword.fetch!(@app_options, :document_types) do %>
|
||||||
<%= for ext <- type.extensions do %>
|
<%= for ext <- type[:extensions] do %>
|
||||||
WriteRegStr HKCR ".<%= ext %>" "" "<%= app_name %>.<%= type.name %>"
|
WriteRegStr HKCR ".<%= ext %>" "" "<%= app_name %>.<%= type[:name] %>"
|
||||||
<% end %>
|
<% end %>
|
||||||
WriteRegStr HKCR "<%= app_name %>.<%= type.name %>" "" "<%= type.name %>"
|
WriteRegStr HKCR "<%= app_name %>.<%= type[:name] %>" "" "<%= type[:name] %>"
|
||||||
WriteRegStr HKCR "<%= app_name %>.<%= type.name %>\DefaultIcon" "" "$INSTDIR\<%= type.name %>Icon.ico"
|
<%= if type[:icon_path] || @app_options[:icon_path] do %>
|
||||||
WriteRegStr HKCR "<%= app_name %>.<%= type.name %>\shell\open\command" "" '$WINDIR\system32\wscript.exe "$INSTDIR\<%= app_name %>Launcher.vbs" "open_file:%1"'
|
WriteRegStr HKCR "<%= app_name %>.<%= type[:name] %>\DefaultIcon" "" "$INSTDIR\<%= type[:name] %>Icon.ico"
|
||||||
|
<% end %>
|
||||||
|
WriteRegStr HKCR "<%= app_name %>.<%= type[:name] %>\shell\open\command" "" '$WINDIR\system32\wscript.exe "$INSTDIR\<%= app_name %>Launcher.vbs" "open_file:%1"'
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<%= for url_scheme <- Keyword.fetch!(@app_options, :url_schemes) do %>
|
<%= for url_scheme <- Keyword.fetch!(@app_options, :url_schemes) do %>
|
||||||
|
@ -72,7 +78,7 @@ Section "Install"
|
||||||
SectionEnd
|
SectionEnd
|
||||||
|
|
||||||
Section "Desktop Shortcut"
|
Section "Desktop Shortcut"
|
||||||
CreateShortCut "$DESKTOP\<%= app_name %>.lnk" "$INSTDIR\<%= app_name %>Launcher.vbs" "" "$INSTDIR\AppIcon.ico"
|
CreateShortCut "$DESKTOP\<%= app_name %>.lnk" "$INSTDIR\<%= app_name %>Launcher.vbs" "" <%= if @app_options[:icon_path] do %> "$INSTDIR\AppIcon.ico" <% end %>
|
||||||
SectionEnd
|
SectionEnd
|
||||||
|
|
||||||
Section "Uninstall"
|
Section "Uninstall"
|
||||||
|
|
33
mix.exs
33
mix.exs
|
@ -146,31 +146,34 @@ defmodule Livebook.MixProject do
|
||||||
],
|
],
|
||||||
app: [
|
app: [
|
||||||
name: "Livebook",
|
name: "Livebook",
|
||||||
icon_path: [
|
|
||||||
macos: "rel/app/icon-macos.png",
|
|
||||||
windows: "rel/app/icon.ico"
|
|
||||||
],
|
|
||||||
url_schemes: ["livebook"],
|
url_schemes: ["livebook"],
|
||||||
document_types: [
|
document_types: [
|
||||||
%{
|
[
|
||||||
name: "LiveMarkdown",
|
name: "LiveMarkdown",
|
||||||
extensions: ["livemd"],
|
extensions: ["livemd"],
|
||||||
icon_path: [
|
macos: [
|
||||||
macos: "rel/app/icon.png",
|
icon_path: "rel/app/icon.png",
|
||||||
windows: "rel/app/icon.ico"
|
role: "Editor"
|
||||||
],
|
],
|
||||||
macos_role: "Editor"
|
windows: [
|
||||||
}
|
icon_path: "rel/app/icon.ico"
|
||||||
|
]
|
||||||
|
]
|
||||||
],
|
],
|
||||||
additional_paths: [
|
additional_paths: [
|
||||||
"rel/erts-#{:erlang.system_info(:version)}/bin",
|
"rel/erts-#{:erlang.system_info(:version)}/bin",
|
||||||
"rel/vendor/elixir/bin"
|
"rel/vendor/elixir/bin"
|
||||||
],
|
],
|
||||||
server: LivebookApp,
|
macos: [
|
||||||
macos_is_agent_app: true,
|
icon_path: "rel/app/icon-macos.png",
|
||||||
macos_build_dmg: macos_notarization != nil,
|
build_dmg: macos_notarization != nil,
|
||||||
macos_notarization: macos_notarization,
|
notarization: macos_notarization
|
||||||
windows_build_installer: true
|
],
|
||||||
|
windows: [
|
||||||
|
server: LivebookApp,
|
||||||
|
icon_path: "rel/app/icon.ico",
|
||||||
|
build_installer: true
|
||||||
|
]
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
|
|
Loading…
Add table
Reference in a new issue