Skip to content

Commit

Permalink
v 0.2.0-alpha
Browse files Browse the repository at this point in the history
  • Loading branch information
drlight17 authored Apr 27, 2024
1 parent 0517bc7 commit b1e09dd
Show file tree
Hide file tree
Showing 7 changed files with 129 additions and 21 deletions.
82 changes: 75 additions & 7 deletions main.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
// Modules to control application life and create native browser window
const { app, clipboard, BrowserWindow, Menu, Tray, nativeImage, Notification, dialog } = require('electron')
const prompt = require('electron-prompt')
const { app, clipboard, BrowserWindow, Menu, Tray, nativeImage, Notification, dialog, session, shell, powerMonitor } = require('electron')
const prompt = require('electron-prompt');

const ShutdownHandler = require('@paymoapp/electron-shutdown-handler').default;


//const { Resvg } = require('@resvg/resvg-js')
const fetch = require('electron-fetch').default

const isMac = process.platform === 'darwin'
const isWindows = process.platform === 'win32'

const fs = require("fs");
const { join } = require('path');
Expand Down Expand Up @@ -56,6 +61,12 @@ try {
{
label: 'Файл',
submenu: [
{
label: 'Открыть Nextcloud',
click: () => {
shell.openExternal(store.get('server_url'));
},
},
{
label: 'Настройки',
click: () => {
Expand Down Expand Up @@ -101,7 +112,7 @@ try {
{ label : "Помощь",
accelerator: 'F1',
click: () => {
openPopup('https://docs.nextcloud.com/server/latest/user_manual/ru');
openPopup('https://docs.nextcloud.com/server/latest/user_manual/ru/talk');
//app.exit(0);
}
},
Expand Down Expand Up @@ -133,6 +144,12 @@ try {
},
},
{ type: 'separator' },
{
label: 'Открыть Nextcloud',
click: () => {
shell.openExternal(store.get('server_url'));
},
},
{
label: 'Настройки',
click: () => {
Expand Down Expand Up @@ -411,6 +428,11 @@ try {
}

async function createWindow () {
// for SSO setting, allowed domains
if (store.get('allow_domain')) {
session.defaultSession.allowNTLMCredentialsForDomains(store.get('allow_domain'));
}

// Create the browser window.
win = new BrowserWindow({
title: app.getName(),
Expand All @@ -427,7 +449,11 @@ try {
}
});

win.setBounds(store.get('bounds'));
// hanlde open external links in system browser
win.webContents.setWindowOpenHandler(({ url }) => {
shell.openExternal(url);
return { action: 'deny' };
});

//customize about
app.setAboutPanelOptions({
Expand Down Expand Up @@ -481,6 +507,9 @@ try {
if (isMac) app.dock.hide();
win.hide();
})
win.on('hide', event => {
store.set('bounds', win.getBounds());
})

// get notification dot status dirty with 1s timeout, TODO place to detect on webContents change
win.webContents.executeJavaScript(fs.readFileSync(path.join(__dirname, 'notification_observer.js')), true)
Expand Down Expand Up @@ -516,7 +545,7 @@ try {
// check cloud
win.webContents.on('did-finish-load', function(e) {

win.webContents.executeJavaScript(fs.readFileSync(path.join(__dirname, 'nextcloud_check.js')), true)
win.webContents.executeJavaScript(fs.readFileSync(path.join(__dirname, 'nextcloud_check.js')),true)

win.webContents.on('console-message', (event, level, message, line, sourceId) => {
try {
Expand Down Expand Up @@ -545,6 +574,9 @@ try {
});

win.on('show', function () {

win.setBounds(store.get('bounds'));

if (isMac) app.dock.setIcon(icon);

if (is_notification) {
Expand All @@ -564,23 +596,36 @@ try {
details = win.webContents.on('will-navigate', (event,redirectUrl) => {
url = this.details.getURL();


if (!(redirectUrl.includes('apps/spreed'))) {
if (redirectUrl.includes('logout')) {
preventUnsupportedBrowser(win);
// dirty but it works
details.executeJavaScript('window.location.replace("'+url+'")')
}
}

//event.preventDefault();

// open profile process
if (redirectUrl.includes('/u/')) {
event.preventDefault();
// dirty prevent PageLoaders appear
win.webContents.insertCSS('#profile span.loading-icon { display:none;}');
win.webContents.insertCSS('#side-menu-loader-bar { width:0!important;}');

openPopup(redirectUrl);
}

// open files process
if (redirectUrl.includes('/f/')) {
event.preventDefault();
// dirty prevent PageLoaders appear
win.webContents.insertCSS('#profile span.loading-icon { display:none;}');
win.webContents.insertCSS('#side-menu-loader-bar { width:0!important;}');

shell.openExternal(redirectUrl);
return { action: 'deny' };
}
});


Expand Down Expand Up @@ -680,12 +725,35 @@ try {
// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
// Some APIs can only be used after this event occurs.
app.whenReady().then(() => {
app.whenReady().then((event) => {

// handle OS shutdown/logout to prevent crush
/*console.log('PID =', process.pid);
process.on('exit', function() {
//e.preventDefault();
console.log('Shutdown/logout is detected! Exiting app!');
});*/

if (url == "") {
setServerUrl(url_example);
} else {
url += "/apps/spreed";
createWindow();
// handle OS shutdown/logout to prevent crush
if (isWindows) {
console.log('PID =', process.pid);
app.on('before-quit', e => {
e.preventDefault();
})
ShutdownHandler.setWindowHandle(win.getNativeWindowHandle());
ShutdownHandler.blockShutdown('');
ShutdownHandler.on('shutdown', () => {
console.log('Shutdown/logout is detected! Exiting app!');
ShutdownHandler.releaseShutdown();
app.exit(0);
})
}
guiInit();
}
})
Expand Down
20 changes: 20 additions & 0 deletions nextcloud_check.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,24 @@

if (_oc_config.version.localeCompare("28.0.0.0", undefined, { numeric: true, sensitivity: 'base' }) == '-1') {
console.log(JSON.stringify({action: "not_found"}));
} else {
// add menu link
if ( !$('#nc_link').length ) {
let li = document.createElement( "li" );
li.classList.add("menu-entry");
li.setAttribute('id','nc_link');

let a = document.createElement( "a" );

a.setAttribute('href','/');
a.setAttribute('target','_blank');
a.textContent += "Открыть Nextcloud";
let img = document.createElement( "img" );
img.setAttribute('src','/core/img/logo/logo.svg');
$(a).prepend($(img));
$(li).append($(a));

$('#firstrunwizard_about').before( $(li) );
//console.log($('#profile'));
}
}
20 changes: 13 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
],
"icon": "icon.png",
"main": "./main.js",
"version": "0.1.1-alpha",
"version": "0.2.0-alpha",
"author": "drlight17",
"build": {
"appId": "com.electron.talk-electron",
Expand Down Expand Up @@ -48,15 +48,19 @@
{
"target": "nsis",
"arch": [
"x64",
"ia32"
"x64"
]
},
{
"target": "zip",
"arch": [
"x64"
]
},
{
"target": "msi",
"arch": [
"x64",
"ia32"
"x64"
]
}
]
Expand All @@ -67,13 +71,15 @@
"start": "electron ."
},
"dependencies": {
"@electron/packager": "latest",
"@paymoapp/electron-shutdown-handler": "latest",
"electron-fetch": "^1.9.1",
"electron-packager": "^17.1.2",
"electron-prompt": "^1.7.0",
"electron-store": "^8.2.0"
},
"devDependencies": {
"electron": "^22.3.27",
"electron-builder": "^24.13.3"
"electron-builder": "^24.13.3",
"@paymoapp/electron-shutdown-handler": "latest"
}
}
16 changes: 10 additions & 6 deletions package.json.linux
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,24 @@
],
"icon": "icon.png",
"main": "./main.js",
"version": "0.1.1-alpha",
"author": "drlight17",
"version": "0.2.0-alpha",
"author": "Yuri Samoilov <[email protected]>",
"homepage": "https://github.com/drlight17/talk-electron",
"build": {
"appId": "com.electron.talk-electron",
"productName": "NC Talk Electron",
"asar": false,
"asar": true,
"linux": {
"icon": "icon.icns",
"target": [
{
"target": "AppImage",
"target": "flatpak",
"arch": [
"x64"
]
},
{
"target": "flatpak",
"target": "AppImage",
"arch": [
"x64"
]
Expand Down Expand Up @@ -58,12 +60,14 @@
},
"dependencies": {
"electron-fetch": "^1.9.1",
"electron-packager": "^17.1.2",
"@electron/packager": "latest",
"@paymoapp/electron-shutdown-handler": "latest",
"electron-prompt": "^1.7.0",
"electron-store": "^8.2.0"
},
"devDependencies": {
"electron": "^22.3.27",
"@paymoapp/electron-shutdown-handler": "latest",
"electron-builder": "^22.10.5"
}
}
2 changes: 2 additions & 0 deletions settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
<form id="settings_form" onsubmit="return false">
<label for="server_url">Адрес сервера Nextcloud:</label>
<input type="text" name="server_url" id="server_url"><br><br>
<label title="Несколько значений через запятую, * - wildcard (может обозначать любой поддомен)" for="allow_domain">Разрешить SSO с доменов (* для всех):</label>
<input type="text" name="allow_domain" id="allow_domain"><br><br>
<input type='hidden' value=false name='run_at_startup'>
<input type="checkbox" value=true name="run_at_startup" id="run_at_startup">
<label for="run_at_startup">Автозапуск при входе пользователя</label>
Expand Down
6 changes: 5 additions & 1 deletion settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ function loadSettings(settings) {
document.getElementById('server_url').value = '`+url_example+`';
}

if (settings.allow_domain !== undefined) {
document.getElementById('allow_domain').value = settings.allow_domain;
}

if (settings.run_at_startup !== undefined) {
document.getElementById('run_at_startup').checked = settings.run_at_startup;
} else {
Expand Down Expand Up @@ -47,4 +51,4 @@ function saveSettings() {
}
}
console.log(JSON.stringify({action: "save_settings", settings: JSON.stringify(settings)}));
}
}
4 changes: 4 additions & 0 deletions styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
margin-block:initial!important;
}

#nc_link img{
filter:inherit!important;
}

/*settings styling*/

#app {
Expand Down

0 comments on commit b1e09dd

Please sign in to comment.