Overview
Your OpenFin application shows a icon group on the taskbar. Window will generate a small image representation of the applications window with the windows name above it. Sometimes that name will appear as a string starting with "internal-generated-window-" followed by a randomly generated hexadecimal characters. This is the OpenFin internal name for the window and is being used because all other options for display are not implemented.
On Window Creation
The easiest way to name the window with its creation options when you are creating it. This is part of the windows identity and can therefore not be changed. For example if you create a simple container window you would:
fin.Window.create( {
name: "My New Window",
// other options
})
or for a platform window:
const pltfm = fin.Platform.getCurrentSync();
pltfm.createWindow({
name: "My New Window",
// other options
})
After Window Creation
document.title = "My Changed Window Title"
When Dragging Out Views
Using Window Template
{
platform: {
defaultWindowOptions: {
url: "http://localhost/windowTemplate.html",
...
You can use the javascript in windowTemplate.html to perform the document.title = "my Value" . Bear in mind this will happen for every window that is created in this application.
Overriding createWindow
Alternatively you can define an override for the PlatformProvider.createWindow() method. This you define on platform initialisation and will affect the way all windows are created for the whole application. Simply using the new windows executeJavaScript() method with document.title = "my Value" will change the title of the window. An example of this for when a window is created went the view is torn out is:
async createWindow(options, callerIdentity) {
// wait for the new window to be created
let newWindow = await super.createWindow(options, callerIdentity);
if (options.reason === 'tearout') {
// wrap the window that the view was torn out of and get values from it
let oldWindow = fin.Window.wrapSync({uuid: callerIdentity.uuid, name: callerIdentity.name});
let oldTitle = await oldWindow.executeJavaScript("document.title");
// change the title in the new window
if( oldTitle !== ""){
newWindow.executeJavaScript(`document.title = '${oldTitle}'`);
} else {
newWindow.executeJavaScript(`document.title = '${callerIdentity.name}'`);
}
}
return newWindow
}
Torn Out Windows Restored from Snapshot
There are times when you have been using the above solutions to rename the window titles and then use the fin.Platform.getSnapshot() to save the current window layout. You will find that the when you use fin.Platform.applySnapshot() that the new window that was created when tearing out the view has reverted back to a document.title value of "internal-generated-window-...". This is because it is OpenFins view that the windows contents controls the value of its title.
To work around this you can store a value in the windows options ( for example in the customData option) when updating the value of document.title. All stored window options are restored from the snapshot. Then when the window is created from the snapshot you can get the stored value and update the document.title with its value.
You can modify the above override to achieve this:
async createWindow(options, callerIdentity) {
// wait for the new window to be created
let newWindow = await super.createWindow(options, callerIdentity);
if (options.reason === 'tearout') {
// wrap the window that the view was torn out of and get values from it
let oldWindow = fin.Window.wrapSync({uuid: callerIdentity.uuid, name: callerIdentity.name});
let oldTitle = await oldWindow.executeJavaScript("document.title");
// change the title in the new window
// also add the title to the window option customData
if( oldTitle !== ""){
newWindow.executeJavaScript(`document.title = '${oldTitle}'`);
newWindow.updateOptions({customData:{title:oldTitle}})
} else {
newWindow.executeJavaScript(`document.title = '${callerIdentity.name}'`);
newWindow.updateOptions({customData:{title:callerIdentity.name}})
}
} else if (options.reason === 'apply-snapshot') {
// get the title value from the window customData option and
// update the new windows document.title with it.
let titleVal = (await newWindow.getOptions()).customData?.title;
if(titleVal !== undefined) {
newWindow.executeJavaScript(`document.title = '${titleVal}'`);
}
}
return newWindow
}
Comments
0 comments
Please sign in to leave a comment.