Skip to content

Commit

Permalink
web audio patch
Browse files Browse the repository at this point in the history
- Web wallpaper audio can be muted from Settings -> Audio -> Master volume -> 0
- "Play audio only when desktop is focused" now works with web wallpapers.
- Better error message for stream wallpaper customize menu.
- Updated WebView2 library.
- Updated Spanish translation.
Credit: Omar Pro Gamer
  • Loading branch information
rocksdanister committed Nov 30, 2021
1 parent 8c2cca6 commit 2978cd0
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 92 deletions.
10 changes: 10 additions & 0 deletions src/livelywpf/livelywpf/Core/API/IpcMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public enum MessageType
cmd_screenshot,
cmd_suspend,
cmd_resume,
cmd_volume,
lsp_perfcntr,
lsp_nowplaying,
lp_slider,
Expand Down Expand Up @@ -136,6 +137,15 @@ public LivelyResumeCmd() : base(MessageType.cmd_resume)
}
}

[Serializable]
public class LivelyVolumeCmd : IpcMessage
{
public int Volume { get; set; }
public LivelyVolumeCmd() : base(MessageType.cmd_volume)
{
}
}

[Serializable]
public class LivelySystemInformation : IpcMessage
{
Expand Down
1 change: 1 addition & 0 deletions src/livelywpf/livelywpf/Core/API/IpcMessageConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist
MessageType.cmd_screenshot => jo.ToObject<LivelyScreenshotCmd>(serializer),
MessageType.cmd_suspend => jo.ToObject<LivelySuspendCmd>(serializer),
MessageType.cmd_resume => jo.ToObject<LivelyResumeCmd>(serializer),
MessageType.cmd_volume => jo.ToObject<LivelyVolumeCmd>(serializer),
MessageType.lsp_perfcntr => jo.ToObject<LivelySystemInformation>(serializer),
MessageType.lsp_nowplaying => jo.ToObject<LivelySystemNowPlaying>(serializer),
MessageType.lp_slider => jo.ToObject<LivelySlider>(serializer),
Expand Down
33 changes: 8 additions & 25 deletions src/livelywpf/livelywpf/Core/Wallpapers/WebProcess.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace livelywpf.Core.Wallpapers
public class WebProcess : IWallpaper
{
private static readonly NLog.Logger Logger = NLog.LogManager.GetCurrentClassLogger();
private int cefD3DRenderingSubProcessPid;//, cefAudioSubProcessPid;
private int cefD3DRenderingSubProcessPid;
private bool _initialized;
public event EventHandler<WindowInitializedArgs> WindowInitialized;
private static int globalCount;
Expand All @@ -43,13 +43,17 @@ public class WebProcess : IWallpaper

public WebProcess(string path, ILibraryModel model, ILivelyScreen display, string livelyPropertyPath, string debugPort, bool diskCache, int volume)
{
LivelyPropertyCopyPath = livelyPropertyPath;
//Streams can also use browser..
//TODO: Add support for livelyproperty video adjustments.
var isWeb = model.LivelyInfo.Type == WallpaperType.url || model.LivelyInfo.Type == WallpaperType.web || model.LivelyInfo.Type == WallpaperType.webaudio;
LivelyPropertyCopyPath = isWeb ? livelyPropertyPath : null;

StringBuilder cmdArgs = new StringBuilder();
cmdArgs.Append(" --url " + "\"" + path + "\"");
cmdArgs.Append(" --display " + "\"" + display + "\"");
cmdArgs.Append(" --property " + "\"" + LivelyPropertyCopyPath + "\"");
cmdArgs.Append(" --volume " + volume);
//volume == 0, Cef is permanently muted and cannot be adjusted runtime
cmdArgs.Append(" --volume " + 100);
cmdArgs.Append(" --geometry " + display.Bounds.Width + "x" + display.Bounds.Height);
//--audio false Issue: https://github.com/commandlineparser/commandline/issues/702
cmdArgs.Append(model.LivelyInfo.Type == WallpaperType.webaudio ? " --audio true" : " ");
Expand Down Expand Up @@ -285,35 +289,14 @@ public void Close()

public void SetVolume(int volume)
{
/*
try
{
if (Proc != null)
{
//VolumeMixer.SetApplicationVolume(Proc.Id, volume);
SetProcessAndChildrenVolume(Proc.Id, volume);
}
}
catch { }
*/
SendMessage(new LivelyVolumeCmd() { Volume = volume });
}

public void SetMute(bool mute)
{
//todo
}

private void SetProcessAndChildrenVolume(int pid, int volume)
{
ManagementObjectSearcher searcher = new ManagementObjectSearcher("Select * From Win32_Process Where ParentProcessID=" + pid);
ManagementObjectCollection moc = searcher.Get();
foreach (ManagementObject mo in moc)
{
SetProcessAndChildrenVolume(Convert.ToInt32(mo["ProcessID"]), volume);
}
VolumeMixer.SetApplicationVolume(Process.GetProcessById(pid).Id, volume);
}

private void KillProcessAndChildren(int pid)
{
ManagementObjectSearcher searcher = new ManagementObjectSearcher("Select * From Win32_Process Where ParentProcessID=" + pid);
Expand Down
Loading

0 comments on commit 2978cd0

Please sign in to comment.