Skip to content

Commit a74e792

Browse files
author
Jason Mobarak
authored
Unify splash and entrypoint [CPP-769] (#584)
Jira: https://swift-nav.atlassian.net/browse/CPP-769 Test release here: https://github.com/swift-nav/swift-toolbox/releases/tag/v4.0.7-unify-splash The splash screen launching as a separate process on macOS causes some strange interactions with the launcher bar in that basically you can't pin the app (it looks like this is because it loses track of what the main window of the app is). Instead of doing this outside of Qt, do it inside Qt... this also vastly simplifies the implementation of the splash screen (which is probably what we should have done from the start, but ~this was my fault for encouraging the over-engineering here~ looks like this doesn't really work on Linux... since we already have the code for the hacky splash screen, we'll just use it on Linux).
1 parent fcf7a22 commit a74e792

File tree

23 files changed

+398
-294
lines changed

23 files changed

+398
-294
lines changed

.github/workflows/main.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,11 @@ jobs:
9292
path: ${{ env.PIP_CACHE_DIR }}
9393
key: ${{ runner.os }}-pyproject-toml-${{ secrets.CACHE_VERSION }}-${{ hashFiles('pyproject.toml') }}
9494

95+
- name: Install ImageMagick
96+
shell: bash
97+
run: |
98+
cargo make install-imagemagick
99+
95100
- name: Set up python builder
96101
shell: bash
97102
run: |
@@ -160,6 +165,11 @@ jobs:
160165
path: ${{ env.PIP_CACHE_DIR }}
161166
key: ${{ runner.os }}-pyproject-toml-${{ secrets.CACHE_VERSION }}-${{ hashFiles('pyproject.toml') }}
162167

168+
- name: Install ImageMagick
169+
shell: bash
170+
run: |
171+
cargo make install-imagemagick
172+
163173
- name: Set up python builder
164174
run: |
165175
cargo make setup-builder

Cargo.lock

Lines changed: 9 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Makefile.toml

Lines changed: 40 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -122,14 +122,11 @@ exec --fail-on-error ${python} -m py2many --rust=1 /tmp/piksi_tools_constants.py
122122
'''
123123

124124
[tasks.generate-resources]
125-
command = "${PYSIDE2_RCC}"
126-
args = [
127-
"resources/console_resources.qrc",
128-
"-o",
129-
"swiftnav_console/console_resources.py",
130-
"-g",
131-
"python",
132-
]
125+
dependencies = ["build-splash-version"]
126+
script_runner = "@duckscript"
127+
script = '''
128+
exec --fail-on-error "${PYSIDE2_RCC}" "resources/console_resources.qrc" "-o" "swiftnav_console/console_resources.py" "-g" "python"
129+
'''
133130

134131
[tasks.check-capnp]
135132
script_runner = "@shell"
@@ -357,7 +354,6 @@ script = "sudo apt-get install gsfonts imagemagick"
357354
script = "brew install imagemagick"
358355

359356
[tasks.build-splash-version]
360-
private = true
361357
script_runner = "@duckscript"
362358
script = '''
363359
output = exec --fail-on-error git describe --always --tags --dirty
@@ -370,30 +366,39 @@ else
370366
end
371367
'''
372368

373-
[tasks.build-splash-bin]
374-
private = true
369+
[tasks.build-windowpos-bin]
375370
dependencies = ["build-splash-version"]
376371
command = "cargo"
377372
args = [
378373
"build",
379374
"--release",
380375
"-vv",
381376
"--features",
382-
"splash",
377+
"winit",
383378
"--bin",
384-
"swift-console-splash",
379+
"windowpos",
385380
]
386381

387382
[tasks.build-console-bin]
388-
private = true
389-
dependencies = ["build-splash-bin"]
383+
command = "cargo"
384+
args = [
385+
"build",
386+
"--release",
387+
"-vv",
388+
"--features=entrypoint",
389+
"--bin",
390+
"${APP_NAME}",
391+
]
392+
393+
[tasks.build-console-bin.linux]
394+
dependencies = ["build-windowpos-bin"]
390395
command = "cargo"
391396
args = [
392397
"build",
393398
"--release",
394399
"-vv",
395400
"--features",
396-
"entrypoint",
401+
"entrypoint,splash",
397402
"--bin",
398403
"${APP_NAME}",
399404
]
@@ -412,19 +417,21 @@ script_runner = "@duckscript"
412417
script = '''
413418
app_name = get_env APP_NAME
414419
cp target/release/${app_name} py39-dist/${app_name}
415-
cp target/release/swift-console-splash py39-dist/swift-console-splash
416420
os = os_family
417421
if eq ${os} mac
418422
exec --fail-on-error install_name_tool -change /install/lib/libpython3.9.dylib @executable_path/lib/libpython3.9.dylib py39-dist/${app_name}
423+
elseif eq ${os} linux
424+
cp target/release/windowpos py39-dist/windowpos
419425
end
420426
'''
421427

422428
[tasks.build-dist-install-console.windows]
423429
script = '''
424-
cp target/release/swift-console-splash.exe py39-dist/swift-console-splash.exe
425430
cp target/release/${APP_NAME}.exe py39-dist/${APP_NAME}.exe
426431
cp target/release/${APP_NAME}.d py39-dist/${APP_NAME}.d
427-
cp target/release/swift_console.pdb py39-dist/swift_console.pdb
432+
if is_path_exists target/release/swift_console.pdb
433+
cp target/release/swift_console.pdb py39-dist/swift_console.pdb
434+
end
428435
cp target/x86_64-pc-windows-msvc/release/console_backend.pdb py39-dist/Lib/site-packages/console_backend/console_backend.pdb
429436
'''
430437

@@ -688,7 +695,6 @@ mkdir ${contents_dir}
688695
mkdir ${contents_mac_os}
689696
exec --fail-on-error cp -r py39-dist "${contents_resources_dir}"
690697
exec --fail-on-error mv ./${contents_resources_dir}/${app_original_name} "./${contents_mac_os}/${app_file_prefix}"
691-
exec --fail-on-error mv ./${contents_resources_dir}/swift-console-splash "./${contents_mac_os}/swift-console-splash"
692698
exec --fail-on-error ln -s "../Resources/lib" ${contents_mac_os}/lib
693699
exec --fail-on-error ln -s "../Resources/.frozen" ${contents_mac_os}/.frozen
694700
exec --fail-on-error ln -s "../Resources/resources" ${contents_mac_os}/resources
@@ -885,6 +891,20 @@ dependencies = ["store-version", "copy-capnp"]
885891
command = "cargo"
886892
args = ["check"]
887893

894+
[tasks.watch-entrypoint]
895+
dependencies = ["store-version", "copy-capnp"]
896+
command = "cargo"
897+
args = [
898+
"watch",
899+
"--exec",
900+
"check --bin swift-console --features=entrypoint,splash",
901+
]
902+
903+
[tasks.watch-windowpos]
904+
dependencies = ["store-version", "copy-capnp"]
905+
command = "cargo"
906+
args = ["watch", "--exec", "check --bin windowpos --features=winit"]
907+
888908
[tasks.python-type-check]
889909
dependencies = ["set-python-files"]
890910
command = "${PYTHON}"

console_backend/src/common_constants.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,6 @@ pub enum ApplicationMetadata {
335335
ORGANIZATION_NAME,
336336
#[strum(serialize = "swiftnav.com")]
337337
ORGANIZATION_DOMAIN,
338-
#[strum(serialize = "swift-toolbox")]
338+
#[strum(serialize = "Swift Console")]
339339
APPLICATION_NAME,
340340
}

entrypoint/Cargo.toml

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,37 +17,31 @@ required-features = ["entrypoint"]
1717

1818
[[bin]]
1919
bench = false
20-
name = "swift-console-splash"
21-
path = "src/splash.rs"
22-
required-features = ["splash"]
20+
name = "windowpos"
21+
path = "src/windowpos.rs"
22+
required-features = ["winit"]
2323

2424
[dependencies.lazy_static]
25-
optional = true
2625
version = "1.4.0"
2726

27+
[dependencies.image]
28+
version = "0.24.2"
29+
2830
[dependencies.winit]
29-
optional = true
3031
version = "0.26.1"
31-
32-
[dependencies.image]
3332
optional = true
34-
version = "0.24.2"
3533

3634
[dependencies.minifb]
37-
optional = true
3835
default-features = false
3936
features = ["x11"]
4037
version = "0.23"
38+
optional = true
4139

4240
[dependencies.pyo3]
4341
default-features = false
4442
features = ["auto-initialize"]
45-
optional = true
4643
version = "0.16"
47-
48-
[features]
49-
entrypoint = ["pyo3", "windows"]
50-
splash = ["minifb", "image", "winit", "windows", "lazy_static"]
44+
optional = true
5145

5246
[target]
5347
[target."cfg(target_os = \"windows\")"]
@@ -58,5 +52,10 @@ version = "0.1"
5852
[target."cfg(target_os = \"windows\")".dependencies]
5953
[target."cfg(target_os = \"windows\")".dependencies.windows]
6054
features = ["Win32_System_Console", "Win32_Foundation"]
61-
optional = true
6255
version = ">=0.24"
56+
optional = true
57+
58+
[features]
59+
default = []
60+
entrypoint = ["pyo3", "windows", "minifb"]
61+
splash = []

entrypoint/build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#[cfg(target_os = "windows")]
1+
#[cfg(target_os = "windows")]
22
use winres::WindowsResource;
33
type Result<T> = std::result::Result<T, Box<dyn std::error::Error>>;
44

entrypoint/src/lib.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,26 @@
1+
use std::io::Cursor;
2+
3+
use lazy_static::lazy_static;
4+
5+
#[cfg(feature = "splash")]
6+
pub mod splash;
7+
8+
pub type Error = Box<dyn std::error::Error>;
9+
pub type Result<T> = std::result::Result<T, Error>;
10+
11+
lazy_static! {
12+
pub static ref SPLASH_IMAGE: image::DynamicImage = {
13+
let splash_image_buf = include_bytes!(concat!("../../", env!("CONSOLE_SPLASH_IMAGE")));
14+
image::io::Reader::with_format(
15+
std::io::BufReader::new(Cursor::new(splash_image_buf)),
16+
image::ImageFormat::Jpeg,
17+
)
18+
.decode()
19+
.expect("could not decode splash image")
20+
};
21+
}
22+
23+
#[cfg(feature = "entrypoint")]
124
pub fn attach_console() {
225
#[cfg(target_os = "windows")]
326
{

entrypoint/src/main.rs

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
#![cfg_attr(target_os = "windows", windows_subsystem = "windows")]
2-
3-
type Result<T> = std::result::Result<T, Box<dyn std::error::Error>>;
1+
#![cfg_attr(target_os = "windows", windows_subsystem = "windows")]
42

53
use pyo3::prelude::*;
64
use pyo3::types::PyTuple;
75

86
use entrypoint::attach_console;
97

10-
const SWIFT_CONSOLE_PID: &str = "SWIFT_CONSOLE_PID";
8+
type Result<T> = std::result::Result<T, Box<dyn std::error::Error>>;
119

1210
fn handle_wayland() {
1311
#[cfg(target_os = "linux")]
@@ -25,37 +23,31 @@ fn handle_wayland() {
2523
}
2624
}
2725

26+
fn handle_splash() {
27+
#[cfg(feature = "splash")]
28+
{
29+
std::env::set_var(
30+
"SWIFTNAV_CONSOLE_SPLASH",
31+
entrypoint::splash::marker_filepath(),
32+
);
33+
entrypoint::splash::spawn();
34+
}
35+
}
36+
2837
fn main() -> Result<()> {
2938
attach_console();
3039
handle_wayland();
3140
let current_exe = std::env::current_exe()?;
3241
let parent = current_exe.parent().ok_or("no parent directory")?;
3342
let args: Vec<_> = std::env::args().collect();
34-
let helper_found = args
35-
.iter()
36-
.any(|arg| matches!(arg.as_ref(), "--help" | "-h" | "--version" | "-V"));
37-
if !helper_found {
38-
let mut command = std::process::Command::new(parent.join("swift-console-splash"));
39-
match command.spawn() {
40-
Ok(child) => {
41-
let pid = child.id();
42-
std::env::set_var(SWIFT_CONSOLE_PID, format!("{pid}"));
43-
}
44-
Err(e) => {
45-
eprintln!("Starting splash screen failed: {e}");
46-
}
47-
};
48-
}
49-
5043
std::env::set_var("SWIFTNAV_CONSOLE_FROZEN", parent);
51-
5244
std::env::set_var("PYTHONHOME", parent);
5345
std::env::set_var("PYTHONDONTWRITEBYTECODE", "1");
46+
handle_splash();
5447
let exit_code = Python::with_gil(|py| {
5548
let args = PyTuple::new(py, args);
5649
let snav = py.import("swiftnav_console.main")?;
5750
snav.call_method("main", (args,), None)?.extract::<i32>()
5851
})?;
59-
6052
std::process::exit(exit_code);
6153
}

0 commit comments

Comments
 (0)