Skip to content

Commit

Permalink
Add --icon option, make icon.png square
Browse files Browse the repository at this point in the history
  • Loading branch information
toasterofbread committed May 4, 2024
1 parent 2ea8b11 commit 8510111
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 6 deletions.
Binary file modified icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,15 @@ class TrayIndicatorImpl(name: String, icon_path: List<String>): TrayIndicator {
app_indicator_set_status(indicator, AppIndicatorStatus.APP_INDICATOR_STATUS_ACTIVE)

val path: MutableList<String> = 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()!!

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "終了"
Expand Down
15 changes: 11 additions & 4 deletions src/commonMain/kotlin/spms/server/SpMsCommand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit 8510111

Please sign in to comment.