Skip to content

Commit

Permalink
WSL: Codchi tray autostart
Browse files Browse the repository at this point in the history
WSL: windows terminal fragments (solves #14)
Updated Logo in MSIX
  • Loading branch information
htngr committed Nov 18, 2024
1 parent 04a183e commit 9fa5f41
Show file tree
Hide file tree
Showing 16 changed files with 118 additions and 23 deletions.
3 changes: 3 additions & 0 deletions build/msix/AppxManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@
<uap5:ExecutionAlias Alias="codchi.exe" />
</uap5:AppExecutionAlias>
</uap5:Extension>
<desktop:Extension Category="windows.startupTask" Executable="codchi.exe" EntryPoint="Windows.FullTrustApplication">
<desktop:StartupTask TaskId="codchi-tray" Enabled="true" DisplayName="Codchi Tray Icon" />
</desktop:Extension>
</Extensions>
</Application>
</Applications>
Expand Down
Binary file modified build/msix/Assets/StoreLogo.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added build/msix/Assets/favicon.ico
Binary file not shown.
Binary file modified build/msix/Assets/favicon150.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified build/msix/Assets/favicon44.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified build/msix/Assets/favicon44.targetsize-44_altform-unplated.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 10 additions & 2 deletions codchi/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions codchi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ windows = { version = "0.58", features = [
] }
wslapi = "0.1.3"
clap_complete_command = { version = "0.6.1", default-features = false }
uuid = { version = "1.11.0", features = ["v5"] }

[build-dependencies]
clap = { version = "4", features = ["derive", "cargo", "string"] }
Expand Down
2 changes: 1 addition & 1 deletion codchi/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ let
'';

CODCHI_WSL_VERSION_MIN = "2.0.14";
CODCHI_WSL_VERSION_MAX = "2.3.24";
CODCHI_WSL_VERSION_MAX = "2.3.26";

};
linux = rec {
Expand Down
11 changes: 10 additions & 1 deletion codchi/src/platform/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ pub trait Host: Sized {
});
}

Self::write_shortcuts(&machine.config.name, desktop_entries.iter())
Self::write_shortcuts(&machine.config.name, desktop_entries.iter())?;
Ok(())
}

fn open_terminal(&self, cmd: &[&str]) -> Result<()>;
Expand Down Expand Up @@ -137,6 +138,14 @@ pub trait Host: Sized {

#[cfg(target_os = "windows")]
fn start_vcxsrv(&self, kill_running: bool) -> Result<()>;

fn post_install(_machine_name: &str) -> Result<()> {
Ok(())
}

fn post_delete(_machine_name: &str) -> Result<()> {
Ok(())
}
}

#[derive(Clone, Debug)]
Expand Down
2 changes: 2 additions & 0 deletions codchi/src/platform/machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@ git add flake.*

set_progress_status("Updating start menu shortcuts...");
HostImpl::write_machine_shortcuts(self)?;
HostImpl::post_install(&self.config.name)?;

hide_progress();

Expand Down Expand Up @@ -391,6 +392,7 @@ git add flake.*

set_progress_status("Deleting start menu shortcuts...");
HostImpl::delete_shortcuts(&self.config.name)?;
HostImpl::post_delete(&self.config.name)?;

println!("Successfully deleted {}. You might also want to run a garbage collection (`codchi gc`).", self.config.name);

