Skip to content

Commit 6fde588

Browse files
committed
Fix android tile service
1 parent 201062d commit 6fde588

File tree

15 files changed

+46
-25
lines changed

15 files changed

+46
-25
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/controller.dart

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,17 @@ class CoreController {
9191
return await _interface.updateConfig(updateParams);
9292
}
9393

94-
Future<String> setupConfig(ClashConfig clashConfig) async {
94+
Future<String> setupConfig(
95+
ClashConfig clashConfig, {
96+
VoidCallback? preloadInvoke,
97+
}) async {
9598
await globalState.genConfigFile(clashConfig);
9699
final params = await globalState.getSetupParams();
97-
return await _interface.setupConfig(params);
100+
final res = _interface.setupConfig(params);
101+
if (preloadInvoke != null) {
102+
preloadInvoke();
103+
}
104+
return res;
98105
}
99106

100107
Future<List<Group>> getProxiesGroups({

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: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,18 @@ 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(
43+
clashConfig,
44+
preloadInvoke: () {
45+
globalState.handleStart();
46+
},
47+
);
4648
}
4749

4850
@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
}

0 commit comments

Comments
 (0)