Skip to content

Commit 7c2331f

Browse files
committed
Fix android tile service
1 parent 201062d commit 7c2331f

File tree

14 files changed

+33
-23
lines changed

14 files changed

+33
-23
lines changed

android/app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666

6767
<activity
6868
android:name=".TempActivity"
69+
android:excludeFromRecents="true"
6970
android:exported="true"
7071
android:theme="@style/TransparentTheme">
7172
<intent-filter>

android/app/src/main/kotlin/com/follow/clash/State.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ object State {
9292

9393
suspend fun destroyServiceEngine() {
9494
runLock.withLock {
95+
GlobalState.log("Destroy service engine")
9596
withContext(Dispatchers.Main) {
9697
runCatching {
9798
serviceFlutterEngine?.destroy()
@@ -103,10 +104,12 @@ object State {
103104

104105
suspend fun startServiceWithEngine() {
105106
runLock.withLock {
106-
if (serviceFlutterEngine != null || runStateFlow.value == RunState.PENDING || runStateFlow.value == RunState.START) {
107+
if (runStateFlow.value == RunState.PENDING || runStateFlow.value == RunState.START) {
107108
return
108109
}
110+
GlobalState.log("Create service engine")
109111
withContext(Dispatchers.Main) {
112+
serviceFlutterEngine?.destroy()
110113
serviceFlutterEngine = FlutterEngine(GlobalState.application)
111114
serviceFlutterEngine?.plugins?.add(ServicePlugin())
112115
serviceFlutterEngine?.plugins?.add(AppPlugin())

android/app/src/main/kotlin/com/follow/clash/TempActivity.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,6 @@ class TempActivity : Activity(),
3030
}
3131
}
3232
}
33-
finishAndRemoveTask()
33+
finish()
3434
}
3535
}

core/hub.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ var (
3333
)
3434

3535
func handleInitClash(paramsString string) bool {
36+
runLock.Lock()
37+
defer runLock.Unlock()
3638
var params = InitParams{}
3739
err := json.Unmarshal([]byte(paramsString), &params)
3840
if err != nil {

core/lib.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ type TunHandler struct {
3737
}
3838

3939
func (th *TunHandler) start(fd int, stack, address, dns string) {
40+
runLock.Lock()
41+
defer runLock.Unlock()
4042
_ = th.limit.Acquire(context.TODO(), 4)
4143
defer th.limit.Release(4)
4244
th.initHook()

lib/controller.dart

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -466,9 +466,6 @@ class AppController {
466466
Map<String, dynamic>? data,
467467
bool handleError = false,
468468
}) async {
469-
if (globalState.isPre) {
470-
return;
471-
}
472469
if (data != null) {
473470
final tagName = data['tag_name'];
474471
final body = data['body'];
@@ -962,7 +959,7 @@ class AppController {
962959
final res = await futureFunction();
963960
return res;
964961
} catch (e) {
965-
commonPrint.log('$futureFunction ===> $e', logLevel: LogLevel.warning);
962+
commonPrint.log('$title===> $e', logLevel: LogLevel.warning);
966963
if (realSilence) {
967964
globalState.showNotifier(e.toString());
968965
} else {

lib/core/interface.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ abstract class CoreHandlerInterface with CoreInterface {
157157
@override
158158
Future<Result> getConfig(String path) async {
159159
return await _invoke<Result>(method: ActionMethod.getConfig, data: path) ??
160-
Result<Map<String, dynamic>>.success({});
160+
Result.success({});
161161
}
162162

163163
@override

lib/main.dart

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,14 @@ Future<void> _service(List<String> flags) async {
3333
},
3434
),
3535
);
36-
Future(() async {
37-
app?.tip(appLocalizations.startVpn);
38-
final version = await system.version;
39-
await coreController.init(version);
40-
final clashConfig = globalState.config.patchClashConfig.copyWith.tun(
41-
enable: false,
42-
);
43-
await globalState.handleStart();
44-
await coreController.setupConfig(clashConfig);
45-
});
36+
app?.tip(appLocalizations.startVpn);
37+
final version = await system.version;
38+
await coreController.init(version);
39+
final clashConfig = globalState.config.patchClashConfig.copyWith.tun(
40+
enable: false,
41+
);
42+
coreController.setupConfig(clashConfig);
43+
globalState.handleStart();
4644
}
4745

4846
@immutable

lib/models/core.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ extension ActionResultExt on ActionResult {
192192
if (code == ResultType.success) {
193193
return Result.success(data);
194194
} else {
195-
return Result.error(data);
195+
return Result.error('$data');
196196
}
197197
}
198198
}

lib/state.dart

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,13 @@ class GlobalState {
304304

305305
Future<void> genConfigFile(ClashConfig pathConfig) async {
306306
final configFilePath = await appPath.configFilePath;
307-
final config = await patchRawConfig(patchConfig: pathConfig);
307+
var config = {};
308+
try {
309+
config = await patchRawConfig(patchConfig: pathConfig);
310+
} catch (e) {
311+
globalState.showNotifier(e.toString());
312+
config = {};
313+
}
308314
final res = await Isolate.run<String>(() async {
309315
try {
310316
final res = json.encode(config);

0 commit comments

Comments
 (0)