Skip to content

Commit

Permalink
Updated FCM to v1 from legacy and other small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
joaomgcd committed Jul 5, 2024
1 parent a4748ff commit eac2304
Show file tree
Hide file tree
Showing 15 changed files with 484 additions and 18 deletions.
11 changes: 9 additions & 2 deletions appdashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import './v2/extensions.js';
import { App,RequestLoadDevicesFromServer } from "./v2/app.js";
import {AppHelperSettings} from "./v2/settings/apphelpersettings.js"
import { ControlSettings } from "./v2/settings/controlsetting.js";
import { SettingEncryptionPassword, SettingTheme, SettingThemeAccentColor,SettingCompanionAppPortToReceive, SettingKeyboardShortcutLastCommand, SettingKeyboardShortcutShowWindow, SettingEventGhostNodeRedPort, SettingClipboardSync, SettingCustomActions, SettingUseNativeNotifications, SettingNotificationTimeout, SettingRequireEncryptionForCommandLine, SettingKeyboardShortcutSkipSong, SettingKeyboardShortcutPreviousSong, SettingKeyboardShortcutPlayPause, SettingThemeBackgroundColor, SettingThemeBackgroundPanelColor, SettingThemeTextColor, SettingThemeTextColorOnAccent, SettingAutoLaunch, SettingLaunchMinimized, SettingNotificationsDisplay, SettingShowLinksAsNotificationsOnly, SettingHideTextInNotifications } from "./v2/settings/setting.js";
import { SettingEncryptionPassword, SettingTheme, SettingThemeAccentColor,SettingCompanionAppPortToReceive, SettingKeyboardShortcutLastCommand, SettingKeyboardShortcutShowWindow, SettingEventGhostNodeRedPort, SettingClipboardSync, SettingClipboardCommand, SettingCustomActions, SettingUseNativeNotifications, SettingNotificationTimeout, SettingRequireEncryptionForCommandLine, SettingKeyboardShortcutSkipSong, SettingKeyboardShortcutPreviousSong, SettingKeyboardShortcutPlayPause, SettingThemeBackgroundColor, SettingThemeBackgroundPanelColor, SettingThemeTextColor, SettingThemeTextColorOnAccent, SettingAutoLaunch, SettingLaunchMinimized, SettingNotificationsDisplay, SettingShowLinksAsNotificationsOnly, SettingHideTextInNotifications } from "./v2/settings/setting.js";
import { AppGCMHandler } from "./v2/gcm/apphelpergcm.js";
import { ControlDialogInput, ControlDialogOk } from "./v2/dialog/controldialog.js";
import { AppContext } from "./v2/appcontext.js";
Expand Down Expand Up @@ -192,6 +192,7 @@ export class AppHelperSettingsDashboard extends AppHelperSettings{
])}),
new Tab({title:"Clipboard Sync",controlContent:new ControlSettings([
new SettingClipboardSync({devices})
// new SettingClipboardCommand()
])}),
new Tab({title:"Automation",controlContent:new ControlSettings([
new SettingEventGhostNodeRedPort(),
Expand Down Expand Up @@ -337,7 +338,7 @@ export class AppDashboard extends App{
}
async load(){
AppContext.context.allowUnsecureContent = true;
window.oncontextmenu = () => ServerEventBus.post(new RequestToggleDevOptions())
window.oncontextmenu = () => ServerEventBus.post(new RequestToggleDevOptions());
// AppGCMHandler.handlePushUrl = (push)=> {
// const url = push.url;
// if(!url) return;
Expand Down Expand Up @@ -630,6 +631,12 @@ export class AppDashboard extends App{
const devices = await this.getDevices(deviceIdsToSendTo);
console.log("Sending auto clipboard", gcm, devices);
await devices.send(gcm);

// const settingClipboardCommand = new SettingClipboardCommand();
// const clipboardCommand = await settingClipboardCommand.value;
// if(clipboardCommand){
// await devices.sendPush({text:clipboardCommand})
// }
}
async onRequestRunCommandLineCommand(request){
await ServerEventBus.post(request);
Expand Down
6 changes: 6 additions & 0 deletions changes.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
{
"changes":[
{
"version": "1.1.3",
"log":[
"Updated FCM to use v1 instead of legacy"
]
} ,
{
"version": "1.1.2",
"log":[
Expand Down
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
</script>
<script src="./v2/gcm/gcmbase.js"></script>
<script src="./v2/dexie.js"></script>
<script src="./v2/api/fcmLegacyToV1Converter.js"></script>
<script type="module">
import { AppDashboard } from './appdashboard.js';
const app = new AppDashboard(document.querySelector("body")).load();
Expand Down
Empty file added ip
Empty file.
10 changes: 8 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "com.joaomgcd.join",
"productName": "Join Desktop",
"homepage": "https://joaoapps.com/join/desktop",
"version": "1.1.2",
"version": "1.1.3",
"description": "A companion app for the Join website",
"main": "main_esm.js",
"scripts": {
Expand Down Expand Up @@ -72,9 +72,15 @@
]
},
"win": {
"target": "squirrel",
"target": [
"portable",
"squirrel"
],
"icon": "build/icon.ico"
},
"portable": {
"artifactName": "join_portable.exe"
},
"squirrelWindows": {
"loadingGif": "joinloading.png"
}
Expand Down
13 changes: 12 additions & 1 deletion server/server.js

Large diffs are not rendered by default.

10 changes: 8 additions & 2 deletions server/servernotification.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,11 @@ class WindowNotifications extends Array{
console.log("Mouse entered");
}
async closeWindowIfNoNotifications(){
if(this.notificationsToShow.length > 0) return;

if(this.notificationsToShow.length > 0){
await EventBus.post(new ExistingNotifications());
return;
}
await EventBus.post(new NoNotifications());
console.log("No notifications. Closing window.");
await this.closeWindow();
}
Expand All @@ -236,6 +239,7 @@ class WindowNotifications extends Array{
if(!this.window) return;

console.log("Notifications cleared. Closing window.");
await EventBus.post(new NoNotifications(options));
await this.closeWindow();
}
async onRequestReplyMessage(request){
Expand Down Expand Up @@ -346,6 +350,8 @@ class StoredNotifications{
this.options = options;
}
}
class ExistingNotifications{}
class NoNotifications{}
export class ServerNotification{
// constructor(args){
// Object.assign(this,args);
Expand Down
131 changes: 131 additions & 0 deletions v2/api/authTokenGetter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
// defineModule(function () {
// class AuthTokenGetter {
// static tokenCacheKey = 'authTokenCache';

// constructor(account, privateKey, base64Implementation) {
// this.account = account;
// this.privateKey = privateKey;
// this.base64Implementation = base64Implementation;

// // Load cache from localStorage
// const cachedData = localStorage.getItem(AuthTokenGetter.tokenCacheKey);
// AuthTokenGetter.tokenCache = cachedData ? JSON.parse(cachedData) : {};
// }

// static saveCacheToLocalStorage() {
// localStorage.setItem(AuthTokenGetter.tokenCacheKey, JSON.stringify(AuthTokenGetter.tokenCache));
// }

// async createJwtToken() {
// const header = {
// alg: "RS256",
// typ: "JWT"
// };

// const now = Math.floor(Date.now() / 1000);
// const expiry = now + 3600; // 1 hour

// const claims = {
// iss: this.account,
// scope: "https://www.googleapis.com/auth/firebase.messaging",
// aud: "https://oauth2.googleapis.com/token",
// iat: now,
// exp: expiry
// };

// const encodedHeader = this.base64Implementation.encode(JSON.stringify(header));
// const encodedClaims = this.base64Implementation.encode(JSON.stringify(claims));
// const unsignedToken = `${encodedHeader}.${encodedClaims}`;

// const createSignature = async () => {
// const privateKeyContent = this.privateKey
// .replace(/\n/g, '')
// .replace("-----BEGIN PRIVATE KEY-----", '')
// .replace("-----END PRIVATE KEY-----", '');

// const keyBytes = this.base64Implementation.decode(privateKeyContent);
// const key = await crypto.subtle.importKey(
// 'pkcs8',
// keyBytes,
// { name: "RSASSA-PKCS1-v1_5", hash: { name: "SHA-256" } },
// false,
// ["sign"]
// );

// const signature = await crypto.subtle.sign(
// "RSASSA-PKCS1-v1_5",
// key,
// new TextEncoder().encode(unsignedToken)
// );

// return this.base64Implementation.encode(signature);
// };

// const signature = await createSignature();
// return `${unsignedToken}.${signature}`;
// }

// async getAccessToken() {
// const currentTime = Math.floor(Date.now() / 1000);

// const existingToken = AuthTokenGetter.tokenCache[this.account];
// if (existingToken && currentTime < existingToken.expiryTime) {
// console.log("Using existing auth token");
// return existingToken.token;
// }

// console.log("Getting new auth token");
// const jwtToken = await this.createJwtToken();

// const response = await fetch('https://oauth2.googleapis.com/token', {
// method: 'POST',
// headers: {
// 'Content-Type': 'application/x-www-form-urlencoded'
// },
// body: new URLSearchParams({
// 'grant_type': 'urn:ietf:params:oauth:grant-type:jwt-bearer',
// 'assertion': jwtToken
// })
// });

// if (!response.ok) {
// const errorText = await response.text();
// throw new Error(`Auth token unexpected response code ${response.status}. Error: ${errorText}`);
// }

// const tokenResponse = await response.json();
// if (!tokenResponse.access_token || !tokenResponse.expires_in) {
// throw new Error("Auth token couldn't parse token response");
// }

// const accessToken = tokenResponse.access_token;
// const newCachedToken = { token: accessToken, expiryTime: currentTime + tokenResponse.expires_in };
// AuthTokenGetter.tokenCache[this.account] = newCachedToken;

// // Save cache to localStorage
// AuthTokenGetter.saveCacheToLocalStorage();

// return accessToken;
// }
// }

// const Base64Implementation = {
// encode: (data) => {
// const bytes = typeof data === 'string' ? new TextEncoder().encode(data) : data;
// return btoa(String.fromCharCode(...new Uint8Array(bytes)));
// },
// decode: (data) => {
// const binaryString = atob(data);
// const len = binaryString.length;
// const bytes = new Uint8Array(len);
// for (let i = 0; i < len; i++) {
// bytes[i] = binaryString.charCodeAt(i);
// }
// return bytes.buffer;
// }
// };
// return {
// AuthTokenGetter,
// Base64Implementation
// };
// });
4 changes: 2 additions & 2 deletions v2/api/builder/apifield.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ export class ApiFields extends Array{
this.push(new ApiField({id:"group",label:"Notification Group (Android 7 and above) - allows you to join notifications in different groups"}));
this.push(new ApiField({id:"category",label:"Notification Category (Android 8 and above) - allows you to customize notification properties"}));
this.push(new ApiField({id:"notificationId",label:"Notification ID - set the same ID to replace a previous notification"}));
this.push(new ApiField({id:"urlclipboard",label:"Clipboard"}));
this.push(new ApiField({id:"urlfile",label:"File (must be a publicly accessible URL)"}));
this.push(new ApiField({id:"clipboard",label:"Clipboard"}));
this.push(new ApiField({id:"file",label:"File (must be a publicly accessible URL)"}));
this.push(new ApiField({id:"callnumber",label:"Phone Call Number"}));
this.push(new ApiField({id:"smsnumber",label:"SMS Number - if sending SMS must also fill in SMS Text below"}));
this.push(new ApiField({id:"smstext",label:"SMS Text - if sending SMS must also fill in SMS Number above"}));
Expand Down
Loading

0 comments on commit eac2304

Please # to comment.