File tree Expand file tree Collapse file tree 10 files changed +44
-20
lines changed Expand file tree Collapse file tree 10 files changed +44
-20
lines changed Original file line number Diff line number Diff line change @@ -6,16 +6,17 @@ const RPC = require("../rpc/RPC");
6
6
*/
7
7
module . exports = ( mainWindow ) => {
8
8
ipcMain . on ( "setActivity" , async ( ev , name ) => {
9
- console . log ( "Activity Call" ) ;
10
9
if ( ! RPC . ready ) await RPC . login ( ) ;
11
- RPC . setActivity ( name ) ;
10
+ if ( RPC . ready ) RPC . setActivity ( name ) ;
12
11
} ) ;
13
12
14
13
ipcMain . on ( "destroyRPC" , ( ev ) => {
15
- RPC . logout ( ) ;
14
+ if ( RPC . ready ) RPC . logout ( ) ;
16
15
} ) ;
17
16
18
- ipcMain . on ( "reconnectRPC" , ( ev ) => {
19
- RPC . login ( ) ;
17
+ ipcMain . on ( "reconnectRPC" , async ( ev ) => {
18
+ if ( RPC . ready ) return ;
19
+ const success = await RPC . login ( ) ;
20
+ if ( success ) RPC . setActivity ( ) ;
20
21
} ) ;
21
22
} ;
Original file line number Diff line number Diff line change @@ -17,7 +17,7 @@ class RichPresence {
17
17
18
18
login ( ) {
19
19
console . log ( "Enabled?" , this . enabled ( ) ) ;
20
- if ( this . enabled ( ) ) return Promise . resolve ( false ) ;
20
+ if ( ! this . enabled ( ) ) return Promise . resolve ( false ) ;
21
21
22
22
return new Promise ( ( resolve ) => {
23
23
this . client . on ( "ready" , ( ) => {
@@ -29,37 +29,42 @@ class RichPresence {
29
29
. login ( {
30
30
clientId : this . id
31
31
} )
32
- . catch ( ( ) => resolve ( false ) ) ;
32
+ . catch ( ( e ) => {
33
+ console . error ( e ) ;
34
+ resolve ( false ) ;
35
+ } ) ;
33
36
} ) ;
34
37
}
35
38
36
39
setActivity ( title ) {
37
40
this . client
38
41
. setActivity ( {
39
42
details : title || "Scratch For Discord" ,
40
- timestamps : {
41
- start : this . startedAt
42
- } ,
43
- assets : {
44
- large_image : "large" ,
45
- large_text : `Scratch For Discord - v${ packageMeta . version } `
46
- } ,
43
+ startTimestamp : this . startedAt ,
47
44
buttons : [
48
45
{
49
46
label : "Download" ,
50
47
url : "https://androz2091.github.io/scratch-for-discord/download/index.html"
51
48
}
52
- ]
49
+ ] ,
50
+ largeImageKey : "large" ,
51
+ largeImageText : `Scratch For Discord - v${ packageMeta . version } ` ,
52
+ smallImageKey : "small" ,
53
+ smallImageText : "Scratch For Discord"
53
54
} )
54
- . catch ( ( ) => { } ) ;
55
+ . catch ( ( e ) => {
56
+ console . error ( e ) ;
57
+ } ) ;
55
58
}
56
59
57
60
logout ( ) {
58
61
this . client . destroy ( ) . then (
59
62
( ) => {
60
63
this . ready = false ;
61
64
} ,
62
- ( ) => { }
65
+ ( e ) => {
66
+ console . error ( e ) ;
67
+ }
63
68
) ;
64
69
}
65
70
}
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ const isDev = require("electron-is-dev");
3
3
const path = require ( "path" ) ;
4
4
const Updater = require ( "./updates/window" ) ;
5
5
const updater = new Updater ( ) ;
6
+ const rpc = require ( "./core/rpc/RPC" ) ;
6
7
require ( "./core/storage/database" ) ;
7
8
const S4D_PROTOCOL = "s4d" ;
8
9
let tray = null ,
@@ -90,8 +91,7 @@ async function createWindow() {
90
91
if ( mainWindow . maximizable ) mainWindow . maximize ( ) ;
91
92
// load extensions
92
93
new ( require ( "./core/ExtensionsLoader" ) ) ( mainWindow ) ;
93
- const rpc = require ( "./core/rpc/RPC" ) ;
94
- rpc . login ( ) . then ( ( ) => rpc . setActivity ( ) ) ;
94
+ rpc . login ( ) . then ( ( success ) => ( success ? rpc . setActivity ( ) : console . log ( "Could not start RPC" ) ) ) ;
95
95
} ) ;
96
96
97
97
mainWindow . webContents . setWindowOpenHandler ( ( handler ) => {
Original file line number Diff line number Diff line change 1
1
{
2
2
"name" : " scratch-for-discord" ,
3
- "version" : " 2.0.0-dev.10 " ,
3
+ "version" : " 2.0.0-dev.11 " ,
4
4
"private" : true ,
5
5
"main" : " environments/main.js" ,
6
6
"description" : " Build your own discord bot with scratch blocks." ,
33
33
"@fortawesome/free-solid-svg-icons" : " ^5.15.4" ,
34
34
"@fortawesome/react-fontawesome" : " ^0.1.15" ,
35
35
"@tailwindcss/forms" : " ^0.3.3" ,
36
+ "@types/discord-rpc" : " ^4.0.0" ,
36
37
"@types/http-server" : " ^0.12.1" ,
37
38
"@types/react" : " ^17.0.17" ,
38
39
"@types/react-router-dom" : " ^5.1.8" ,
Original file line number Diff line number Diff line change
1
+ import { useEffect } from "react" ;
2
+
1
3
export default function ExtensionStore ( ) {
4
+ useEffect ( ( ) => {
5
+ window . ScratchNative ?. sendMessage ( "setActivity" , "on S4D Store" ) ;
6
+ } , [ ] ) ;
7
+
2
8
return (
3
9
< div className = "dark:bg-gray-900 bg-white h-screen w-full overflow-scroll" >
4
10
< div className = "pt-5 px-20" >
Original file line number Diff line number Diff line change @@ -25,6 +25,7 @@ export default function HomeScreen() {
25
25
const routeHistory = useHistory ( ) ;
26
26
27
27
useEffect ( ( ) => {
28
+ window . ScratchNative ?. sendMessage ( "setActivity" , "Scratch For Discord" ) ;
28
29
console . log ( "[DEBUG] Loading recent workspace data..." ) ;
29
30
window . ScratchNative ?. onceMessage ( "recentWorkspace" , ( ev , data ) => {
30
31
setWorkspaces ( Array . isArray ( data ) ? data : [ ] ) ;
Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ export default function Settings() {
8
8
const [ settings , setSettings ] = useState ( null ) ;
9
9
10
10
function refresh ( ) {
11
+ window . ScratchNative ?. sendMessage ( "setActivity" , "on settings" ) ;
11
12
console . log ( "[DEBUG] Loading settings..." ) ;
12
13
const scratch = window . ScratchNative ;
13
14
@@ -41,6 +42,8 @@ export default function Settings() {
41
42
className = "form-select px-4 py-1 w-1/2 mt-1 rounded-md bg-gray-100 border-transparent focus:border-gray-500 dark:focus:bg-white focus:ring-0"
42
43
onChange = { ( e ) => {
43
44
window . ScratchNative ?. sendMessage ( "toggleRPC" , e . target . value === "on" ) ;
45
+ if ( e . target . value !== "on" ) window . ScratchNative ?. sendMessage ( "destroyRPC" ) ;
46
+ else if ( e . target . value === "on" ) window . ScratchNative ?. sendMessage ( "reconnectRPC" ) ;
44
47
refresh ( ) ;
45
48
} }
46
49
>
Original file line number Diff line number Diff line change @@ -14,6 +14,7 @@ export default class Workspace extends Component {
14
14
15
15
componentDidMount ( ) {
16
16
console . log ( "[DEBUG] Loading workspace..." ) ;
17
+ window . ScratchNative ?. sendMessage ( "setActivity" , "on Slash Commands GUI" ) ;
17
18
window . ScratchNative ?. onceMessage ( "connection" , ( ev , status ) => {
18
19
this . setState ( {
19
20
ready : status ,
Original file line number Diff line number Diff line change @@ -19,6 +19,7 @@ export default class Workspace extends Component {
19
19
20
20
componentDidMount ( ) {
21
21
console . log ( "[DEBUG] Loading workspace..." ) ;
22
+ window . ScratchNative ?. sendMessage ( "setActivity" , "on S4D workspace" ) ;
22
23
window . ScratchNative ?. onceMessage ( "connectFallbackServer" , ( ev , port ) => {
23
24
if ( ! port ) return ;
24
25
this . setState ( {
Original file line number Diff line number Diff line change 1918
1918
dependencies:
1919
1919
"@types/ms" "*"
1920
1920
1921
+ "@types/discord-rpc@^4.0.0":
1922
+ version "4.0.0"
1923
+ resolved "https://registry.yarnpkg.com/@types/discord-rpc/-/discord-rpc-4.0.0.tgz#29080812b9092996046af1a21138fb488d180f87"
1924
+ integrity sha512-a5HiKOcBkB43g/lN6fBYw8FyGc6Ue9CYucxxHxXlELXpb1CxCa2NA2pGK2Ub88pi4uY5+HQeSFbYtH6DJtV3Qw==
1925
+
1921
1926
"@types/eslint@^7.2.6":
1922
1927
version "7.28.0"
1923
1928
resolved "https://registry.yarnpkg.com/@types/eslint/-/eslint-7.28.0.tgz#7e41f2481d301c68e14f483fe10b017753ce8d5a"
You can’t perform that action at this time.
0 commit comments