Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
project8856
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
赵宇轩
project8856
Commits
5761f612
Commit
5761f612
authored
3 years ago
by
noberumotto
Browse files
Options
Downloads
Patches
Plain Diff
更换计时方法
parent
a28d7789
Branches
Branches containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Core/Servicers/Instances/Main.cs
+56
-39
56 additions, 39 deletions
Core/Servicers/Instances/Main.cs
with
56 additions
and
39 deletions
Core/Servicers/Instances/Main.cs
+
56
−
39
View file @
5761f612
...
...
@@ -31,7 +31,16 @@ namespace Core.Servicers.Instances
"ApplicationFrameHost"
,
"StartMenuExperienceHost"
,
"ShellExperienceHost"
,
"OpenWith"
"OpenWith"
,
"Updater"
,
"LockApp"
,
""
,
""
,
""
,
""
,
""
,
""
,
};
/// <summary>
...
...
@@ -39,12 +48,15 @@ namespace Core.Servicers.Instances
/// </summary>
private
string
activeProcess
,
activeProcessDescription
,
activeProcessFile
=
null
;
//private DateTime activeStartTime = DateTime.Now;
/// <summary>
///
活动计时器
///
焦点开始时间
/// </summary>
private
Timer
activeTimer
;
private
DateTime
activeStartTime
=
DateTime
.
Now
;
///// <summary>
///// 活动计时器
///// </summary>
//private Timer activeTimer;
/// <summary>
/// 睡眠状态
/// </summary>
...
...
@@ -56,10 +68,10 @@ namespace Core.Servicers.Instances
private
ConfigModel
config
;
public
event
EventHandler
OnUpdateTime
;
/// <summary>
/// 当前焦点使用时长(秒)
/// </summary>
private
int
activeSeconds
=
0
;
///
//
<summary>
///
//
当前焦点使用时长(秒)
///
//
</summary>
//
private int activeSeconds = 0;
public
Main
(
IObserver
observer
,
IData
data
,
...
...
@@ -74,30 +86,25 @@ namespace Core.Servicers.Instances
observer
.
OnAppActive
+=
Observer_OnAppActive
;
sleepdiscover
.
SleepStatusChanged
+=
Sleepdiscover_SleepStatusChanged
;
activeTimer
=
new
Timer
();
activeTimer
.
Interval
=
1000
;
activeTimer
.
Elapsed
+=
ActiveTimer_Elapsed
;
activeTimer
.
Disposed
+=
ActiveTimer_Disposed
;
//activeTimer = new Timer();
//activeTimer.Interval = 1000;
//activeTimer.Elapsed += ActiveTimer_Elapsed;
appConfig
.
ConfigChanged
+=
AppConfig_ConfigChanged
;
dateObserver
.
OnDateChanging
+=
DateObserver_OnDateChanging
;
}
private
void
ActiveTimer_Disposed
(
object
sender
,
EventArgs
e
)
{
Debug
.
WriteLine
(
"disposed!timer"
);
}
private
void
ActiveTimer_Elapsed
(
object
sender
,
ElapsedEventArgs
e
)
{
activeSeconds
++;
Debug
.
WriteLine
(
activeSeconds
.
ToString
());
}
//private void ActiveTimer_Elapsed(object sender, ElapsedEventArgs e)
//{
// activeSeconds++;
//}
private
void
DateObserver_OnDateChanging
(
object
sender
,
EventArgs
e
)
{
Debug
.
WriteLine
(
"日期变更前:"
+
DateTime
.
Now
.
ToString
());
UpdateTime
();
if
(
sleepStatus
==
SleepStatus
.
Wake
)
{
Debug
.
WriteLine
(
"日期变更前:"
+
DateTime
.
Now
.
ToString
());
UpdateTime
();
}
}
private
void
AppConfig_ConfigChanged
(
ConfigModel
oldConfig
,
ConfigModel
newConfig
)
...
...
@@ -144,14 +151,13 @@ namespace Core.Servicers.Instances
UpdateTime
();
activeProcess
=
null
;
activeTimer
.
Stop
();
//activeSeconds = 0;
//
activeTimer.Stop();
}
}
private
void
Observer_OnAppActive
(
string
processName
,
string
description
,
string
file
)
{
if
(
activeProcess
!=
processName
&&
activeProcessFile
!=
file
)
{
UpdateTime
();
...
...
@@ -166,13 +172,13 @@ namespace Core.Servicers.Instances
activeProcessDescription
=
description
;
activeProcessFile
=
file
;
//
activeStartTime = DateTime.Now;
activeStartTime
=
DateTime
.
Now
;
activeSeconds
=
0
;
if
(!
activeTimer
.
Enabled
)
{
activeTimer
.
Start
();
}
//
activeSeconds = 0;
//
if (!activeTimer.Enabled)
//
{
//
activeTimer.Start();
//
}
// 提取icon
Iconer
.
ExtractFromFile
(
file
,
processName
,
description
);
...
...
@@ -180,8 +186,8 @@ namespace Core.Servicers.Instances
else
{
activeProcess
=
null
;
activeSeconds
=
0
;
activeTimer
.
Stop
();
//
activeSeconds = 0;
//
activeTimer.Stop();
}
}
...
...
@@ -238,15 +244,26 @@ namespace Core.Servicers.Instances
if
(!
string
.
IsNullOrEmpty
(
activeProcess
))
{
// 更新计时
TimeSpan
timeSpan
=
DateTime
.
Now
-
activeStartTime
;
int
seconds
=
(
int
)
timeSpan
.
TotalSeconds
;
int
seconds
=
activeSeconds
;
// 如果是休眠状态要减去5分钟
if
(
sleepStatus
==
SleepStatus
.
Sleep
)
{
seconds
-=
300
;
}
Debug
.
WriteLine
(
sleepStatus
+
" 进程:"
+
activeProcess
+
" 更新时间:"
+
seconds
);
if
(
seconds
<=
0
)
{
return
;
}
Logger
.
Info
(
sleepStatus
+
" 进程:"
+
activeProcess
+
" 更新时间:"
+
seconds
);
data
.
Set
(
activeProcess
,
activeProcessDescription
,
activeProcessFile
,
seconds
);
// 关联进程更新
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment