Skip to content

Commit 7b229ed

Browse files
committed
fix: Jahro project settings saving process bugfix
1 parent 0c02ac7 commit 7b229ed

File tree

5 files changed

+150
-48
lines changed

5 files changed

+150
-48
lines changed

Editor/View/JahroEditorView.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,28 @@ public void CreateGUI()
6262

6363
_projectSettings = JahroProjectSettings.LoadOrCreate();
6464

65+
_projectSettings.OnSettingsChanged += SaveProjectSettings;
66+
6567
SetWindowMode(WindowMode.LOADING);
6668

6769
CheckVersion();
6870
}
6971

72+
private void OnDestroy()
73+
{
74+
_projectSettings.OnSettingsChanged -= SaveProjectSettings;
75+
}
76+
77+
private void SaveProjectSettings()
78+
{
79+
if (_projectSettings != null)
80+
{
81+
EditorUtility.SetDirty(_projectSettings);
82+
AssetDatabase.SaveAssets();
83+
AssetDatabase.Refresh();
84+
}
85+
}
86+
7087
private async void CheckVersion()
7188
{
7289
try

Editor/View/SettingsView.cs

Lines changed: 23 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,15 @@ public class SettingsView
2626
private Button _projectOverviewButton;
2727
private Button _teamOverviewButton;
2828
private Button _accountSettingsButton;
29-
3029
private Toggle _jahroEnableToggle;
3130
private Toggle _autoDisableToggle;
3231
private EnumField _launchKeyField;
3332
private Toggle _keyboardShortcutsToggle;
3433
private Toggle _mobileTapAreaToggle;
3534
private Toggle _dublicateLogsToggle;
3635
private MaskField _assembliesField;
37-
3836
private List<string> _assembliesNames = new List<string>();
3937
private int _assembliesFlag;
40-
4138
public event Action OnResetApiKey;
4239

4340
public SettingsView(VisualElement root)
@@ -168,8 +165,7 @@ public void Initialize(KeyValidator.ValidateKeyResponse validation, JahroProject
168165

169166
if (_projectSettings.ActiveAssemblies.Count == 0 && _assembliesNames != null && _assembliesNames.Count > 0)
170167
{
171-
_projectSettings.ActiveAssemblies.AddRange(_assembliesNames);
172-
EditorUtility.SetDirty(_projectSettings);
168+
_projectSettings.ActiveAssemblies = new List<string>(_assembliesNames);
173169
}
174170

175171
UpdateAssemblySelection();
@@ -184,11 +180,11 @@ private void SetupDataBinding()
184180
_container.ClearBindings();
185181
_container.dataSource = _projectSettings;
186182

187-
BindToggle(_jahroEnableToggle, "_jahroEnabled");
188-
BindToggle(_autoDisableToggle, "_autoDisableInRelease");
189-
BindToggle(_keyboardShortcutsToggle, "_useLaunchKeyboardShortcut");
190-
BindToggle(_mobileTapAreaToggle, "_useLaunchTapArea");
191-
BindToggle(_dublicateLogsToggle, "_duplicateToUnityConsole");
183+
BindToggleWithCallback(_jahroEnableToggle, "_jahroEnabled", (value) => _projectSettings.JahroEnabled = value);
184+
BindToggleWithCallback(_autoDisableToggle, "_autoDisableInRelease", (value) => _projectSettings.AutoDisableInRelease = value);
185+
BindToggleWithCallback(_keyboardShortcutsToggle, "_useLaunchKeyboardShortcut", (value) => _projectSettings.UseLaunchKeyboardShortcut = value);
186+
BindToggleWithCallback(_mobileTapAreaToggle, "_useLaunchTapArea", (value) => _projectSettings.UseLaunchTapArea = value);
187+
BindToggleWithCallback(_dublicateLogsToggle, "_duplicateToUnityConsole", (value) => _projectSettings.DuplicateToUnityConsole = value);
192188

193189
if (_launchKeyField != null)
194190
{
@@ -202,7 +198,6 @@ private void SetupDataBinding()
202198
if (_projectSettings != null)
203199
{
204200
_projectSettings.LaunchKey = (KeyCode)evt.newValue;
205-
SaveProjectSettings();
206201
}
207202
});
208203
}
@@ -215,43 +210,47 @@ private void SetupDataBinding()
215210
{
216211
_assembliesFlag = (int)evt.newValue;
217212

218-
bool listChanged = false;
213+
// Create a new list to trigger the property setter
214+
var newActiveAssemblies = new List<string>(_projectSettings.ActiveAssemblies);
219215

220216
for (int i = 0; i < _assembliesNames.Count; i++)
221217
{
222218
string name = _assembliesNames[i];
223-
bool active = _projectSettings.ActiveAssemblies.Contains(name);
219+
bool active = newActiveAssemblies.Contains(name);
224220
int layer = 1 << i;
225221
bool selected = (_assembliesFlag & layer) != 0;
226222

227223
if (!active && selected)
228224
{
229-
_projectSettings.ActiveAssemblies.Add(name);
230-
listChanged = true;
225+
newActiveAssemblies.Add(name);
231226
}
232227
else if (active && !selected)
233228
{
234-
_projectSettings.ActiveAssemblies.Remove(name);
235-
listChanged = true;
229+
newActiveAssemblies.Remove(name);
236230
}
237231
}
238232

239-
if (listChanged)
240-
{
241-
SaveProjectSettings();
242-
}
233+
_projectSettings.ActiveAssemblies = newActiveAssemblies;
243234
}
244235
});
245236
}
246237
}
247238

248-
private void BindToggle(Toggle toggle, string propertyPath)
239+
private void BindToggleWithCallback(Toggle toggle, string fieldPath, System.Action<bool> onValueChanged)
249240
{
250241
if (toggle == null) return;
251242

252243
toggle.SetBinding("value", new DataBinding
253244
{
254-
dataSourcePath = new PropertyPath(propertyPath)
245+
dataSourcePath = new PropertyPath(fieldPath)
246+
});
247+
248+
toggle.RegisterValueChangedCallback(evt =>
249+
{
250+
if (_projectSettings != null)
251+
{
252+
onValueChanged?.Invoke(evt.newValue);
253+
}
255254
});
256255
}
257256

@@ -288,13 +287,6 @@ public void Hide()
288287
_container.style.display = DisplayStyle.None;
289288
}
290289

291-
private void SaveProjectSettings()
292-
{
293-
if (_projectSettings != null)
294-
{
295-
EditorUtility.SetDirty(_projectSettings);
296-
AssetDatabase.SaveAssets();
297-
}
298-
}
290+
299291
}
300292
}

Runtime/Core/Context/JahroConfig.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@ public enum Environment
1010

1111
internal const Environment ENV = Environment.PROD;
1212

13-
public static readonly string CurrentVersion = "0.1.0-alpha.7";
13+
public static readonly string CurrentVersion = "0.1.0-alpha.8";
1414

1515
internal static readonly string RegisterUrl = "https://console.jahro.io";
1616

1717
public static readonly string ChangelogUrl = "https://jahro.io/changelog";
1818

1919
internal static readonly string DocumentationRoot = "https://docs.jahro.io/";
2020

21-
internal static readonly string DocumentationWatcherOverview = "https://docs.jahro.io/start-here/watcher";
21+
internal static readonly string DocumentationWatcherOverview = "https://jahro.io/docs/watcher";
2222

23-
internal static readonly string DocumentationCommandsOverview = "https://docs.jahro.io/start-here/commands";
23+
internal static readonly string DocumentationCommandsOverview = "https://jahro.io/docs/unity-commands";
2424

2525
internal static readonly string HostUrl = ENV == Environment.PROD ? "https://api.jahro.io/jahro-api" : "http://localhost:3000";
2626
}

Runtime/Core/Data/JahroProjectSettings.cs

Lines changed: 105 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
using System.Collections.Generic;
22
using UnityEngine;
33
using System.Linq;
4+
using System;
45

