Skip to content

Commit f523741

Browse files
cjcxjqiin2333
authored andcommitted
修复合并出现的错误
1 parent a8bf9a9 commit f523741

File tree

8 files changed

+121
-65
lines changed

8 files changed

+121
-65
lines changed

app/src/main/java/com/limelight/Game.java

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
import android.content.ServiceConnection;
5858
import android.content.SharedPreferences;
5959
import android.content.pm.ActivityInfo;
60+
import android.content.pm.PackageManager;
6061
import android.content.res.Configuration;
6162
import android.graphics.Point;
6263
import android.graphics.Rect;
@@ -1241,7 +1242,7 @@ public void onRequestPermissionsResult(int requestCode, String[] permissions, in
12411242
// Check if the permission was granted
12421243
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
12431244
// 用户给了权限,立即启动服务
1244-
StreamNotificationService.start(this, currentHostAddress, appName);
1245+
StreamNotificationService.start(this, pcName, appName);
12451246
} else {
12461247
// Permission denied, show a toast message
12471248
Toast.makeText(this, "没有通知权限,后台串流可能会中断", Toast.LENGTH_LONG).show();
@@ -1909,6 +1910,15 @@ public void changeResolution() {
19091910
protected void onStop() {
19101911
super.onStop();
19111912

1913+
if ((isExtremeResumeEnabled || isChangingResolution) && !isFinishing()) {
1914+
LimeLog.info("Extreme Resume: onStop intercepted.");
1915+
// 只有在不是修改分辨率的情况下(即真的是切到后台了),才发通知
1916+
if (!isChangingResolution) {
1917+
showKeepAliveNotification();
1918+
}
1919+
return;
1920+
}
1921+
19121922
// 暂停串流时长计时(进入后台时串流实际上是暂停的)
19131923
if (isStreamingActive && lastActiveTime > 0) {
19141924
accumulatedStreamTime += System.currentTimeMillis() - lastActiveTime;
@@ -4011,7 +4021,7 @@ public void connectionStarted() {
40114021
// 此时 App 在前台,可以合法启动 Foreground Service
40124022
showKeepAliveNotification();
40134023
}
4014-
});
4024+
);
40154025

40164026
// Report this shortcut being used (off the main thread to prevent ANRs)
40174027
ComputerDetails computer = new ComputerDetails();
@@ -4479,7 +4489,7 @@ public void surfaceDestroyed(SurfaceHolder holder) {
44794489
try {
44804490
decoderRenderer.setRenderTarget(mDummyHolder);
44814491
} catch (Exception e) {
4482-
e.printStackTrace();
4492+
LimeLog.warning("Failed to set render target to dummy holder: "+e.getMessage());
44834493
}
44844494
}
44854495
return; // 安全返回,后台继续解码
@@ -4561,7 +4571,7 @@ private void showKeepAliveNotification() {
45614571
}
45624572

45634573
// 2. 启动服务 + 通知
4564-
StreamNotificationService.start(this, currentHostAddress, appName);
4574+
StreamNotificationService.start(this, pcName, appName);
45654575
}
45664576

45674577
private void cancelKeepAliveNotification() {
@@ -4695,7 +4705,7 @@ private void startCursorService(String hostIp) {
46954705
}
46964706
}
46974707
} catch (Exception e) {
4698-
LimeLog.warning("CursorNet: 连接断开或失败: " + e.getMessage());
4708+
LimeLog.warning("CursorNet: Connection disconnected or failed: " + e.getMessage());
46994709
} finally {
47004710
try { if (cursorSocket != null) cursorSocket.close(); } catch (Exception ignored) {}
47014711
cursorSocket = null;
@@ -5275,7 +5285,8 @@ public DummySurfaceHolder() {
52755285
if (image != null) {
52765286
image.close();
52775287
}
5278-
} catch (Exception ignored) {
5288+
} catch (Exception e) {
5289+
LimeLog.warning("DummySurfaceHolder: Exception while acquiring/closing image: " + e.getMessage());
52795290
}
52805291
}, mDrainHandler);
52815292

