Packages
mob_new
0.1.21
0.4.20
0.4.19
0.4.18
0.4.17
0.4.16
0.4.15
0.4.14
0.4.13
0.4.12
0.4.11
0.4.10
0.4.9
0.4.8
0.4.7
0.4.6
0.4.5
0.4.4
0.4.3
0.4.2
0.4.1
0.4.0
0.3.16
0.3.15
0.3.14
0.3.13
0.3.12
0.3.11
0.3.10
0.3.9
0.3.8
0.3.7
0.3.6
0.3.5
0.3.4
0.3.3
0.3.2
0.3.1
0.3.0
0.2.0
0.1.45
0.1.44
0.1.43
0.1.42
0.1.40
0.1.33
0.1.30
0.1.29
0.1.28
0.1.27
0.1.26
0.1.25
0.1.24
0.1.23
0.1.21
0.1.20
0.1.19
0.1.18
0.1.17
0.1.16
0.1.15
0.1.14
0.1.12
0.1.11
0.1.10
0.1.9
0.1.8
0.1.7
0.1.6
0.1.5
0.1.4
0.1.3
0.1.2
0.1.1
0.1.0
Project generator for the Mob mobile framework
Current section
Files
Jump to
Current section
Files
priv/templates/mob.new/lib/app_name/app.ex.eex
defmodule <%= module_name %>.App do
@moduledoc "Application entry point for <%= display_name %>."
use Mob.App
@impl Mob.App
def navigation(_platform) do
stack(:main, root: <%= module_name %>.HomeScreen)
end
@impl Mob.App
def on_start do
{:ok, _} = Application.ensure_all_started(:ecto_sqlite3)
{:ok, _} = <%= module_name %>.Repo.start_link()
Ecto.Migrator.with_repo(<%= module_name %>.Repo, fn repo ->
Ecto.Migrator.run(repo, migrations_dir(), :up, all: true)
end)
Mob.Screen.start_root(<%= module_name %>.HomeScreen)
Mob.Dist.ensure_started(node: :"<%= app_name %>_android@127.0.0.1", cookie: :mob_secret)
end
# Returns the path to the migrations directory for the current environment.
#
# WHY NOT Application.app_dir/2?
#
# Application.app_dir(app, "priv/repo/migrations") calls :code.priv_dir(app)
# under the hood. That works in a normal `mix run` dev environment where the
# app lives in $OTP_ROOT/lib/APP-VERSION/ebin/.
#
# On Android and iOS, Mob deploys .beam files to a flat -pa directory with no
# versioned lib structure, so :code.priv_dir/1 returns {error, bad_name}.
# Ecto.Migrator.run/3 silently finds zero migrations and logs "Migrations
# already up" — tables are never created and any query against them crashes
# the screen GenServer, making the screen appear frozen.
#
# The fix: mob_beam.c/mob_beam.m set MOB_BEAMS_DIR=beams_dir before erl_start.
# The deployer pushes priv/ into beams_dir/priv/ and runs chmod -R 755 on it
# (mkdir-as-root creates system:system drwxrwx--x dirs that the app process
# can traverse but not list, breaking Path.wildcard). Here we read MOB_BEAMS_DIR
# and pass the explicit path to Ecto.Migrator.run/4.
defp migrations_dir do
case System.get_env("MOB_BEAMS_DIR") do
nil -> Application.app_dir(:<%= app_name %>, "priv/repo/migrations")
beams_dir -> Path.join([beams_dir, "priv", "repo", "migrations"])
end
end
end