Expand Down
76 changes: 73 additions & 3 deletions codchi/src/platform/windows/host.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{
cli::DEBUG,
config::CodchiConfig,
consts,
consts::{self, APP_NAME},
platform::{DesktopEntry, Host},
util::PathExt,
};
Expand Down Expand Up @@ -30,7 +30,7 @@ impl Host for HostImpl {
.join(machine_name)
.cleanup_and_get()?;

let codchi_exe = env::current_exe()?;
// let codchi_exe = env::current_exe()?;

for DesktopEntry {
app_name,
Expand All @@ -40,7 +40,7 @@ impl Host for HostImpl {
is_terminal,
} in apps
{
let mut lnk = ShellLink::new(&codchi_exe)?;
let mut lnk = ShellLink::new("codchi.exe")?;
if let Some(ico_path) = icon {
let target = ico_folder.join(format!("{app_name}.ico"));
fs::copy(ico_path, &target)?;
Expand Down Expand Up @@ -166,4 +166,74 @@ impl Host for HostImpl {
terms.iter().map(|(term, _)| term).join(", ")
)
}

fn post_install(machine_name: &str) -> Result<()> {
// write json fragments for windows terminal
{
// from https://learn.microsoft.com/en-us/windows/terminal/json-fragment-extensions#calculating-a-guid-for-a-built-in-profile
let guid = {
use uuid::Uuid;
// Windows Terminal namespace GUID for auto-generated profiles
let terminal_namespace_guid =
Uuid::parse_str("2bde4a90-d05f-401c-9492-e40884ead1d8")?;
let profile_name = consts::machine::machine_name(machine_name);

let utf16le_bytes: Vec<u8> = profile_name
.encode_utf16()
.flat_map(|unit| unit.to_le_bytes()) // little-endian (BOM-less)
.collect();

Uuid::new_v5(&terminal_namespace_guid, &utf16le_bytes)
};
let fragment_dir = get_known_folder_path(KnownFolder::LocalAppData)
.expect("FOLDERID_LocalAppData missing")
.join("Microsoft")
.join("Windows Terminal")
.join("Fragments")
.join(APP_NAME);
fragment_dir.get_or_create()?;

let fragment_path = fragment_dir.join(format!("{machine_name}.json"));

// omit icon for now because if its missing, the fragment doesn't work. Also, after
// each codchi update the icon path changes until the machine is rebuilt
// let codchi_icon = env::current_exe()?
// .parent()
// .context("Failed to access codchi.exe install dir.")?
// .join("Assets")
// .join("favicon150.png");
// let codchi_icon = codchi_icon.display();
// "icon": "{codchi_icon}",

fs::write(
fragment_path,
format!(
r#"{{
"profiles": [
{{
"updates": "{{{guid}}}",
"commandline": "codchi.exe exec {machine_name}",
"name": "Codchi - {machine_name}",
}}
]
}}"#
),
)?;
}

Ok(())
}

fn post_delete(machine_name: &str) -> Result<()> {
get_known_folder_path(KnownFolder::LocalAppData)
.expect("FOLDERID_LocalAppData missing")
.join("Microsoft")
.join("Windows Terminal")
.join("Fragments")
.join(APP_NAME)
.join(format!("{machine_name}.json"))
.remove();

Ok(())
}
}
14 changes: 14 additions & 0 deletions docs/src/docs/config/misc.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,17 @@ By default the time zone is UTC inside a code machine. You can change this via
time.timeZone = "Europe/Berlin";
}
```

## Windows Networking

By default WSL configures the `/etc/hosts` and `/etc/resolv.conf` to match the networking settings of the host. Therefore they can't be generated by NixOS / Codchi. While Windows' DNS settings (through `/etc/resolv.conf`) are often neccessary for a working WSL instance, `/etc/hosts` is overridden by Codchi to enable reproducible IP / Domain configuration.

To override this change these options:
```nix
{
environment.etc = {
hosts.enable = true; # /etc/hosts set by Codchi
"resolv.conf".enable = false; # /etc/hosts set by WSL
};
}
```
14 changes: 0 additions & 14 deletions docs/src/docs/contrib/roadmap.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,6 @@

- Docs
- [ ] Demo Video
- NixOS options
- [ ] hosts / resolv.conf
- auto update
- update available notification / working auto update


- MVP Features
- [ ] Codchi doctor (periodical check)

- [ ] License

- Future
- Custom certs auto adding
Expand All @@ -24,10 +14,6 @@
- [ ] Internal Docs / Contrib
- [ ] Uninstalling Codchi, Migrating away

- Bugs
- update required with local repos => invalidate nix cache flag?
- (testing: dont prompt)

- open questions:
- WSL
- what happens if store stops and machines runs?
Expand Down
6 changes: 4 additions & 2 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,11 @@
inherit lib;

nixosModules.default = import ./nix/nixos;
nixosModules.codchi = {
nixosModules.codchi = { pkgs, ... }: {
nixpkgs.config.allowUnfree = true;
environment.systemPackages = self.devShells.${system}.default.nativeBuildInputs;
environment.systemPackages = self.devShells.${system}.default.nativeBuildInputs ++ [
pkgs.vscodium
];
# programs.neovim = {
# enable = true;
# package = pkgs.nixvim.makeNixvim (import ./editor.nix);
Expand Down

0 comments on commit 9fa5f41

Please sign in to comment.