diff --git a/samples/VueFileExplorer/Program.cs b/samples/VueFileExplorer/Program.cs index 74bcef2..44c8f6f 100644 --- a/samples/VueFileExplorer/Program.cs +++ b/samples/VueFileExplorer/Program.cs @@ -29,7 +29,7 @@ static void HandleWebMessageReceived(object sender, string message) case "navigateTo": var basePath = parsedMessage.GetProperty("basePath").GetString(); var relativePath = parsedMessage.GetProperty("relativePath").GetString(); - var destinationPath = Path.GetFullPath(Path.Combine(basePath, relativePath)); + var destinationPath = Path.GetFullPath(Path.Combine(basePath, relativePath)).TrimEnd(Path.DirectorySeparatorChar); ShowDirectoryInfo(window, destinationPath); break; case "showFile": @@ -41,7 +41,7 @@ static void HandleWebMessageReceived(object sender, string message) static void ShowDirectoryInfo(WebWindow window, string path) { - window.Title = path; + window.Title = Path.GetFileName(path); var directoryInfo = new DirectoryInfo(path); SendCommand(window, "showDirectory", new diff --git a/src/WebWindow/WebWindow.cs b/src/WebWindow/WebWindow.cs index 436f6d6..b73597d 100644 --- a/src/WebWindow/WebWindow.cs +++ b/src/WebWindow/WebWindow.cs @@ -63,7 +63,7 @@ public WebWindow(string title, Action configure) var options = new WebWindowOptions(); configure.Invoke(options); - _title = title; + WriteTitleField(title); var onWebMessageReceivedDelegate = (OnWebMessageReceivedCallback)ReceiveWebMessage; _gcHandlesToFree.Add(GCHandle.Alloc(onWebMessageReceivedDelegate)); @@ -100,7 +100,7 @@ public string Title get => _title; set { - _title = value; + WriteTitleField(value); WebWindow_SetTitle(_nativeWebWindow, _title); } } @@ -156,6 +156,22 @@ public void SendMessage(string message) public event EventHandler OnWebMessageReceived; + private void WriteTitleField(string value) + { + if (string.IsNullOrEmpty(value)) + { + value = "Untitled window"; + } + + // Due to Linux/Gtk platform limitations, the window title has to be no more than 31 chars + if (value.Length > 31 && RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + { + value = value.Substring(0, 31); + } + + _title = value; + } + private void ReceiveWebMessage([MarshalAs(UnmanagedType.LPUTF8Str)] string message) { OnWebMessageReceived?.Invoke(this, message);