Skip to content

Commit

Permalink
fix: symbian crash on startup, LF line endings
Browse files Browse the repository at this point in the history
  • Loading branch information
ruslang02 committed Sep 27, 2021
1 parent 2c45b1e commit 7b92c2a
Show file tree
Hide file tree
Showing 17 changed files with 214 additions and 146 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
src/discord.js/**
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,5 @@ moc/
**/*.js
!**/*.util.js
node_modules/
!src/ui/client.js
*.autosave
Makefile
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"files.exclude": {
"**/*.cache": true,
"**/*.inf": true,
"**/*.js": true,
"src/js/**/*.js": true,
"**/*.loc": true,
"**/*.mmp": true,
"**/*.pkg": true,
Expand Down
9 changes: 4 additions & 5 deletions src/globals.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ declare namespace Qml {
}

interface PageStackWindow extends Window {
initialPage: Qml.Page
pageStack: PageStack
}

Expand Down Expand Up @@ -174,17 +175,15 @@ declare function openDatabaseSync(
callback?: (db: Qt.Database) => void
): Database;

declare interface Window extends Qml.PageStackWindow {
declare interface Window extends Qml.Component, Qml.PageStackWindow {
client: import("./js/client/Client").Client
store: import("./js/store/DatabaseStore").DatabaseStore
}

const avkon: AvkonHelper;
const socket: Socket;
const http: HttpClient;
const viewer: QmlApplicationViewer;
const global: Qml.Component & {
client: import("./js/client/Client").Client
store: import("./js/store/DatabaseStore").DatabaseStore
};

const ListView: {
Beginning: number
Expand Down
2 changes: 1 addition & 1 deletion src/js/client/http/Http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const Http = {
) {
const METHOD = method.toUpperCase();

http.request(METHOD, path, global.store.get("settings").token, body ?? "");
http.request(METHOD, path, window.store.get("settings").token, body ?? "");

function listener(response: string) {
callback(null, JSON.parse(response));
Expand Down
2 changes: 1 addition & 1 deletion src/js/client/socket/SocketManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export class SocketManager {
constructor(private client: Client) { }

connect() {
const settings = global.store.get("settings");
const settings = window.store.get("settings");
const [host, port] = (settings.proxyUrl || defaultSettings.proxyUrl).split(":");

socket.connectToServer(host, +port);
Expand Down
2 changes: 2 additions & 0 deletions src/js/ui/DMPage/DMPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ Page {

property string pageName: "Direct Messages"

tools: toolbar

Component.onCompleted: Js.handleReady()

SystemPalette { id: palette; colorGroup: SystemPalette.Active }
Expand Down
16 changes: 8 additions & 8 deletions src/js/ui/DMPage/DMPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@ declare const dmPage: Qml.Page & Qml.Component;

function loadChannels() {
dmListModel.clear();
const cdnProxyUrl = global.store.get("settings").cdnProxyUrl || defaultSettings.cdnProxyUrl;
const channels = Object.keys(global.client.privateChannels)
.filter(a => global.client.privateChannels[a].lastMessageId)
const cdnProxyUrl = window.store.get("settings").cdnProxyUrl || defaultSettings.cdnProxyUrl;
const channels = Object.keys(window.client.privateChannels)
.filter(a => window.client.privateChannels[a].lastMessageId)
.sort((a, b) => {
const ac = global.client.privateChannels[a];
const bc = global.client.privateChannels[b];
const ac = window.client.privateChannels[a];
const bc = window.client.privateChannels[b];

return ac.lastMessageId.localeCompare(bc.lastMessageId);
}).reverse();

channels.length = 50;
channels.forEach(channelId => {
const channel: PrivateChannel = global.client.privateChannels[channelId];
const channel: PrivateChannel = window.client.privateChannels[channelId];
const [recipient] = channel.recipients;
const item = {
id: channelId,
Expand All @@ -42,7 +42,7 @@ function loadChannels() {

function handleReady() {
setTimeout(() => {
global.client.on("ready", loadChannels);
window.client.on("ready", loadChannels);
});
}

Expand All @@ -51,7 +51,7 @@ function openMessages(channelId: string) {
Qt.resolvedUrl("../MessagesPage/MessagesPage.qml"),
{
channelId,
channelName: "@" + global.client.privateChannels[channelId].recipients[0].username,
channelName: "@" + window.client.privateChannels[channelId].recipients[0].username,
}
);
}
10 changes: 0 additions & 10 deletions src/js/ui/DMPage/GuildPage.qml

This file was deleted.

31 changes: 31 additions & 0 deletions src/js/ui/GuildPage/GuildPage.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import QtQuick 1.1
import com.nokia.symbian 1.1
import "GuildPage.js" as Js

PageStackWindow {
id: window
platformSoftwareInputPanelEnabled: true
platformInverted: false
showStatusBar: true
showToolBar: true

Component.onCompleted: Js.handleReady()

Menu {
id: menu
content: MenuLayout {
MenuItem {
id: loginButton
text: "Sign in"
}
MenuItem {
id: settingsButton
text: "Settings"
}
MenuItem {
id: backButton
text: "Exit"
}
}
}
}
3 changes: 3 additions & 0 deletions src/js/ui/GuildPage/GuildPage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { Client } from "client/Client";

const client = new Client();
6 changes: 3 additions & 3 deletions src/js/ui/MessagesPage/MessagesPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function sendMessage(content: string) {
}

function appendMessage(msg: MessageDto) {
const cdnProxyUrl = global.store.get("settings").cdnProxyUrl || defaultSettings.cdnProxyUrl;
const cdnProxyUrl = window.store.get("settings").cdnProxyUrl || defaultSettings.cdnProxyUrl;
const splitTimestamp = msg.timestamp.split("T");
const [year, month, day] = splitTimestamp[0].split("-");
const [hour, minute, second] = splitTimestamp[1].split(".")[0].split(":");
Expand Down Expand Up @@ -72,7 +72,7 @@ function handleMessage(msg: MessageDto) {
function handleReady() {
setTimeout(() => {
loadMessages();
global.client.on("message", handleMessage);
window.client.on("message", handleMessage);
});

inputField.implicitHeightChanged.connect(() => {
Expand Down Expand Up @@ -103,5 +103,5 @@ function handleMessageReady(attachments: string) {
}

function handleDestroyed() {
global.client.off("message", handleMessage);
window.client.off("message", handleMessage);
}
16 changes: 8 additions & 8 deletions src/js/ui/SettingsPage/SettingsPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ declare const dialogField: Qml.TextField;
declare const debugModeItem: Qml.SelectionListItem;

function loadSettings() {
const settings = global.store.get("settings");
const settings = window.store.get("settings");

debugModeItem.subTitle = settings.debug ? "Enabled" : "Disabled";
}
Expand All @@ -18,43 +18,43 @@ function handleReady() {

dialog.buttonClicked.connect(bi => {
if (bi === 0) {
global.store.fetch("settings", settings => {
window.store.fetch("settings", settings => {
// @ts-ignore
settings[property] = dialogField.text;
global.store.set("settings", settings);
window.store.set("settings", settings);
loadSettings();
});
}
});

tokenItem.clicked.connect(() => {
dialog.titleText = "Token";
dialogField.text = global.store.get("settings").token ?? "";
dialogField.text = window.store.get("settings").token ?? "";
dialogField.placeholderText = "";
property = "token";
dialog.open();
});

cdnProxyUrlItem.clicked.connect(() => {
dialog.titleText = "CDN proxy URL";
dialogField.text = global.store.get("settings").cdnProxyUrl ?? "";
dialogField.text = window.store.get("settings").cdnProxyUrl ?? "";
dialogField.placeholderText = "hostname:port";
property = "cdnProxyUrl";
dialog.open();
});

proxyUrlItem.clicked.connect(() => {
dialog.titleText = "Gateway proxy URL";
dialogField.text = global.store.get("settings").proxyUrl ?? "";
dialogField.text = window.store.get("settings").proxyUrl ?? "";
dialogField.placeholderText = "hostname:port";
property = "proxyUrl";
dialog.open();
});

debugModeItem.clicked.connect(() => {
global.store.fetch("settings", settings => {
window.store.fetch("settings", settings => {
settings.debug = !settings.debug;
global.store.set("settings", settings);
window.store.set("settings", settings);
loadSettings();
});
});
Expand Down
93 changes: 89 additions & 4 deletions src/js/ui/launcher.qml
Original file line number Diff line number Diff line change
@@ -1,19 +1,104 @@
import QtQuick 1.1
import QtMobility.feedback 1.1
import com.nokia.symbian 1.1
import com.nokia.extras 1.1
import "DMPage"
import "./launcher.js" as Js

Item {
id: global
PageStackWindow {
id: window
platformSoftwareInputPanelEnabled: true
platformInverted: false
showStatusBar: true
showToolBar: true

Component.onCompleted: Js.handleReady()

HapticsEffect {
id: hapticsEffect;
attackTime: 250;
fadeTime: 250;
attackIntensity: 0;
fadeIntensity: 0
}

InfoBanner {
id: banner
}

Menu {
id: menu
content: MenuLayout {
MenuItem {
id: loginButton
text: "Sign in"
}
MenuItem {
id: settingsButton
text: "Settings"
}
MenuItem {
id: backButton
text: "Exit"
}
}
}

ToolBarLayout {
id: toolbar

ToolButton {
id: minimizeButton
flat: true
iconSource: "toolbar-back"
}

ToolButton {
id: menuButton
iconSource: "toolbar-menu"
}
}

StatusBar {
y: -window.y
Item {
anchors { left: parent.left; leftMargin: 6; bottom: parent.bottom; top: parent.top }
width: parent.width - 186;
clip: true
Text {
id: statusBarText
anchors.verticalCenter: parent.verticalCenter
maximumLineCount: 1
color: "white"
font.pointSize: 6
font.bold: true
}
Rectangle {
width: 25
anchors { top: parent.top; bottom: parent.bottom; right: parent.right }
rotation: -90
gradient: Gradient {
GradientStop { position: 0.0; color: "#00000000" }
GradientStop { position: 1.0; color: "#ff000000" }
}
}
}
Connections {
target: pageStack
onCurrentPageChanged: statusBarText.text = pageStack.currentPage.pageName
}
}

function module() {}

function exports() {}

function require(url) {
return Js.require(url);
}

function setTimeout(callback, timeout) {
const timer = Qt.createQmlObject("import QtQuick 1.0; Timer {}", global);
const timer = Qt.createQmlObject("import QtQuick 1.0; Timer {}", window);

timer.interval = timeout || 1;
timer.repeat = false;
Expand All @@ -33,7 +118,7 @@ Item {
}

function setInterval(callback, timeout) {
const timer = Qt.createQmlObject("import QtQuick 1.0; Timer {}", global);
const timer = Qt.createQmlObject("import QtQuick 1.0; Timer {}", window);

timer.interval = timeout || 1;
timer.repeat = true;
Expand Down
Loading

0 comments on commit 7b92c2a

Please sign in to comment.