The simplest way would be to connect all your external sources to the TV.
Connect the optical audio out of the TV to the soundbar. You may need to turn the optical output on, the TV speakers off, and change the audio output type in the TV menu to get it working. Select the optical input on the soundbar and leave it there.
Some TVs don't send audio from the 'smart' apps out of the TV.