56
namespace JahroConsole.Core.Data
67
{
7-
88
public class JahroProjectSettings : ScriptableObject, IProjectSettings
99
{
1010
[SerializeField]
@@ -31,21 +31,116 @@ public class JahroProjectSettings : ScriptableObject, IProjectSettings
3131
[SerializeField]
3232
private bool _autoDisableInRelease;
3333

34-
public bool JahroEnabled { get => _jahroEnabled; set => _jahroEnabled = value; }
34+
public event Action OnSettingsChanged;
3535

36-
public bool UseLaunchKeyboardShortcut { get => _useLaunchKeyboardShortcut; set => _useLaunchKeyboardShortcut = value; }
36+
public bool JahroEnabled
37+
{
38+
get => _jahroEnabled;
39+
set
40+
{
41+
if (_jahroEnabled != value)
42+
{
43+
_jahroEnabled = value;
44+
NotifySettingsChanged();
45+
}
46+
}
47+
}
3748

38-
public bool UseLaunchTapArea { get => _useLaunchTapArea; set => _useLaunchTapArea = value; }
49+
public bool UseLaunchKeyboardShortcut
50+
{
51+
get => _useLaunchKeyboardShortcut;
52+
set
53+
{
54+
if (_useLaunchKeyboardShortcut != value)
55+
{
56+
_useLaunchKeyboardShortcut = value;
57+
NotifySettingsChanged();
58+
}
59+
}
60+
}
3961

40-
public KeyCode LaunchKey { get => _launchKey; set => _launchKey = value; }
62+
public bool UseLaunchTapArea
63+
{
64+
get => _useLaunchTapArea;
65+
set
66+
{
67+
if (_useLaunchTapArea != value)
68+
{
69+
_useLaunchTapArea = value;
70+
NotifySettingsChanged();
71+
}
72+
}
73+
}
4174

42-
public List<string> ActiveAssemblies { get => _activeAssemblies; set => _activeAssemblies = value; }
75+
public KeyCode LaunchKey
76+
{
77+
get => _launchKey;
78+
set
79+
{
80+
if (_launchKey != value)
81+
{
82+
_launchKey = value;
83+
NotifySettingsChanged();
84+
}
85+
}
86+
}
4387

44-
public bool DuplicateToUnityConsole { get => _duplicateToUnityConsole; set => _duplicateToUnityConsole = value; }
88+
public List<string> ActiveAssemblies
89+
{
90+
get => _activeAssemblies;
91+
set
92+
{
93+
if (_activeAssemblies != value)
94+
{
95+
_activeAssemblies = value;
96+
NotifySettingsChanged();
97+
}
98+
}
99+
}
45100

46-
public string APIKey { get => _APIKey; set => _APIKey = value; }
101+
public bool DuplicateToUnityConsole
102+
{
103+
get => _duplicateToUnityConsole;
104+
set
105+
{
106+
if (_duplicateToUnityConsole != value)
107+
{
108+
_duplicateToUnityConsole = value;
109+
NotifySettingsChanged();
110+
}
111+
}
112+
}
47113

48-
public bool AutoDisableInRelease { get => _autoDisableInRelease; set => _autoDisableInRelease = value; }
114+
public string APIKey
115+
{
116+
get => _APIKey;
117+
set
118+
{
119+
if (_APIKey != value)
120+
{
121+
_APIKey = value;
122+
NotifySettingsChanged();
123+
}
124+
}
125+
}
126+
127+
public bool AutoDisableInRelease
128+
{
129+
get => _autoDisableInRelease;
130+
set
131+
{
132+
if (_autoDisableInRelease != value)
133+
{
134+
_autoDisableInRelease = value;
135+
NotifySettingsChanged();
136+
}
137+
}
138+
}
139+
140+
private void NotifySettingsChanged()
141+
{
142+
OnSettingsChanged?.Invoke();
143+
}
49144

50145
public static bool isSettingsFileExists()
51146
{
@@ -67,15 +162,14 @@ public static JahroProjectSettings CreateDefault()
67162
{
68163
var settings = ScriptableObject.CreateInstance<JahroProjectSettings>();
69164
settings._APIKey = "";
70-
settings.JahroEnabled = true;
165+
settings._jahroEnabled = true;
71166
settings._useLaunchKeyboardShortcut = true;
72167
settings._useLaunchTapArea = true;
73168
settings._activeAssemblies = new List<string>();
74169
settings._duplicateToUnityConsole = false;
75170
settings._launchKey = KeyCode.BackQuote;
76171
settings._autoDisableInRelease = false;
77172

78-
79173
#if UNITY_EDITOR
80174
var assemblies = UnityEditor.Compilation.CompilationPipeline.GetAssemblies(UnityEditor.Compilation.AssembliesType.Player)
81175
.Where(assembly =>
@@ -92,6 +186,5 @@ public static JahroProjectSettings CreateDefault()
92186
#endif
93187
return settings;
94188
}
95-
96189
}
97190
}

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
22
"name": "io.jahro.console",
3-
"version": "0.1.0-alpha.7",
3+
"version": "0.1.0-alpha.8",
44
"displayName": "Jahro",
55
"description": "Jahro is a powerful and easy-to-use Unity debugging console and runtime tool. Effortlessly execute commands, monitor variables in real-time, capture logs, and sync snapshots to analyze your game like never before. Perfect for developers who want a smarter way to debug, test, and optimize their Unity projects!",
6-
"unity": "2019.1",
6+
"unity": "2021.1",
77
"unityRelease": "0b5",
88
"dependencies": {},
99
"keywords": [

0 commit comments

Comments
 (0)