Skip to content

Commit 2e0582f

Browse files
committed
chore: refactor controller prototype and remove circular references
1 parent fa308f3 commit 2e0582f

26 files changed

Lines changed: 221 additions & 52 deletions

owlplug-client/src/main/java/com/owlplug/auth/controllers/AccountController.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,11 @@
3232
import org.slf4j.Logger;
3333
import org.slf4j.LoggerFactory;
3434
import org.springframework.beans.factory.annotation.Autowired;
35+
import org.springframework.context.annotation.Scope;
3536
import org.springframework.stereotype.Controller;
3637

37-
@Controller
38+
@Controller()
39+
@Scope("prototype")
3840
public class AccountController extends AbstractDialogController {
3941

4042
private final Logger log = LoggerFactory.getLogger(this.getClass());

owlplug-client/src/main/java/com/owlplug/core/controllers/MainController.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import com.owlplug.core.components.TaskRunner;
3434
import com.owlplug.core.controllers.dialogs.CrashRecoveryDialogController;
3535
import com.owlplug.core.controllers.dialogs.WelcomeDialogController;
36+
import com.owlplug.core.events.OptionRefreshEvent;
3637
import com.owlplug.core.utils.PlatformUtils;
3738
import com.owlplug.explore.controllers.ExploreController;
3839
import com.owlplug.explore.services.ExploreService;
@@ -59,6 +60,7 @@
5960
import org.slf4j.Logger;
6061
import org.slf4j.LoggerFactory;
6162
import org.springframework.beans.factory.annotation.Autowired;
63+
import org.springframework.context.ApplicationEventPublisher;
6264
import org.springframework.stereotype.Controller;
6365

6466
@Controller
@@ -67,16 +69,12 @@ public class MainController extends BaseController {
6769
private final Logger log = LoggerFactory.getLogger(this.getClass());
6870

6971
@Autowired
70-
private LazyViewRegistry viewRegistry;
72+
private ApplicationEventPublisher publisher;
7173
@Autowired
72-
private AccountController accountController;
74+
private LazyViewRegistry viewRegistry;
7375
@Autowired
7476
private CrashRecoveryDialogController crashRecoveryDialogController;
7577
@Autowired
76-
private WelcomeDialogController welcomeDialogController;
77-
@Autowired
78-
private OptionsController optionsController;
79-
@Autowired
8078
private ExploreController exploreController;
8179
@Autowired
8280
private AuthenticationService authenticationService;
@@ -135,6 +133,7 @@ public void initialize() {
135133

136134
accountComboBox.getSelectionModel().selectedItemProperty().addListener((options, oldValue, newValue) -> {
137135
if (newValue instanceof AccountMenuItem) {
136+
AccountController accountController = new AccountController();
138137
accountController.show();
139138
// Delay comboBox selector change
140139
Platform.runLater(() -> accountComboBox.setValue(oldValue));
@@ -183,11 +182,14 @@ public void dispatchPostInitialize() {
183182
log.info("Previous execution not terminated safely, opening crash recovery dialog");
184183
crashRecoveryDialogController.show();
185184
} else if (this.getPreferences().getBoolean(ApplicationDefaults.FIRST_LAUNCH_KEY, true)) {
186-
welcomeDialogController.show();
185+
WelcomeDialogController dialog = new WelcomeDialogController();
186+
dialog.show();
187187
exploreService.syncSources();
188188
}
189189
this.getPreferences().putBoolean(ApplicationDefaults.FIRST_LAUNCH_KEY, false);
190-
optionsController.refreshView();
190+
191+
// Refresh Options view
192+
publisher.publishEvent(new OptionRefreshEvent());
191193

192194
this.getTelemetryService().event("/Startup", p -> {
193195
p.put("osName", System.getProperty("os.name"));

owlplug-client/src/main/java/com/owlplug/core/controllers/OptionsController.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,15 @@
2323
import com.owlplug.core.components.ApplicationDefaults;
2424
import com.owlplug.core.controllers.dialogs.DonateDialogController;
2525
import com.owlplug.core.controllers.fragments.PluginPathFragmentController;
26+
import com.owlplug.core.events.OptionRefreshEvent;
2627
import com.owlplug.core.model.OperatingSystem;
2728
import com.owlplug.core.services.OptionsService;
2829
import com.owlplug.core.ui.SlidingLabel;
2930
import com.owlplug.core.utils.PlatformUtils;
3031
import com.owlplug.host.loaders.NativePluginLoader;
3132
import com.owlplug.plugin.controllers.dialogs.ListDirectoryDialogController;
3233
import com.owlplug.plugin.services.NativeHostService;
34+
import javafx.application.Platform;
3335
import javafx.collections.FXCollections;
3436
import javafx.collections.ObservableList;
3537
import javafx.fxml.FXML;
@@ -42,9 +44,12 @@
4244
import javafx.scene.layout.VBox;
4345
import javafx.scene.text.TextFlow;
4446
import org.springframework.beans.factory.annotation.Autowired;
47+
import org.springframework.context.annotation.Scope;
48+
import org.springframework.context.event.EventListener;
4549
import org.springframework.stereotype.Controller;
4650

4751
@Controller
52+
@Scope("prototype")
4853
public class OptionsController extends BaseController {
4954

5055
@Autowired
@@ -262,6 +267,11 @@ public void initialize() {
262267
refreshView();
263268
}
264269

270+
@EventListener
271+
public void handle(OptionRefreshEvent event) {
272+
Platform.runLater(this::refreshView);
273+
}
274+
265275
public void refreshView() {
266276

267277
vst2PluginPathFragment.refresh();

owlplug-client/src/main/java/com/owlplug/core/controllers/dialogs/WelcomeDialogController.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,23 @@
2323
import com.owlplug.core.components.LazyViewRegistry;
2424
import com.owlplug.core.controllers.OptionsController;
2525
import com.owlplug.core.controllers.fragments.PluginPathFragmentController;
26+
import com.owlplug.core.events.OptionRefreshEvent;
2627
import com.owlplug.core.model.OperatingSystem;
2728
import com.owlplug.plugin.components.PluginTaskFactory;
2829
import com.owlplug.plugin.controllers.dialogs.ListDirectoryDialogController;
30+
import javafx.application.Platform;
2931
import javafx.fxml.FXML;
3032
import javafx.scene.control.Button;
3133
import javafx.scene.control.Label;
3234
import javafx.scene.image.ImageView;
3335
import javafx.scene.layout.VBox;
3436
import org.springframework.beans.factory.annotation.Autowired;
37+
import org.springframework.context.annotation.Scope;
38+
import org.springframework.context.event.EventListener;
3539
import org.springframework.stereotype.Controller;
3640

3741
@Controller
42+
@Scope("prototype")
3843
public class WelcomeDialogController extends AbstractDialogController {
3944

4045
@Autowired
@@ -58,7 +63,7 @@ public class WelcomeDialogController extends AbstractDialogController {
5863
private PluginPathFragmentController auPluginPathFragment;
5964
private PluginPathFragmentController lv2PluginPathFragment;
6065

61-
WelcomeDialogController() {
66+
public WelcomeDialogController() {
6267
super(700, 300);
6368
this.setOverlayClose(false);
6469
}
@@ -109,6 +114,11 @@ public void initialize() {
109114

110115
}
111116

117+
@EventListener
118+
public void handle(OptionRefreshEvent event) {
119+
Platform.runLater(this::refreshView);
120+
}
121+
112122
public void refreshView() {
113123
vst2PluginPathFragment.refresh();
114124
vst3PluginPathFragment.refresh();
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/* OwlPlug
2+
* Copyright (C) 2021 Arthur <dropsnorz@gmail.com>
3+
*
4+
* This file is part of OwlPlug.
5+
*
6+
* OwlPlug is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License version 3
8+
* as published by the Free Software Foundation.
9+
*
10+
* OwlPlug is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with OwlPlug. If not, see <https://www.gnu.org/licenses/>.
17+
*/
18+
19+
package com.owlplug.core.events;
20+
21+
public class ExploreRefreshEvent {
22+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/* OwlPlug
2+
* Copyright (C) 2021 Arthur <dropsnorz@gmail.com>
3+
*
4+
* This file is part of OwlPlug.
5+
*
6+
* OwlPlug is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License version 3
8+
* as published by the Free Software Foundation.
9+
*
10+
* OwlPlug is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with OwlPlug. If not, see <https://www.gnu.org/licenses/>.
17+
*/
18+
19+
package com.owlplug.core.events;
20+
21+
public class OptionRefreshEvent {
22+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/* OwlPlug
2+
* Copyright (C) 2021 Arthur <dropsnorz@gmail.com>
3+
*
4+
* This file is part of OwlPlug.
5+
*
6+
* OwlPlug is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License version 3
8+
* as published by the Free Software Foundation.
9+
*
10+
* OwlPlug is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with OwlPlug. If not, see <https://www.gnu.org/licenses/>.
17+
*/
18+
19+
package com.owlplug.core.events;
20+
21+
public class PluginDisplayEvent {
22+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/* OwlPlug
2+
* Copyright (C) 2021 Arthur <dropsnorz@gmail.com>
3+
*
4+
* This file is part of OwlPlug.
5+
*
6+
* OwlPlug is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License version 3
8+
* as published by the Free Software Foundation.
9+
*
10+
* OwlPlug is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with OwlPlug. If not, see <https://www.gnu.org/licenses/>.
17+
*/
18+
19+
package com.owlplug.core.events;
20+
21+
public class PluginRefreshEvent {
22+
}

owlplug-client/src/main/java/com/owlplug/explore/controllers/ExploreController.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,11 @@
6060
import org.slf4j.Logger;
6161
import org.slf4j.LoggerFactory;
6262
import org.springframework.beans.factory.annotation.Autowired;
63+
import org.springframework.context.annotation.Scope;
6364
import org.springframework.stereotype.Controller;
6465

6566
@Controller
67+
@Scope("prototype")
6668
public class ExploreController extends BaseController {
6769

6870
private final Logger log = LoggerFactory.getLogger(this.getClass());
@@ -75,7 +77,7 @@ public class ExploreController extends BaseController {
7577
private ImageCache imageCache;
7678
@Autowired
7779
private LazyViewRegistry viewRegistry;
78-
@Autowired
80+
@FXML
7981
private PackageInfoController packageInfoController;
8082
@Autowired
8183
private MainController mainController;

owlplug-client/src/main/java/com/owlplug/explore/controllers/NewSourceDialogController.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,11 @@
3333
import javafx.scene.control.TextField;
3434
import javafx.scene.image.ImageView;
3535
import org.springframework.beans.factory.annotation.Autowired;
36+
import org.springframework.context.annotation.Scope;
3637
import org.springframework.stereotype.Controller;
3738

3839
@Controller
40+
@Scope("prototype")
3941
public class NewSourceDialogController extends AbstractDialogController implements IEntityCreateOrUpdate<RemoteSource> {
4042

4143
@Autowired

0 commit comments

Comments
 (0)