From 8510111cdcf34f426350571250ae57995107618a Mon Sep 17 00:00:00 2001 From: Talo Halton Date: Sat, 4 May 2024 12:50:30 +0100 Subject: [PATCH] Add --icon option, make icon.png square --- icon.png | Bin 5914 -> 1955 bytes .../indicator/TrayIndicatorImpl.kt.linux | 9 +++++++-- .../strings/ServerLocalisation.kt | 1 + .../strings/ServerLocalisationEn.kt | 1 + .../strings/ServerLocalisationJa.kt | 1 + .../kotlin/spms/server/SpMsCommand.kt | 15 +++++++++++---- 6 files changed, 21 insertions(+), 6 deletions(-) diff --git a/icon.png b/icon.png index e14d336e6f66e37888ed15c8248c34b4bf191105..52f0075a5c55832b51569cc194be411ae568777c 100644 GIT binary patch delta 1954 zcmV;T2VMA@E~5{S7k@wq1^@s6s%dfF00004b3#c}2nYxWd4EBCe_5@sH5N#r|AmSIOG{>(7 z_RpcE1-LO~B6b7kl;gc8ebyklCNgFM@o)Ya;JXDhjei7Qjo9A_9M!1(TB26qn*c!< zFwhv&7kD=!?hc?&3EKJt4@7tt7v&Hz%`mXzVrT=S2*^A28T% z%_^|S5PxxN2Cfl6YXPly8r%;yYE!`GfWb9JUu(ha1cpX9h60N#eY=7AH1M_nhvK)u zBzBNvt4$jHI$-d1qwkr<6Zm@yM`$JQ0&dMK9C*pl@Z)6P)P*CmStrO?(>q`jeqtdjP|!ucw)!vQIh6MdIR`TiXBN> zX0+F7%Q69@jrK2%_8~_5`V3rY_<^KXfQNyDBK<6`I&E1d-~^-n1EYOVpsia{X9lh; zaFWiGvZ! zw0}!JIT=D|0?K;&NgQb`jG5Q1v^U@~Ndp4yFFNPyoC5kvIylgOa|%zRSZ2Igqm2G_ zpN2UBl|{xn>i*4WZ<7>?^FOk93gBZ&7aG4EX|&g^TUIFBN74fdze=A=dfXtewy2dx zdn4E>>9>-Oan8MG^!cIDZuQ?2z+5Ae0)MzVGH!t}=8O!S*6FbpPvI|6Vs;!pkC?=6 zU_=(@PbC~ngHLCNqCx?~@S$rGUt=Uq65~IJIQ|ZSFx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su7oXLEk`$I>`RrLb{HH!t8Gy@*kO26|Cpk|(#o<1-D_6hT%||Qq7QVZ z@%7K&m_4(h+;y0%7$;VDJU!HfvuV5P1xviSS_yn~U=2#Dn1U=+d>=$`u7&fPcG4U# z*vK!M$0Y22Xg))yGU>u>Mxn*l86#AAamD8RJ)+%KuCKGN&`Ye+_q>40DJf5--}L-t za<#f{#_-u2&1Xn8Jb#7m5uI5tM~6l-8e95qn8;h>1VpVSa|uV~FZh?gpg^%nZ#2fd VC@IUG1Af&|48NtmKYPc1_itPS+VTJZ diff --git a/src/commonMain/kotlin/cinterop/indicator/TrayIndicatorImpl.kt.linux b/src/commonMain/kotlin/cinterop/indicator/TrayIndicatorImpl.kt.linux index 6ba4ac6..494416e 100644 --- a/src/commonMain/kotlin/cinterop/indicator/TrayIndicatorImpl.kt.linux +++ b/src/commonMain/kotlin/cinterop/indicator/TrayIndicatorImpl.kt.linux @@ -118,10 +118,15 @@ class TrayIndicatorImpl(name: String, icon_path: List): TrayIndicator { app_indicator_set_status(indicator, AppIndicatorStatus.APP_INDICATOR_STATUS_ACTIVE) val path: MutableList = icon_path.toMutableList() - val icon_file: String = path.removeLast().split('.', limit = 2).first() + + var filename: String = path.removeLast() + val last_dot: Int = filename.lastIndexOf('.') + if (last_dot != -1) { + filename = filename.substring(0, last_dot) + } app_indicator_set_icon_theme_path(indicator, '/' + path.joinToString("/")) - app_indicator_set_icon_full(indicator, icon_file, name) + app_indicator_set_icon_full(indicator, filename, name) menu = gtk_menu_new()!! diff --git a/src/commonMain/kotlin/spms/localisation/strings/ServerLocalisation.kt b/src/commonMain/kotlin/spms/localisation/strings/ServerLocalisation.kt index e5f165f..5c2ca06 100644 --- a/src/commonMain/kotlin/spms/localisation/strings/ServerLocalisation.kt +++ b/src/commonMain/kotlin/spms/localisation/strings/ServerLocalisation.kt @@ -10,6 +10,7 @@ interface ServerLocalisation { val option_help_gui: String val option_help_mute: String val option_help_headless: String + val option_help_icon: String val indicator_button_open_client: String val indicator_button_stop_server: String diff --git a/src/commonMain/kotlin/spms/localisation/strings/ServerLocalisationEn.kt b/src/commonMain/kotlin/spms/localisation/strings/ServerLocalisationEn.kt index 8b12239..0f76e3c 100644 --- a/src/commonMain/kotlin/spms/localisation/strings/ServerLocalisationEn.kt +++ b/src/commonMain/kotlin/spms/localisation/strings/ServerLocalisationEn.kt @@ -11,6 +11,7 @@ class ServerLocalisationEn: ServerLocalisation { override val option_help_gui: String = "Show mpv's graphical interface" override val option_help_mute: String = "Mute player on startup" override val option_help_headless: String = "Run without mpv" + override val option_help_icon: String = "Path to icon" override val indicator_button_open_client: String = "Open client" override val indicator_button_stop_server: String = "Stop" diff --git a/src/commonMain/kotlin/spms/localisation/strings/ServerLocalisationJa.kt b/src/commonMain/kotlin/spms/localisation/strings/ServerLocalisationJa.kt index 82a2d17..7dc190e 100644 --- a/src/commonMain/kotlin/spms/localisation/strings/ServerLocalisationJa.kt +++ b/src/commonMain/kotlin/spms/localisation/strings/ServerLocalisationJa.kt @@ -11,6 +11,7 @@ class ServerLocalisationJa: ServerLocalisation { override val option_help_gui: String = "mpvのグラフィカルインタフェースを表示" override val option_help_mute: String = "実行時にプレイヤーをミュートする" override val option_help_headless: String = "mpvプレイヤーなしで実行" + override val option_help_icon: String = "アイコンへのパス" override val indicator_button_open_client: String = "クライアントを開く" override val indicator_button_stop_server: String = "終了" diff --git a/src/commonMain/kotlin/spms/server/SpMsCommand.kt b/src/commonMain/kotlin/spms/server/SpMsCommand.kt index 622f7e6..b132fc2 100644 --- a/src/commonMain/kotlin/spms/server/SpMsCommand.kt +++ b/src/commonMain/kotlin/spms/server/SpMsCommand.kt @@ -38,15 +38,21 @@ private const val CLIENT_REPLY_TIMEOUT_MS: Long = 10000 @Suppress("OPT_IN_USAGE") @OptIn(ExperimentalForeignApi::class) -fun createIndicator(coroutine_scope: CoroutineScope, loc: SpMsLocalisation, port: Int, endProgram: () -> Unit): TrayIndicator? { +fun createIndicator( + coroutine_scope: CoroutineScope, + loc: SpMsLocalisation, + port: Int, + user_icon_path: String?, + endProgram: () -> Unit +): TrayIndicator? { val icon_path: Path = - when (Platform.osFamily) { + user_icon_path?.toPath() ?: when (Platform.osFamily) { OsFamily.LINUX -> "/tmp/ic_spmp.png".toPath() OsFamily.WINDOWS -> "${getenv("USERPROFILE")!!.toKString()}/AppData/Local/Temp/ic_spmp.png".toPath() else -> throw NotImplementedError(Platform.osFamily.name) } - if (!FileSystem.SYSTEM.exists(icon_path)) { + if (user_icon_path == null && !FileSystem.SYSTEM.exists(icon_path)) { val parent: Path = icon_path.parent!! if (!FileSystem.SYSTEM.exists(parent)) { FileSystem.SYSTEM.createDirectories(parent, true) @@ -98,6 +104,7 @@ class SpMsCommand: Command( ) { private val port: Int by option("-p", "--port").int().default(SPMS_DEFAULT_PORT).help { context.loc.server.option_help_port } private val headless: Boolean by option("-x", "--headless").flag().help { context.loc.server.option_help_headless } + private val icon_path: String? by option("-i", "--icon").help { context.loc.server.option_help_icon } private val player_options: PlayerOptions by PlayerOptions() override fun run() { @@ -125,7 +132,7 @@ class SpMsCommand: Command( runBlocking { try { - val indicator: TrayIndicator? = createIndicator(this, localisation, port) { + val indicator: TrayIndicator? = createIndicator(this, localisation, port, icon_path) { stop = true }