app/src/main/java/com/limelight/GameMenu.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1801,7 +1801,7 @@ private void buildNormalMenuOptions(List<MenuOption> normalOptions) {
18011801
));
18021802

18031803
normalOptions.add(new MenuOption(
1804-
"更改分辨率 Change Resolution",
1804+
getString(R.string.game_menu_change_resolution),
18051805
false,
18061806
this::showResolutionMenu,
18071807
"game_menu_change_resolution",

app/src/main/java/com/limelight/services/StreamNotificationService.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,17 @@ public class StreamNotificationService extends Service {
2424
private static final int NOTIFICATION_ID = 1001;
2525

2626
// Intent 参数键名
27-
private static final String EXTRA_HOST_NAME = "extra_host_name";
27+
private static final String EXTRA_PC_NAME = "extra_pc_name";
2828
private static final String EXTRA_APP_NAME = "extra_app_name";
2929

30-
public static void start(Context context, String hostName, String appName) {
30+
public static void start(Context context, String pcName, String appName) {
3131
Intent intent = new Intent(context, StreamNotificationService.class);
32-
intent.putExtra(EXTRA_HOST_NAME, hostName);
32+
intent.putExtra(EXTRA_PC_NAME, pcName);
3333
intent.putExtra(EXTRA_APP_NAME, appName);
3434
try {
3535
ContextCompat.startForegroundService(context, intent);
3636
} catch (Exception e) {
37-
e.printStackTrace();
37+
LimeLog.severe("Failed to start foreground service: " + e.getMessage());
3838
}
3939
}
4040

@@ -61,13 +61,13 @@ public void onCreate() {
6161
@Override
6262
public int onStartCommand(Intent intent, int flags, int startId) {
6363
// 构建默认通知 (防御性,防止 intent 为空)
64-
String hostName = "Unknown";
65-
String appName = "Moonlight";
64+
String pcName = "Unknown";
65+
String appName = "Desktop";
6666
if (intent != null) {
67-
hostName = intent.getStringExtra(EXTRA_HOST_NAME);
67+
pcName = intent.getStringExtra(EXTRA_PC_NAME);
6868
appName = intent.getStringExtra(EXTRA_APP_NAME);
6969
}
70-
Notification notification = buildNotification(hostName, appName);
70+
Notification notification = buildNotification(pcName, appName);
7171

7272
// =========================================================
7373
// 无论 intent 是否为空,无论是否要停止,
@@ -127,7 +127,7 @@ private void createNotificationChannel() {
127127
}
128128
}
129129

130-
private Notification buildNotification(String hostName, String appName) {
130+
private Notification buildNotification(String pcName, String appName) {
131131
// 点击通知跳转回 Game Activity
132132
Intent intent = new Intent(this, Game.class);
133133
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
@@ -139,9 +139,9 @@ private Notification buildNotification(String hostName, String appName) {
139139
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, intent, flags);
140140

141141
String title = "Moonlight-V+";
142-
String content = String.format("正在串流: %s (%s)",
142+
String content = getString(R.string.notification_content_streaming,
143143
appName != null ? appName : "Desktop",
144-
hostName != null ? hostName : "Unknown");
144+
pcName != null ? pcName : "Unknown");
145145

146146
return new NotificationCompat.Builder(this, CHANNEL_ID)
147147
.setSmallIcon(R.drawable.ic_play) // 确保图标资源存在

app/src/main/res/layout-land/activity_app_view.xml

Lines changed: 84 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -38,28 +38,31 @@
3838

3939
<ImageButton
4040
android:id="@+id/settingsButton"
41-
android:layout_width="70dp"
42-
android:layout_height="65dp"
41+
android:layout_width="50dp"
42+
android:layout_height="60dp"
4343
android:cropToPadding="false"
44-
android:scaleType="fitXY"
44+
android:scaleType="fitCenter"
4545
android:layout_marginTop="@dimen/activity_safearea_top"
46+
android:paddingTop="20dp"
4647
android:layout_alignParentLeft="true"
4748
android:layout_alignParentStart="true"
4849
android:layout_alignParentTop="true"
4950
android:src="@drawable/ic_settings"
5051
android:preferKeepClear="true"
52+
android:focusable="true"
53+
android:focusableInTouchMode="false"
5154
style="?android:attr/borderlessButtonStyle"/>
5255

5356
<ImageButton
5457
android:id="@+id/app_restoreSessionButton"
55-
android:layout_width="70dp"
56-
android:layout_height="65dp"
58+
android:layout_width="50dp"
59+
android:layout_height="60dp"
60+
android:paddingTop="20dp"
61+
android:scaleType="fitCenter"
5762
android:cropToPadding="false"
58-
android:scaleType="fitXY"
59-
android:layout_marginTop="@dimen/activity_safearea_top"
6063
android:layout_toRightOf="@+id/settingsButton"
6164
android:layout_toEndOf="@+id/settingsButton"
62-
android:layout_alignParentTop="true"
65+
android:layout_alignTop="@+id/settingsButton"
6366
android:src="@drawable/ic_restore"
6467
android:preferKeepClear="true"
6568
style="?android:attr/borderlessButtonStyle"/>
@@ -74,12 +77,16 @@
7477
android:layout_marginTop="20dp"
7578
android:layout_marginRight="20dp"
7679
android:layout_marginEnd="20dp"
77-
android:layout_marginLeft="150dp"
80+
android:layout_marginLeft="90dp"
7881
android:gravity="end"
7982
android:paddingTop="@dimen/activity_safearea_top"
8083
android:paddingBottom="15dp"
8184
android:preferKeepClear="true"
8285
android:textSize="24sp"
86+
android:autoSizeTextType="uniform"
87+
android:autoSizeMinTextSize="14sp"
88+
android:autoSizeMaxTextSize="28sp"
89+
android:autoSizeStepGranularity="1sp"
8390
android:textStyle="normal"
8491
android:fontFamily="sans-serif-light"
8592
android:textColor="#FFFFFF"
@@ -94,52 +101,85 @@
94101
android:breakStrategy="balanced"
95102
android:hyphenationFrequency="normal" />
96103

97-
<!-- 上一次设置信息显示区域 - 放在应用列表下方 -->
104+
<!-- 显示器选择信息显示区域 - 位于appListText下方 -->
98105
<LinearLayout
99-
android:id="@+id/lastSettingsInfo"
106+
android:id="@+id/displaySelectionInfo"
107+
android:layout_width="match_parent"
108+
android:layout_height="wrap_content"
109+
android:layout_below="@id/appFragmentContainer"
110+
android:layout_marginLeft="8dp"
111+
android:layout_marginRight="8dp"
112+
android:layout_marginEnd="8dp"
113+
android:layout_marginTop="8dp"
114+
android:orientation="vertical"
115+
android:gravity="start"
116+
android:visibility="gone">
117+
118+
<RadioGroup
119+
android:id="@+id/displayRadioGroup"
120+
android:layout_width="wrap_content"
121+
android:layout_height="wrap_content"
122+
android:orientation="vertical"
123+
android:gravity="start"
124+
android:layout_gravity="start" />
125+
126+
</LinearLayout>
127+
128+
<!-- 底部信息容器 - 包含上一次设置信息 -->
129+
<LinearLayout
130+
android:id="@+id/bottomInfoContainer"
100131
android:layout_width="match_parent"
101132
android:layout_height="wrap_content"
102133
android:layout_alignParentBottom="true"
103-
android:layout_marginTop="20dp"
104134
android:layout_marginLeft="20dp"
105135
android:layout_marginRight="20dp"
106136
android:layout_marginEnd="20dp"
107-
android:layout_marginBottom="20dp"
137+
android:layout_marginBottom="10dp"
108138
android:orientation="vertical"
109-
android:gravity="end"
110-
android:visibility="gone">
139+
android:gravity="end">
111140

112-
<CheckBox
113-
android:id="@+id/useLastSettingsCheckbox"
114-
android:layout_width="wrap_content"
115-
android:layout_height="wrap_content"
116-
android:layout_marginTop="5dp"
117-
android:focusable="true"
118-
android:text="@string/app_last_settings_use_checkbox"
119-
android:textColor="#CCFFFFFF"
120-
android:textSize="12sp"
121-
android:fontFamily="sans-serif-light"
122-
android:buttonTint="#FFFFFF"
123-
android:checked="false" />
124-
125-
<TextView
126-
android:id="@+id/lastSettingsText"
141+
<!-- 上一次设置信息显示区域 -->
142+
<LinearLayout
143+
android:id="@+id/lastSettingsInfo"
127144
android:layout_width="match_parent"
128145
android:layout_height="wrap_content"
129-
android:textSize="13sp"
130-
android:textColor="#CCFFFFFF"
131-
android:shadowColor="#80000000"
132-
android:shadowDx="1"
133-
android:shadowDy="1"
134-
android:shadowRadius="2"
135-
android:fontFamily="sans-serif-light"
136-
android:background="@drawable/settings_info_background"
137-
android:padding="8dp"
138-
android:maxLines="3"
139-
android:ellipsize="end"
140-
android:lineSpacingExtra="2dp"
141-
android:text="@string/app_last_settings_title" />
146+
android:orientation="vertical"
147+
android:gravity="end"
148+
android:visibility="gone">
149+
150+
<CheckBox
151+
android:id="@+id/useLastSettingsCheckbox"
152+
android:layout_width="wrap_content"
153+
android:layout_height="wrap_content"
154+
android:layout_marginTop="5dp"
155+
android:focusable="true"
156+
android:text="@string/app_last_settings_use_checkbox"
157+
android:textColor="#CCFFFFFF"
158+
android:textSize="12sp"
159+
android:fontFamily="sans-serif-light"
160+
android:buttonTint="#FFFFFF"
161+
android:checked="false" />
162+
163+
<TextView
164+
android:id="@+id/lastSettingsText"
165+
android:layout_width="match_parent"
166+
android:layout_height="wrap_content"
167+
android:textSize="13sp"
168+
android:textColor="#CCFFFFFF"
169+
android:shadowColor="#80000000"
170+
android:shadowDx="1"
171+
android:shadowDy="1"
172+
android:shadowRadius="2"
173+
android:fontFamily="sans-serif-light"
174+
android:background="@drawable/settings_info_background"
175+
android:padding="8dp"
176+
android:maxLines="3"
177+
android:ellipsize="end"
178+
android:lineSpacingExtra="2dp"
179+
android:text="@string/app_last_settings_title" />
180+
181+
</LinearLayout>
142182

143183
</LinearLayout>
144184

145-
</RelativeLayout>
185+
</RelativeLayout>

app/src/main/res/layout/activity_app_view.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@
5555

5656
<ImageButton
5757
android:id="@+id/app_restoreSessionButton"
58-
android:layout_width="70dp"
59-
android:layout_height="65dp"
58+
android:layout_width="50dp"
59+
android:layout_height="45dp"
6060
android:cropToPadding="false"
6161
android:scaleType="fitXY"
6262
android:layout_below="@+id/settingsButton"

app/src/main/res/values-zh-rCN/strings.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -686,4 +686,7 @@
686686
<string name="unpaired_devices_hidden">已隐藏未配对设备</string>
687687
<string name="new_unpaired_device_shown">检测到新的未配对设备,已自动显示未配对设备</string>
688688
<string name="host_resolution_changed">主机分辨率已变更为 %1$dx%2$d</string>
689+
690+
<string name="game_menu_change_resolution">更改分辨率</string>
691+
<string name="notification_content_streaming">正在串流: %s (%s)</string>
689692
</resources>

app/src/main/res/values/strings.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -725,5 +725,7 @@
725725
<!-- Drawer Menu -->
726726
<string name="menu">Menu</string>
727727
<string name="title_settings">Settings</string>
728+
<string name="game_menu_change_resolution">Change resolution</string>
729+
<string name="notification_content_streaming">Streaming in progress: %s (%s)</string>
728730

729731
</resources>

0 commit comments

Comments
 (0)