1
0
mirror of https://github.com/chylex/TweetDuck.git synced 2025-05-09 05:34:05 +02:00

Add current PID into WindowsUtils.CurrentProcessID and use it

This commit is contained in:
chylex 2017-06-30 17:07:37 +02:00
parent 19a445fdab
commit 4818652582
3 changed files with 11 additions and 15 deletions

View File

@ -21,7 +21,7 @@ public LockManager(string file){
private void CreateLockFileStream(){
lockStream = new FileStream(file, FileMode.Create, FileAccess.Write, FileShare.Read);
WriteIntToStream(lockStream, GetCurrentProcessId());
WriteIntToStream(lockStream, WindowsUtils.CurrentProcessID);
lockStream.Flush(true);
}
@ -166,11 +166,5 @@ private static int ReadIntFromStream(Stream stream){
stream.Read(bytes, 0, 4);
return BitConverter.ToInt32(bytes, 0);
}
private static int GetCurrentProcessId(){
using(Process process = Process.GetCurrentProcess()){
return process.Id;
}
}
}
}

View File

@ -345,16 +345,13 @@ private void soundNotification_PlaybackError(object sender, PlaybackErrorEventAr
}
protected override void WndProc(ref Message m){
if (isLoaded && m.Msg == Program.WindowRestoreMessage){
using(Process process = Process.GetCurrentProcess()){
if (process.Id == m.WParam.ToInt32()){
trayIcon_ClickRestore(trayIcon, new EventArgs());
}
if (isLoaded){
if (m.Msg == Program.WindowRestoreMessage && WindowsUtils.CurrentProcessID == m.WParam.ToInt32()){
trayIcon_ClickRestore(trayIcon, new EventArgs());
return;
}
return;
}
if (isBrowserReady && m.Msg == NativeMethods.WM_PARENTNOTIFY && (m.WParam.ToInt32() & 0xFFFF) == NativeMethods.WM_XBUTTONDOWN){
browser.ExecuteScriptAsync("TDGF_onMouseClickExtra", (m.WParam.ToInt32() >> 16) & 0xFFFF);
return;

View File

@ -11,9 +11,14 @@ static class WindowsUtils{
private static readonly Lazy<Regex> RegexStripHtmlStyles = new Lazy<Regex>(() => new Regex(@"\s?(?:style|class)="".*?"""), false);
private static readonly Lazy<Regex> RegexOffsetClipboardHtml = new Lazy<Regex>(() => new Regex(@"(?<=EndHTML:|EndFragment:)(\d+)"), false);
public static int CurrentProcessID { get; }
public static bool ShouldAvoidToolWindow { get; }
static WindowsUtils(){
using(Process me = Process.GetCurrentProcess()){
CurrentProcessID = me.Id;
}
Version ver = Environment.OSVersion.Version;
ShouldAvoidToolWindow = ver.Major == 6 && ver.Minor == 2; // windows 8/10
}