|
1 | 1 | package fr.adrienbrault.idea.symfony2plugin.webDeployment; |
2 | 2 |
|
3 | | -import com.intellij.openapi.components.ProjectComponent; |
| 3 | +import com.intellij.openapi.Disposable; |
4 | 4 | import com.intellij.openapi.progress.ProgressIndicator; |
5 | 5 | import com.intellij.openapi.progress.Task; |
6 | 6 | import com.intellij.openapi.project.DumbService; |
|
16 | 16 | /** |
17 | 17 | * @author Daniel Espendiller <daniel@espendiller.net> |
18 | 18 | */ |
19 | | -public class WebDeploymentProjectComponent implements ProjectComponent { |
20 | | - |
21 | | - private Project project; |
22 | | - |
23 | | - public WebDeploymentProjectComponent(Project project) { |
24 | | - this.project = project; |
25 | | - } |
| 19 | +public class WebDeploymentProjectComponent { |
| 20 | + public static class PostStartupActivity implements com.intellij.openapi.startup.StartupActivity { |
| 21 | + @Override |
| 22 | + public void runActivity(@NotNull Project project) { |
| 23 | + if(!WebDeploymentUtil.isEnabled(project)) { |
| 24 | + return; |
| 25 | + } |
26 | 26 |
|
27 | | - public void initComponent() { |
| 27 | + project.getService(ProjectService.class).start(); |
| 28 | + } |
28 | 29 | } |
29 | 30 |
|
30 | | - public void disposeComponent() { |
31 | | - } |
| 31 | + public static class ProjectService implements Disposable { |
| 32 | + private final Project project; |
| 33 | + private Timer timer1; |
32 | 34 |
|
33 | | - @NotNull |
34 | | - public String getComponentName() { |
35 | | - return "WebDeploymentProjectComponent"; |
36 | | - } |
37 | | - |
38 | | - public void projectOpened() { |
39 | | - if(!WebDeploymentUtil.isEnabled(project)) { |
40 | | - return; |
| 35 | + public ProjectService(@NotNull Project project) { |
| 36 | + this.project = project; |
41 | 37 | } |
42 | 38 |
|
43 | | - // remote file downloader |
44 | | - if(Settings.getInstance(project).remoteDevFileScheduler) { |
45 | | - Symfony2ProjectComponent.getLogger().info("Starting Symfony webDeployment background scheduler"); |
| 39 | + public void start() { |
| 40 | + // remote file downloader |
| 41 | + if(Settings.getInstance(project).remoteDevFileScheduler) { |
| 42 | + Symfony2ProjectComponent.getLogger().info("Starting Symfony webDeployment background scheduler"); |
46 | 43 |
|
47 | | - DumbService.getInstance(project).smartInvokeLater(() -> new Timer().schedule(new MyTimerTask(), 1000, 300000)); |
| 44 | + this.timer1 = new Timer(); |
| 45 | + DumbService.getInstance(this.project).smartInvokeLater(() -> timer1.schedule(new MyTimerTask(project), 1000, 300000)); |
| 46 | + } |
48 | 47 | } |
49 | | - } |
50 | 48 |
|
51 | | - public void projectClosed() { |
52 | | - if(RemoteWebServerUtil.STORAGE_INSTANCES.containsKey(project)) { |
| 49 | + @Override |
| 50 | + public void dispose() { |
53 | 51 | RemoteWebServerUtil.STORAGE_INSTANCES.remove(project); |
| 52 | + |
| 53 | + if (this.timer1 != null) { |
| 54 | + this.timer1.cancel(); |
| 55 | + this.timer1.purge(); |
| 56 | + this.timer1 = null; |
| 57 | + } |
54 | 58 | } |
55 | 59 | } |
56 | 60 |
|
57 | | - private class MyTimerTask extends TimerTask { |
| 61 | + private static class MyTimerTask extends TimerTask { |
| 62 | + @NotNull |
| 63 | + private final Project project; |
| 64 | + |
| 65 | + public MyTimerTask(@NotNull Project project) { |
| 66 | + this.project = project; |
| 67 | + } |
58 | 68 |
|
59 | 69 | @Override |
60 | 70 | public void run() { |
|
0 commit comments