I've battled with fungus gnats and fruit flies in the past. My best method of differentiating them is the color of their abdomen - fungus gnats tend to be black/gray, while fruit flies tend to be reddish-brown. Knowing what you're dealing with will help you devise a method for battling them and keeping them at bay.
Fungus gnats tend to not care much for fermented things but can be so prolific that they'll end up everywhere. These little bastards usually make a home in potted plant soil inside your home. You can do a visual inspection of the soil surface while blowing softly across the surface of the soil to see if you can see them crawling/flying about. When you have an infestation you can actually see larvae movement downwards into the soil as you're blowing. My best method of treating this scenario is a good spraying of permithrin insectiside across the entire surface of the soil, followed by a 1/4" (or thicker) layer of horticultural/coarse sand across the entire surface. This has worked very well for me in the past.
Fruit flies are more problematic when it comes to those fermenting good we all have laying about. They want in and are attracted to co2 (i.e. airlocks). Luckily, they need food to survive very long. Keep fruits in your fridge and check all veggies/fruits on your counters for signs of fruit fly holes. Use the homemade traps like you have been. Then a few days should take care of it. I've found the best trap to be either white or red wine with a couple drops of dish soap - works better for my fruit flies that the vinegar does.
Despite their presence, I've brewed with them around, indoors, with great success. Covering your chilling wort with syran wrap or foil works great. Then just minimize open air contact during transfers and swipe them away if you see them around.