Skip to content

Instantly share code, notes, and snippets.

View CostaFot's full-sized avatar

Costa Fotiadis CostaFot

View GitHub Profile
event TypedEventHandler<object, IItemsChangedEventArgs> INotifyItemsChanged.ItemsChanged
{
add { _itemsChanged += value; RefreshPackages(); } // <-- the whole point
remove => _itemsChanged -= value;
}
process.Start();
string stdout = process.StandardOutput.ReadToEnd();
string stderr = process.StandardError.ReadToEnd();
process.WaitForExit(); // do NOT move this above the reads
internal sealed partial class ClearAppDataCommand : InvokableCommand
{
private readonly string _packageName;
public ClearAppDataCommand(string packageName)
{
_packageName = packageName;
Name = "Clear App Data";
}
buildTypes.release.proguard {
configurationFiles.from("proguard-rules.pro")
}
Tray(
icon = clockIcon(),
tooltip = "DogeClock",
menu = {
Item(if (isVisible) "Hide" else "Show", onClick = { isVisible = !isVisible })
Separator()
Item("Exit", onClick = ::exitApplication)
},
)
@Serializable
private data class PositionConfig(val x: Float, val y: Float)
class PositionRepository {
fun loadPosition(): WindowPosition? {
if (!configFile.exists()) return null
return try {
val config = Json.decodeFromString<PositionConfig>(configFile.readText())
WindowPosition(config.x.dp, config.y.dp)
} catch (e: Exception) {
val appModule = module {
single<WindowStyleHelper> {
if (System.getProperty("os.name").startsWith("Windows")) {
WindowsWindowStyleHelper()
} else {
// provide macOS or Linux implementations below
}
}
}
// Define which Windows functions we need
internal interface User32 : Library {
fun FindWindowA(className: String?, windowTitle: String?): Pointer?
fun GetWindowLongA(hwnd: Pointer, index: Int): Int
fun SetWindowLongA(hwnd: Pointer, index: Int, newStyle: Int): Int
}
class WindowsWindowStyleHelper : WindowStyleHelper {
// JNA loads the actual Windows DLL at runtime
val user32 = Native.load("user32", User32::class.java)
class ClockViewModel : ViewModel() {
// ....
init {
viewModelScope.launch {
while (true) {
delay(60.seconds)
_time.value = LocalTime.now().format(formatter)
}
}
}
init {
viewModelScope.launch {
while (true) {
delay((60 - LocalTime.now().second) * 1000L)
_time.value = LocalTime.now().format(formatter)
}
}
}