|
27 | 27 | import haveno.common.crypto.KeyRing;
|
28 | 28 | import haveno.common.crypto.PubKeyRing;
|
29 | 29 | import haveno.common.crypto.Sig;
|
| 30 | +import haveno.common.file.FileUtil; |
30 | 31 | import haveno.common.util.Utilities;
|
| 32 | +import haveno.core.api.CoreNotificationService; |
31 | 33 | import haveno.core.api.XmrConnectionService;
|
32 | 34 | import haveno.core.app.HavenoSetup;
|
33 | 35 | import haveno.core.offer.OfferPayload;
|
|
36 | 38 | import haveno.core.support.dispute.arbitration.arbitrator.Arbitrator;
|
37 | 39 | import haveno.core.trade.messages.PaymentReceivedMessage;
|
38 | 40 | import haveno.core.trade.messages.PaymentSentMessage;
|
| 41 | +import haveno.core.user.Preferences; |
39 | 42 | import haveno.core.util.JsonUtil;
|
40 | 43 | import haveno.core.xmr.wallet.XmrWalletService;
|
41 | 44 | import haveno.network.p2p.NodeAddress;
|
| 45 | + |
| 46 | +import java.io.File; |
42 | 47 | import java.math.BigDecimal;
|
43 | 48 | import java.math.BigInteger;
|
44 | 49 | import java.net.InetAddress;
|
|
53 | 58 | import java.util.List;
|
54 | 59 | import java.util.Locale;
|
55 | 60 | import java.util.concurrent.CountDownLatch;
|
| 61 | + |
| 62 | +import javax.sound.sampled.AudioFormat; |
| 63 | +import javax.sound.sampled.AudioInputStream; |
| 64 | +import javax.sound.sampled.AudioSystem; |
| 65 | +import javax.sound.sampled.DataLine; |
| 66 | +import javax.sound.sampled.SourceDataLine; |
| 67 | + |
56 | 68 | import lombok.extern.slf4j.Slf4j;
|
57 | 69 | import monero.common.MoneroRpcConnection;
|
58 | 70 | import monero.daemon.model.MoneroOutput;
|
@@ -110,11 +122,18 @@ public static Object getWalletFunctionLock() {
|
110 | 122 | public static XmrWalletService xmrWalletService;
|
111 | 123 | public static XmrConnectionService xmrConnectionService;
|
112 | 124 | public static OpenOfferManager openOfferManager;
|
| 125 | + public static CoreNotificationService notificationService; |
| 126 | + public static Preferences preferences; |
113 | 127 |
|
114 | 128 | public static boolean isSeedNode() {
|
115 | 129 | return havenoSetup == null;
|
116 | 130 | }
|
117 | 131 |
|
| 132 | + public static boolean isDaemon() { |
| 133 | + if (isSeedNode()) return true; |
| 134 | + return havenoSetup.getCoreContext().isApiUser(); |
| 135 | + } |
| 136 | + |
118 | 137 | @SuppressWarnings("unused")
|
119 | 138 | public static Date getReleaseDate() {
|
120 | 139 | if (RELEASE_DATE == null) return null;
|
@@ -533,4 +552,60 @@ public static boolean isTransactionRejected(Throwable e) {
|
533 | 552 | public static boolean isIllegal(Throwable e) {
|
534 | 553 | return e instanceof IllegalArgumentException || e instanceof IllegalStateException;
|
535 | 554 | }
|
| 555 | + |
| 556 | + public static void playChimeSound() { |
| 557 | + playAudioFile("chime.wav"); |
| 558 | + } |
| 559 | + |
| 560 | + public static void playCashRegisterSound() { |
| 561 | + playAudioFile("cash_register.wav"); |
| 562 | + } |
| 563 | + |
| 564 | + private static void playAudioFile(String fileName) { |
| 565 | + if (isDaemon()) return; // ignore if running as daemon |
| 566 | + if (!preferences.getUseSoundForNotificationsProperty().get()) return; // ignore if sounds disabled |
| 567 | + new Thread(() -> { |
| 568 | + try { |
| 569 | + |
| 570 | + // get audio file |
| 571 | + File wavFile = new File(havenoSetup.getConfig().appDataDir, fileName); |
| 572 | + if (!wavFile.exists()) FileUtil.resourceToFile(fileName, wavFile); |
| 573 | + AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(wavFile); |
| 574 | + |
| 575 | + // get original format |
| 576 | + AudioFormat baseFormat = audioInputStream.getFormat(); |
| 577 | + |
| 578 | + // set target format: PCM_SIGNED, 16-bit |
| 579 | + AudioFormat targetFormat = new AudioFormat( |
| 580 | + AudioFormat.Encoding.PCM_SIGNED, |
| 581 | + baseFormat.getSampleRate(), |
| 582 | + 16, // 16-bit instead of 32-bit float |
| 583 | + baseFormat.getChannels(), |
| 584 | + baseFormat.getChannels() * 2, // Frame size: 2 bytes per channel (16-bit) |
| 585 | + baseFormat.getSampleRate(), |
| 586 | + false // Little-endian |
| 587 | + ); |
| 588 | + |
| 589 | + // convert audio to target format |
| 590 | + AudioInputStream convertedStream = AudioSystem.getAudioInputStream(targetFormat, audioInputStream); |
| 591 | + |
| 592 | + // play audio |
| 593 | + DataLine.Info info = new DataLine.Info(SourceDataLine.class, targetFormat); |
| 594 | + SourceDataLine sourceLine = (SourceDataLine) AudioSystem.getLine(info); |
| 595 | + sourceLine.open(targetFormat); |
| 596 | + sourceLine.start(); |
| 597 | + byte[] buffer = new byte[1024]; |
| 598 | + int bytesRead = 0; |
| 599 | + while ((bytesRead = convertedStream.read(buffer, 0, buffer.length)) != -1) { |
| 600 | + sourceLine.write(buffer, 0, bytesRead); |
| 601 | + } |
| 602 | + sourceLine.drain(); |
| 603 | + sourceLine.close(); |
| 604 | + convertedStream.close(); |
| 605 | + audioInputStream.close(); |
| 606 | + } catch (Exception e) { |
| 607 | + e.printStackTrace(); |
| 608 | + } |
| 609 | + }).start(); |
| 610 | + } |
536 | 611 | }
|
0 commit comments