Skip to content
This repository has been archived by the owner on Jun 5, 2023. It is now read-only.

Commit

Permalink
Update window title handling in VueFileExplorer sample for #9
Browse files Browse the repository at this point in the history
  • Loading branch information
SteveSandersonMS committed Nov 20, 2019
1 parent 7fee8f2 commit 8704934
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
4 changes: 2 additions & 2 deletions samples/VueFileExplorer/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand All @@ -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
Expand Down
20 changes: 18 additions & 2 deletions src/WebWindow/WebWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public WebWindow(string title, Action<WebWindowOptions> configure)
var options = new WebWindowOptions();
configure.Invoke(options);

_title = title;
WriteTitleField(title);

var onWebMessageReceivedDelegate = (OnWebMessageReceivedCallback)ReceiveWebMessage;
_gcHandlesToFree.Add(GCHandle.Alloc(onWebMessageReceivedDelegate));
Expand Down Expand Up @@ -100,7 +100,7 @@ public string Title
get => _title;
set
{
_title = value;
WriteTitleField(value);
WebWindow_SetTitle(_nativeWebWindow, _title);

This comment has been minimized.

Copy link
@mika76

mika76 Nov 20, 2019

Still doesn't work sadly - fails on this line. I put a Console.WriteLine just before the line and got this...

Setting title bin on 140538969950816
Setting title VueFileExplorer on 140538969950816
Setting title bin on 140538969950816
Setting title VueFileExplorer on 140538969950816
--> CRASH <--

so its not the _title string that is the problem , and _nativeWebWindow seems fine too - so must be something on the native side.

}
}
Expand Down Expand Up @@ -156,6 +156,22 @@ public void SendMessage(string message)

public event EventHandler<string> 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);
Expand Down

0 comments on commit 8704934

Please sign in to comment.