Repository navigation
Windows splash screen and shared AppUserModelID #21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
95fe4bd
Add Windows splash screen and shared AppUserModelID.
dominicletz 2c3ef21
Start Transport unlinked from EventBridge.
dominicletz 2f6baf1
Fix Transport.ensure_started: Process.alive?/1 is not guard-safe.
dominicletz 3aad0ea
Resubscribe EventBridge after an unlinked Transport crash.
dominicletz f5b1e59
Build aumid_nif via MSVC host script, not elixir_make.
dominicletz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| #include <erl_nif.h> | ||
| #include <string.h> | ||
|
|
||
| #ifdef _WIN32 | ||
| #include <windows.h> | ||
| #include <shobjidl.h> | ||
| #endif | ||
|
|
||
| static ERL_NIF_TERM atom_ok; | ||
| static ERL_NIF_TERM atom_error; | ||
|
|
||
| static int on_load(ErlNifEnv *env, void **priv_data, ERL_NIF_TERM load_info) { | ||
| (void)priv_data; | ||
| (void)load_info; | ||
| atom_ok = enif_make_atom(env, "ok"); | ||
| atom_error = enif_make_atom(env, "error"); | ||
| return 0; | ||
| } | ||
|
|
||
| static ERL_NIF_TERM set_nif(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) { | ||
| (void)argc; | ||
| #ifndef _WIN32 | ||
| (void)argv; | ||
| return atom_ok; | ||
| #else | ||
| char id[512]; | ||
| if (enif_get_string(env, argv[0], id, sizeof(id), ERL_NIF_LATIN1) <= 0) { | ||
| ErlNifBinary bin; | ||
| if (!enif_inspect_binary(env, argv[0], &bin) || bin.size >= sizeof(id)) { | ||
| return enif_make_badarg(env); | ||
| } | ||
| memcpy(id, bin.data, bin.size); | ||
| id[bin.size] = '\0'; | ||
| } | ||
| if (id[0] == '\0') return atom_ok; | ||
|
|
||
| int n = MultiByteToWideChar(CP_UTF8, 0, id, -1, NULL, 0); | ||
| if (n <= 0) return enif_make_tuple2(env, atom_error, enif_make_atom(env, "utf8")); | ||
| WCHAR *wide = (WCHAR *)enif_alloc(sizeof(WCHAR) * (size_t)n); | ||
| if (!wide) return enif_make_tuple2(env, atom_error, enif_make_atom(env, "alloc")); | ||
| MultiByteToWideChar(CP_UTF8, 0, id, -1, wide, n); | ||
| HRESULT hr = SetCurrentProcessExplicitAppUserModelID(wide); | ||
| enif_free(wide); | ||
| if (FAILED(hr)) { | ||
| return enif_make_tuple2(env, atom_error, enif_make_int(env, (int)hr)); | ||
| } | ||
| return atom_ok; | ||
| #endif | ||
| } | ||
|
|
||
| static ErlNifFunc nif_funcs[] = {{"set_nif", 1, set_nif}}; | ||
|
|
||
| ERL_NIF_INIT(Elixir.DesktopWebview.AppUserModelId, nif_funcs, on_load, NULL, NULL, NULL) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| defmodule DesktopWebview.AppUserModelId do | ||
| @moduledoc false | ||
|
|
||
| # Prebuilt by scripts/build_windows.ps1 → priv/native/windows/aumid_nif.dll | ||
| # (not compiled via mix). Missing DLL keeps the Elixir stub (:ok no-op). | ||
|
|
||
| @on_load :load_nif | ||
|
|
||
| def load_nif do | ||
| path = | ||
| [:code.priv_dir(:desktop_webview), "native", "windows", "aumid_nif"] | ||
| |> Path.join() | ||
| |> String.to_charlist() | ||
|
|
||
| case :erlang.load_nif(path, 0) do | ||
| :ok -> :ok | ||
| {:error, _} -> :ok | ||
| end | ||
| end | ||
|
|
||
| # Host passes EDW_APP_USER_MODEL_ID so BEAM shares the host AppUserModelID. | ||
| def apply_from_env do | ||
| case System.get_env("EDW_APP_USER_MODEL_ID") do | ||
| id when is_binary(id) and id != "" -> set(id) | ||
| _ -> :ok | ||
| end | ||
| end | ||
|
|
||
| def set(id) when is_binary(id), do: set_nif(id) | ||
|
|
||
| def set_nif(_id), do: :ok | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| #include "aumid.hpp" | ||
| #include "win_util.hpp" | ||
|
|
||
| #include <cstdio> | ||
| #include <shobjidl.h> | ||
|
|
||
| bool set_app_user_model_id(const std::string& utf8_id) { | ||
| if (utf8_id.empty()) return true; | ||
| std::wstring wide = utf8_to_wide(utf8_id); | ||
| HRESULT hr = SetCurrentProcessExplicitAppUserModelID(wide.c_str()); | ||
| if (FAILED(hr)) { | ||
| fprintf(stderr, "edw: SetCurrentProcessExplicitAppUserModelID failed (0x%08lx)\n", | ||
| static_cast<unsigned long>(hr)); | ||
| return false; | ||
| } | ||
| return true; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| #pragma once | ||
|
|
||
| #include <string> | ||
|
|
||
| // Set the process AppUserModelID (Task Manager / taskbar grouping). No-op if empty. | ||
| // Returns true on success or when id is empty. | ||
| bool set_app_user_model_id(const std::string& utf8_id); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.