Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions AutoPilot.App.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@
<ItemGroup>
<PackageReference Include="GitHub.Copilot.SDK" Version="0.1.22" />
<PackageReference Include="Markdig" Version="0.40.0" />
<PackageReference Include="Microsoft.Maui.Controls" Version="$(MauiVersion)" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebView.Maui" Version="$(MauiVersion)" />
<PackageReference Include="Microsoft.Maui.Controls" Version="10.0.31" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebView.Maui" Version="10.0.31" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="10.0.0" />
<PackageReference Include="sqlite-net-pcl" Version="*" />
<PackageReference Include="SQLitePCLRaw.bundle_green" Version="*" />
Expand Down
2 changes: 2 additions & 0 deletions Components/Layout/SessionSidebar.razor
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,7 @@ else

private async Task BrowseDirectory()
{
#if MACCATALYST
try
{
var dir = await FolderPickerService.PickFolderAsync();
Expand All @@ -394,6 +395,7 @@ else
{
Console.WriteLine($"Folder picker error: {ex.Message}");
}
#endif
}

private async Task ResumeSession(PersistedSessionInfo persisted)
Expand Down
3 changes: 2 additions & 1 deletion MainPage.xaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="AutoPilot.App.MainPage">
x:Class="AutoPilot.App.MainPage"
SafeAreaEdges="Container">

<BlazorWebView x:Name="blazorWebView" HostPage="wwwroot/index.html" />

Expand Down
17 changes: 16 additions & 1 deletion Models/ConnectionSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,26 @@ public static ConnectionSettings Load()
if (File.Exists(SettingsPath))
{
var json = File.ReadAllText(SettingsPath);
return JsonSerializer.Deserialize<ConnectionSettings>(json) ?? new();
return JsonSerializer.Deserialize<ConnectionSettings>(json) ?? DefaultSettings();
}
}
catch { }
return DefaultSettings();
}

private static ConnectionSettings DefaultSettings()
{
#if ANDROID
// Android can't run Copilot locally — default to persistent mode with common LAN IP
return new ConnectionSettings
{
Mode = ConnectionMode.Persistent,
Host = "192.168.50.72", // Mac host on local network
Port = 4321
};
#else
return new();
#endif
}

public void Save()
Expand Down
2 changes: 1 addition & 1 deletion Platforms/Android/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<application android:allowBackup="true" android:icon="@mipmap/appicon" android:roundIcon="@mipmap/appicon_round" android:supportsRtl="true"></application>
<application android:allowBackup="true" android:icon="@mipmap/appicon" android:roundIcon="@mipmap/appicon_round" android:supportsRtl="true" android:usesCleartextTraffic="true"></application>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CAMERA" />
Expand Down
2 changes: 1 addition & 1 deletion Platforms/Android/MainActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ protected override void OnCreate(Bundle? savedInstanceState)
{
base.OnCreate(savedInstanceState);

// Draw behind system bars (edge-to-edge)
// Edge-to-edge with transparent system bars
if (Window != null)
{
WindowCompat.SetDecorFitsSystemWindows(Window, false);
Expand Down
61 changes: 45 additions & 16 deletions Services/CopilotService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,34 +16,56 @@ public class CopilotService : IAsyncDisposable
private string? _activeSessionName;
private SynchronizationContext? _syncContext;

private static readonly string AppDataDir = GetAppDataDir();
private static string? _copilotBaseDir;
private static string CopilotBaseDir => _copilotBaseDir ??= GetCopilotBaseDir();

private static string GetAppDataDir()
private static string GetCopilotBaseDir()
{
// On mobile, UserProfile may be empty — use LocalApplicationData instead
var home = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
if (string.IsNullOrEmpty(home))
home = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
return Path.Combine(home, ".copilot");
try
{
#if ANDROID
var home = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
if (string.IsNullOrEmpty(home))
home = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
if (string.IsNullOrEmpty(home))
home = Android.App.Application.Context.FilesDir?.AbsolutePath ?? Path.GetTempPath();
return Path.Combine(home, ".copilot");
#else
var home = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
if (string.IsNullOrEmpty(home))
home = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
if (string.IsNullOrEmpty(home))
home = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
return Path.Combine(home, ".copilot");
#endif
}
catch
{
return Path.Combine(Path.GetTempPath(), ".copilot");
}
}

private static readonly string SessionStatePath = Path.Combine(AppDataDir, "session-state");
private static string? _sessionStatePath;
private static string SessionStatePath => _sessionStatePath ??= Path.Combine(CopilotBaseDir, "session-state");

private static readonly string ActiveSessionsFile = Path.Combine(AppDataDir, "autopilot-active-sessions.json");
private static string? _activeSessionsFile;
private static string ActiveSessionsFile => _activeSessionsFile ??= Path.Combine(CopilotBaseDir, "autopilot-active-sessions.json");

private static readonly string UiStateFile = Path.Combine(AppDataDir, "autopilot-ui-state.json");
private static string? _uiStateFile;
private static string UiStateFile => _uiStateFile ??= Path.Combine(CopilotBaseDir, "autopilot-ui-state.json");

private static readonly string ProjectDir = FindProjectDir();
private static string? _projectDir;
private static string ProjectDir => _projectDir ??= FindProjectDir();

private static string FindProjectDir()
{
try
{
// Walk up from the base directory to find the .csproj (works from bin/Debug/... at runtime)
var dir = AppDomain.CurrentDomain.BaseDirectory;
if (string.IsNullOrEmpty(dir)) return CopilotBaseDir;
for (int i = 0; i < 10; i++)
{
if (string.IsNullOrEmpty(dir)) break;
if (Directory.Exists(dir) && Directory.GetFiles(dir, "*.csproj").Length > 0)
return dir;
var parent = Directory.GetParent(dir);
Expand All @@ -53,10 +75,7 @@ private static string FindProjectDir()
}
catch { }
// Fallback
var home = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
return string.IsNullOrEmpty(home)
? Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)
: home;
return CopilotBaseDir;
}

public string DefaultModel { get; set; } = "claude-opus-4.6";
Expand Down Expand Up @@ -147,6 +166,16 @@ public async Task InitializeAsync(CancellationToken cancellationToken = default)
return;
}

#if ANDROID
// Android can't run Copilot CLI locally — must connect to remote server
settings.Mode = ConnectionMode.Persistent;
CurrentMode = ConnectionMode.Persistent;
if (settings.Host == "localhost" || settings.Host == "127.0.0.1")
{
Debug("Android detected with localhost — update Host in settings to your Mac's IP");
}
Debug($"Android: connecting to remote server at {settings.CliUrl}");
#endif
// In Persistent mode, auto-start the server if not already running
if (settings.Mode == ConnectionMode.Persistent)
{
Expand Down
2 changes: 2 additions & 0 deletions Services/ServerManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ private static string GetCopilotDir()
var home = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
if (string.IsNullOrEmpty(home))
home = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
if (string.IsNullOrEmpty(home))
home = Path.GetTempPath();
return Path.Combine(home, ".copilot");
}

Expand Down