When Blender open multiple main windows, bpy.context's behavior are not as single windows

Hi, I put below code in scripts\startup\bl_ui\space_topbar.py ,when in single windows, I get the result what I want.
But when I open some new main windows from this opened Blender ,the behavior of the script is not normal as single windows one . no matter how I change the bpy.context.window.scene to bpy.data.window_managers[-1].windows[-1].scene the workspace can’t set to right scene. Am I missing any context in the multi-mian window?

def workspace_scene_link_keeper():
if (bpy.context.workspace.name == '2D DRAW'):

    if(bpy.context.scene.name != 'first_floor'):

        if('first_floor' in bpy.data.scenes):

            bpy.context.window.scene = bpy.data.scenes['first_floor']



            bpy.context.window.scene = bpy.data.scenes['first_floor']

elif(bpy.context.workspace.name == '3D DRAW'):

    if(bpy.context.scene.name != 'Scene' ):

        bpy.context.window.scene = bpy.data.scenes['Scene']

return 0


not sure if you can context override like that
if you are in blender 3.2+ you can use

 with bpy.context.temp_override(window=bpy.context.window_manager.windows[0]):
    # my code